Skip to content

Commit c71ba66

Browse files
neosys007Paolo Abeni
authored andcommitted
nfc: pn533: allocate rx skb before consuming bytes
pn532_receive_buf() reports the number of accepted bytes to the serdev core. The current code consumes bytes into recv_skb and may already hand a complete frame to pn533_recv_frame() before allocating a fresh receive buffer. If that alloc_skb() fails, the callback returns 0 even though it has already consumed bytes, and it leaves recv_skb as NULL for the next receive callback. That breaks the receive_buf() accounting contract and can also lead to a NULL dereference on the next skb_put_u8(). Allocate the receive skb lazily before consuming the next byte instead. If allocation fails, return the number of bytes already accepted. Fixes: c656aa4 ("nfc: pn533: add UART phy driver") Cc: stable@vger.kernel.org Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Link: https://patch.msgid.link/20260405094003.3-pn533-v2-pengpeng@iscas.ac.cn Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent ebe560e commit c71ba66

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

drivers/nfc/pn533/uart.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ static size_t pn532_receive_buf(struct serdev_device *serdev,
211211

212212
timer_delete(&dev->cmd_timeout);
213213
for (i = 0; i < count; i++) {
214+
if (!dev->recv_skb) {
215+
dev->recv_skb = alloc_skb(PN532_UART_SKB_BUFF_LEN,
216+
GFP_KERNEL);
217+
if (!dev->recv_skb)
218+
return i;
219+
}
220+
214221
if (unlikely(!skb_tailroom(dev->recv_skb)))
215222
skb_trim(dev->recv_skb, 0);
216223

@@ -219,9 +226,7 @@ static size_t pn532_receive_buf(struct serdev_device *serdev,
219226
continue;
220227

221228
pn533_recv_frame(dev->priv, dev->recv_skb, 0);
222-
dev->recv_skb = alloc_skb(PN532_UART_SKB_BUFF_LEN, GFP_KERNEL);
223-
if (!dev->recv_skb)
224-
return 0;
229+
dev->recv_skb = NULL;
225230
}
226231

227232
return i;

0 commit comments

Comments
 (0)