hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/nfc/netlink.c
....@@ -1039,10 +1039,13 @@
10391039 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10401040 if (!msg) {
10411041 rc = -ENOMEM;
1042
- goto exit;
1042
+ goto put_local;
10431043 }
10441044
10451045 rc = nfc_genl_send_params(msg, local, info->snd_portid, info->snd_seq);
1046
+
1047
+put_local:
1048
+ nfc_llcp_local_put(local);
10461049
10471050 exit:
10481051 device_unlock(&dev->dev);
....@@ -1105,7 +1108,7 @@
11051108 if (info->attrs[NFC_ATTR_LLC_PARAM_LTO]) {
11061109 if (dev->dep_link_up) {
11071110 rc = -EINPROGRESS;
1108
- goto exit;
1111
+ goto put_local;
11091112 }
11101113
11111114 local->lto = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_LTO]);
....@@ -1116,6 +1119,9 @@
11161119
11171120 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX])
11181121 local->miux = cpu_to_be16(miux);
1122
+
1123
+put_local:
1124
+ nfc_llcp_local_put(local);
11191125
11201126 exit:
11211127 device_unlock(&dev->dev);
....@@ -1172,7 +1178,7 @@
11721178
11731179 if (rc != 0) {
11741180 rc = -EINVAL;
1175
- goto exit;
1181
+ goto put_local;
11761182 }
11771183
11781184 if (!sdp_attrs[NFC_SDP_ATTR_URI])
....@@ -1191,7 +1197,7 @@
11911197 sdreq = nfc_llcp_build_sdreq_tlv(tid, uri, uri_len);
11921198 if (sdreq == NULL) {
11931199 rc = -ENOMEM;
1194
- goto exit;
1200
+ goto put_local;
11951201 }
11961202
11971203 tlvs_len += sdreq->tlv_len;
....@@ -1201,10 +1207,14 @@
12011207
12021208 if (hlist_empty(&sdreq_list)) {
12031209 rc = -EINVAL;
1204
- goto exit;
1210
+ goto put_local;
12051211 }
12061212
12071213 rc = nfc_llcp_send_snl_sdreq(local, &sdreq_list, tlvs_len);
1214
+
1215
+put_local:
1216
+ nfc_llcp_local_put(local);
1217
+
12081218 exit:
12091219 device_unlock(&dev->dev);
12101220
....@@ -1442,8 +1452,12 @@
14421452 rc = dev->ops->se_io(dev, se_idx, apdu,
14431453 apdu_length, cb, cb_context);
14441454
1455
+ device_unlock(&dev->dev);
1456
+ return rc;
1457
+
14451458 error:
14461459 device_unlock(&dev->dev);
1460
+ kfree(cb_context);
14471461 return rc;
14481462 }
14491463
....@@ -1497,6 +1511,7 @@
14971511 u32 dev_idx, se_idx;
14981512 u8 *apdu;
14991513 size_t apdu_len;
1514
+ int rc;
15001515
15011516 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
15021517 !info->attrs[NFC_ATTR_SE_INDEX] ||
....@@ -1510,25 +1525,37 @@
15101525 if (!dev)
15111526 return -ENODEV;
15121527
1513
- if (!dev->ops || !dev->ops->se_io)
1514
- return -ENOTSUPP;
1528
+ if (!dev->ops || !dev->ops->se_io) {
1529
+ rc = -EOPNOTSUPP;
1530
+ goto put_dev;
1531
+ }
15151532
15161533 apdu_len = nla_len(info->attrs[NFC_ATTR_SE_APDU]);
1517
- if (apdu_len == 0)
1518
- return -EINVAL;
1534
+ if (apdu_len == 0) {
1535
+ rc = -EINVAL;
1536
+ goto put_dev;
1537
+ }
15191538
15201539 apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]);
1521
- if (!apdu)
1522
- return -EINVAL;
1540
+ if (!apdu) {
1541
+ rc = -EINVAL;
1542
+ goto put_dev;
1543
+ }
15231544
15241545 ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL);
1525
- if (!ctx)
1526
- return -ENOMEM;
1546
+ if (!ctx) {
1547
+ rc = -ENOMEM;
1548
+ goto put_dev;
1549
+ }
15271550
15281551 ctx->dev_idx = dev_idx;
15291552 ctx->se_idx = se_idx;
15301553
1531
- return nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
1554
+ rc = nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
1555
+
1556
+put_dev:
1557
+ nfc_put_device(dev);
1558
+ return rc;
15321559 }
15331560
15341561 static int nfc_genl_vendor_cmd(struct sk_buff *skb,
....@@ -1551,14 +1578,21 @@
15511578 subcmd = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_SUBCMD]);
15521579
15531580 dev = nfc_get_device(dev_idx);
1554
- if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds)
1581
+ if (!dev)
15551582 return -ENODEV;
1583
+
1584
+ if (!dev->vendor_cmds || !dev->n_vendor_cmds) {
1585
+ err = -ENODEV;
1586
+ goto put_dev;
1587
+ }
15561588
15571589 if (info->attrs[NFC_ATTR_VENDOR_DATA]) {
15581590 data = nla_data(info->attrs[NFC_ATTR_VENDOR_DATA]);
15591591 data_len = nla_len(info->attrs[NFC_ATTR_VENDOR_DATA]);
1560
- if (data_len == 0)
1561
- return -EINVAL;
1592
+ if (data_len == 0) {
1593
+ err = -EINVAL;
1594
+ goto put_dev;
1595
+ }
15621596 } else {
15631597 data = NULL;
15641598 data_len = 0;
....@@ -1573,10 +1607,14 @@
15731607 dev->cur_cmd_info = info;
15741608 err = cmd->doit(dev, data, data_len);
15751609 dev->cur_cmd_info = NULL;
1576
- return err;
1610
+ goto put_dev;
15771611 }
15781612
1579
- return -EOPNOTSUPP;
1613
+ err = -EOPNOTSUPP;
1614
+
1615
+put_dev:
1616
+ nfc_put_device(dev);
1617
+ return err;
15801618 }
15811619
15821620 /* message building helper */