Skip to content

Commit 1b9dadb

Browse files
Wei Yongjundavem330
authored andcommitted
NFC: st21nfca: Fix memory leak in device probe and remove
'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]>
1 parent 5be60a9 commit 1b9dadb

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
@@ -524,7 +524,8 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
524524
phy->gpiod_ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
525525
if (IS_ERR(phy->gpiod_ena)) {
526526
nfc_err(dev, "Unable to get ENABLE GPIO\n");
527-
return PTR_ERR(phy->gpiod_ena);
527+
r = PTR_ERR(phy->gpiod_ena);
528+
goto out_free;
528529
}
529530

530531
phy->se_status.is_ese_present =
@@ -535,7 +536,7 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
535536
r = st21nfca_hci_platform_init(phy);
536537
if (r < 0) {
537538
nfc_err(&client->dev, "Unable to reboot st21nfca\n");
538-
return r;
539+
goto out_free;
539540
}
540541

541542
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
@@ -544,15 +545,23 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
544545
ST21NFCA_HCI_DRIVER_NAME, phy);
545546
if (r < 0) {
546547
nfc_err(&client->dev, "Unable to register IRQ handler\n");
547-
return r;
548+
goto out_free;
548549
}
549550

550-
return st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
551-
ST21NFCA_FRAME_HEADROOM,
552-
ST21NFCA_FRAME_TAILROOM,
553-
ST21NFCA_HCI_LLC_MAX_PAYLOAD,
554-
&phy->hdev,
555-
&phy->se_status);
551+
r = st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
552+
ST21NFCA_FRAME_HEADROOM,
553+
ST21NFCA_FRAME_TAILROOM,
554+
ST21NFCA_HCI_LLC_MAX_PAYLOAD,
555+
&phy->hdev,
556+
&phy->se_status);
557+
if (r)
558+
goto out_free;
559+
560+
return 0;
561+
562+
out_free:
563+
kfree_skb(phy->pending_skb);
564+
return r;
556565
}
557566

558567
static int st21nfca_hci_i2c_remove(struct i2c_client *client)
@@ -563,6 +572,8 @@ static int st21nfca_hci_i2c_remove(struct i2c_client *client)
563572

564573
if (phy->powered)
565574
st21nfca_hci_i2c_disable(phy);
575+
if (phy->pending_skb)
576+
kfree_skb(phy->pending_skb);
566577

567578
return 0;
568579
}

0 commit comments

Comments
 (0)