nfc: Fix potential resource leaks
Subsystems (3)
PATCH v2 1/1 nfc: Fix potential resource leaks
nfc_get_device() take reference for the device, add missing nfc_put_device() to release it when not need anymore. Also fix the style warnning by use error EOPNOTSUPP instead of ENOTSUPP.
Fixes 5ce3f32b5264 ("NFC: netlink: SE API implementation")
Fixes 29e76924cf08 ("nfc: netlink: Add capability to reply to vendor_cmd with data")
Signed-off-by Miaoqian Lin <[email protected]>
---
changes in v2:
- rename error to rc.
- add blank line.
v1: https://lore.kernel.org/all/[email protected]/
--- net/nfc/netlink.c | 52 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-)
net/nfc/netlink.c +38 -14
@@ -1497,6 +1497,7 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)u32 dev_idx, se_idx;u8 *apdu;size_t apdu_len; +int rc; if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || !info->attrs[NFC_ATTR_SE_INDEX] ||
@@ -1510,25 +1511,37 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)if (!dev)return -ENODEV ; -if (!dev->ops || !dev->ops->se_io) -return -ENOTSUPP ; +if (!dev->ops || !dev->ops->se_io) { + rc = -EOPNOTSUPP ; + goto put_dev; + } apdu_len =nla_len (info->attrs[NFC_ATTR_SE_APDU ]); -if (apdu_len ==0 ) -return -EINVAL ; +if (apdu_len ==0 ) { + rc = -EINVAL ; + goto put_dev; + } apdu =nla_data (info->attrs[NFC_ATTR_SE_APDU ]); -if (!apdu) -return -EINVAL ; +if (!apdu) { + rc = -EINVAL ; + goto put_dev; + } ctx =kzalloc (sizeof (struct se_io_ctx ),GFP_KERNEL ); -if (!ctx) -return -ENOMEM ; +if (!ctx) { + rc = -ENOMEM ; + goto put_dev; + } ctx->dev_idx = dev_idx; ctx->se_idx = se_idx; -return nfc_se_io (dev, se_idx, apdu, apdu_len, se_io_cb, ctx); + rc =nfc_se_io (dev, se_idx, apdu, apdu_len, se_io_cb, ctx); + +put_dev: +nfc_put_device (dev); +return rc; } static int nfc_genl_vendor_cmd(struct sk_buff *skb,
@@ -1551,14 +1564,21 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, subcmd =nla_get_u32 (info->attrs[NFC_ATTR_VENDOR_SUBCMD ]); dev =nfc_get_device (dev_idx); -if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds) +if (!dev)return -ENODEV ; +if (!dev->vendor_cmds || !dev->n_vendor_cmds) { + err = -ENODEV ; + goto put_dev; + } +if (info->attrs[NFC_ATTR_VENDOR_DATA ]) { data =nla_data (info->attrs[NFC_ATTR_VENDOR_DATA ]); data_len =nla_len (info->attrs[NFC_ATTR_VENDOR_DATA ]); -if (data_len ==0 ) -return -EINVAL ; +if (data_len ==0 ) { + err = -EINVAL ; + goto put_dev; + } }else { data =NULL ; data_len =0 ;
@@ -1573,10 +1593,14 @@ static int nfc_genl_vendor_cmd(struct sk_buff *skb, dev->cur_cmd_info = info; err = cmd->doit (dev, data, data_len); dev->cur_cmd_info =NULL ; -return err; + goto put_dev; } -return -EOPNOTSUPP ; + err = -EOPNOTSUPP ; + +put_dev: +nfc_put_device (dev); +return err; }/* message building helper */
Signature · 1 line
2.25.1
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:
Quoted 10 lines · On Fri, 23 Dec 2022 11:37:18 +0400 you wrote:
nfc_get_device()take reference for the device, add missingnfc_put_device()to release it when not need anymore. Also fix the style warnning by use error EOPNOTSUPP instead of ENOTSUPP.Fixes 5ce3f32b5264 ("NFC: netlink: SE API implementation")Fixes 29e76924cf08 ("nfc: netlink: Add capability to reply to vendor_cmd with data")Signed-off-by Miaoqian Lin <[email protected]>[...]
Here is the summary with links:
- [v2] nfc: Fix potential resource leaks
https://git.kernel.org/netdev/net/c/df49908f3c52
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html