Skip to content

Commit e553265

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 <hulkci@huawei.com> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8d70dc0 commit e553265

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

  • drivers/nfc/st21nfca

‎drivers/nfc/st21nfca/i2c.c‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
533533
phy->gpiod_ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
534534
if (IS_ERR(phy->gpiod_ena)) {
535535
nfc_err(dev, "Unable to get ENABLE GPIO\n");
536-
return PTR_ERR(phy->gpiod_ena);
536+
r = PTR_ERR(phy->gpiod_ena);
537+
goto out_free;
537538
}
538539

539540
phy->se_status.is_ese_present =
@@ -544,7 +545,7 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
544545
r = st21nfca_hci_platform_init(phy);
545546
if (r < 0) {
546547
nfc_err(&client->dev, "Unable to reboot st21nfca\n");
547-
return r;
548+
goto out_free;
548549
}
549550

550551
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
@@ -553,15 +554,23 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
553554
ST21NFCA_HCI_DRIVER_NAME, phy);
554555
if (r < 0) {
555556
nfc_err(&client->dev, "Unable to register IRQ handler\n");
556-
return r;
557+
goto out_free;
557558
}
558559

559-
return st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
560-
ST21NFCA_FRAME_HEADROOM,
561-
ST21NFCA_FRAME_TAILROOM,
562-
ST21NFCA_HCI_LLC_MAX_PAYLOAD,
563-
&phy->hdev,
564-
&phy->se_status);
560+
r = st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
561+
ST21NFCA_FRAME_HEADROOM,
562+
ST21NFCA_FRAME_TAILROOM,
563+
ST21NFCA_HCI_LLC_MAX_PAYLOAD,
564+
&phy->hdev,
565+
&phy->se_status);
566+
if (r)
567+
goto out_free;
568+
569+
return 0;
570+
571+
out_free:
572+
kfree_skb(phy->pending_skb);
573+
return r;
565574
}
566575

567576
static int st21nfca_hci_i2c_remove(struct i2c_client *client)
@@ -574,6 +583,8 @@ static int st21nfca_hci_i2c_remove(struct i2c_client *client)
574583

575584
if (phy->powered)
576585
st21nfca_hci_i2c_disable(phy);
586+
if (phy->pending_skb)
587+
kfree_skb(phy->pending_skb);
577588

578589
return 0;
579590
}

0 commit comments

Comments
 (0)