diff mbox series

[net] NFC: netlink: put device in nfc_genl_se_io()

Message ID 20230105082738.671183-1-shaozhengchao@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] NFC: netlink: put device in nfc_genl_se_io() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/apply fail Patch does not apply to net

Commit Message

shaozhengchao Jan. 5, 2023, 8:27 a.m. UTC
When nfc_genl_se_io() function is called, no matter it failed or succeed,
it does not put device. Fix it.

Fixes: 5ce3f32b5264 ("NFC: netlink: SE API implementation")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/nfc/netlink.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

Comments

Jiri Pirko Jan. 5, 2023, 1:55 p.m. UTC | #1
Thu, Jan 05, 2023 at 09:27:38AM CET, shaozhengchao@huawei.com wrote:
>When nfc_genl_se_io() function is called, no matter it failed or succeed,
>it does not put device. Fix it.
>
>Fixes: 5ce3f32b5264 ("NFC: netlink: SE API implementation")
>Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Jakub Kicinski Jan. 6, 2023, 6:18 a.m. UTC | #2
On Thu, 5 Jan 2023 16:27:38 +0800 Zhengchao Shao wrote:
> When nfc_genl_se_io() function is called, no matter it failed or succeed,
> it does not put device. Fix it.
> 
> Fixes: 5ce3f32b5264 ("NFC: netlink: SE API implementation")
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>

Does not apply
diff mbox series

Patch

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 9d91087b9399..86601d400bd6 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -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 ret;
 
 	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) {
+		ret = -EOPNOTSUPP;
+		goto out;
+	}
 
 	apdu_len = nla_len(info->attrs[NFC_ATTR_SE_APDU]);
-	if (apdu_len == 0)
-		return -EINVAL;
+	if (apdu_len == 0) {
+		ret = -EINVAL;
+		goto out;
+	}
 
 	apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]);
-	if (!apdu)
-		return -EINVAL;
+	if (!apdu) {
+		ret = -EINVAL;
+		goto out;
+	}
 
 	ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL);
-	if (!ctx)
-		return -ENOMEM;
+	if (!ctx) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	ctx->dev_idx = dev_idx;
 	ctx->se_idx = se_idx;
 
-	return nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
+	ret = nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
+
+out:
+	nfc_put_device(dev);
+	return ret;
 }
 
 static int nfc_genl_vendor_cmd(struct sk_buff *skb,