Commit 8f79ded9 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Samuel Ortiz

NFC: st21nfca: Fix potential memory leak

If all bits of 'dev_mask' are already set, there is a memory leak because
'info' should be freed before returning.

While fixing it, 'return -ENOMEM' directly if the first kzalloc fails.
This makes the code more readable.
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent ca42fb9e
...@@ -959,10 +959,8 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, ...@@ -959,10 +959,8 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops,
unsigned long quirks = 0; unsigned long quirks = 0;
info = kzalloc(sizeof(struct st21nfca_hci_info), GFP_KERNEL); info = kzalloc(sizeof(struct st21nfca_hci_info), GFP_KERNEL);
if (!info) { if (!info)
r = -ENOMEM; return -ENOMEM;
goto err_alloc_hdev;
}
info->phy_ops = phy_ops; info->phy_ops = phy_ops;
info->phy_id = phy_id; info->phy_id = phy_id;
...@@ -978,8 +976,10 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, ...@@ -978,8 +976,10 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops,
* persistent info to discriminate 2 identical chips * persistent info to discriminate 2 identical chips
*/ */
dev_num = find_first_zero_bit(dev_mask, ST21NFCA_NUM_DEVICES); dev_num = find_first_zero_bit(dev_mask, ST21NFCA_NUM_DEVICES);
if (dev_num >= ST21NFCA_NUM_DEVICES) if (dev_num >= ST21NFCA_NUM_DEVICES) {
return -ENODEV; r = -ENODEV;
goto err_alloc_hdev;
}
set_bit(dev_num, dev_mask); set_bit(dev_num, dev_mask);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment