Skip to content

Commit 2389203

Browse files
Wei Yongjungregkh
authored andcommitted
NFC: st21nfca: Fix memory leak in device probe and remove
[ Upstream commit 1b9dadb ] 'phy->pending_skb' is alloced when device probe, but forgot to free in the error handling path and remove path, this cause memory leak as follows: unreferenced object 0xffff88800bc06800 (size 512): comm "8", pid 11775, jiffies 4295159829 (age 9.032s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000d66c09ce>] __kmalloc_node_track_caller+0x1ed/0x450 [<00000000c93382b3>] kmalloc_reserve+0x37/0xd0 [<000000005fea522c>] __alloc_skb+0x124/0x380 [<0000000019f29f9a>] st21nfca_hci_i2c_probe+0x170/0x8f2 Fix it by freeing 'pending_skb' in error and remove. Fixes: 6895730 ("NFC: ST21NFCA: Add driver for STMicroelectronics ST21NFCA NFC Chip") Reported-by: Hulk Robot <[email protected]> Signed-off-by: Wei Yongjun <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent c1babfe commit 2389203

File tree

1 file changed

+20
-9
lines changed
  • drivers/nfc/st21nfca

1 file changed

+20
-9
lines changed

drivers/nfc/st21nfca/i2c.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
528528
phy->gpiod_ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
529529
if (IS_ERR(phy->gpiod_ena)) {
530530
nfc_err(dev, "Unable to get ENABLE GPIO\n");
531-
return PTR_ERR(phy->gpiod_ena);
531+
r = PTR_ERR(phy->gpiod_ena);
532+
goto out_free;
532533
}
533534

534535
phy->se_status.is_ese_present =
@@ -539,7 +540,7 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
539540
r = st21nfca_hci_platform_init(phy);
540541
if (r < 0) {
541542
nfc_err(&client->dev, "Unable to reboot st21nfca\n");
542-
return r;
543+
goto out_free;
543544
}
544545

545546
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
@@ -548,15 +549,23 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
548549
ST21NFCA_HCI_DRIVER_NAME, phy);
549550
if (r < 0) {
550551
nfc_err(&client->dev, "Unable to register IRQ handler\n");
551-
return r;
552+
goto out_free;
552553
}
553554

554-
return st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
555-
ST21NFCA_FRAME_HEADROOM,
556-
ST21NFCA_FRAME_TAILROOM,
557-
ST21NFCA_HCI_LLC_MAX_PAYLOAD,
558-
&phy->hdev,
559-
&phy->se_status);
555+
r = st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
556+
ST21NFCA_FRAME_HEADROOM,
557+
ST21NFCA_FRAME_TAILROOM,
558+
ST21NFCA_HCI_LLC_MAX_PAYLOAD,
559+
&phy->hdev,
560+
&phy->se_status);
561+
if (r)
562+
goto out_free;
563+
564+
return 0;
565+
566+
out_free:
567+
kfree_skb(phy->pending_skb);
568+
return r;
560569
}
561570

562571
static int st21nfca_hci_i2c_remove(struct i2c_client *client)
@@ -567,6 +576,8 @@ static int st21nfca_hci_i2c_remove(struct i2c_client *client)
567576

568577
if (phy->powered)
569578
st21nfca_hci_i2c_disable(phy);
579+
if (phy->pending_skb)
580+
kfree_skb(phy->pending_skb);
570581

571582
return 0;
572583
}

0 commit comments

Comments
 (0)