| .. | .. |
|---|
| 1039 | 1039 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 1040 | 1040 | if (!msg) { |
|---|
| 1041 | 1041 | rc = -ENOMEM; |
|---|
| 1042 | | - goto exit; |
|---|
| 1042 | + goto put_local; |
|---|
| 1043 | 1043 | } |
|---|
| 1044 | 1044 | |
|---|
| 1045 | 1045 | rc = nfc_genl_send_params(msg, local, info->snd_portid, info->snd_seq); |
|---|
| 1046 | + |
|---|
| 1047 | +put_local: |
|---|
| 1048 | + nfc_llcp_local_put(local); |
|---|
| 1046 | 1049 | |
|---|
| 1047 | 1050 | exit: |
|---|
| 1048 | 1051 | device_unlock(&dev->dev); |
|---|
| .. | .. |
|---|
| 1105 | 1108 | if (info->attrs[NFC_ATTR_LLC_PARAM_LTO]) { |
|---|
| 1106 | 1109 | if (dev->dep_link_up) { |
|---|
| 1107 | 1110 | rc = -EINPROGRESS; |
|---|
| 1108 | | - goto exit; |
|---|
| 1111 | + goto put_local; |
|---|
| 1109 | 1112 | } |
|---|
| 1110 | 1113 | |
|---|
| 1111 | 1114 | local->lto = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_LTO]); |
|---|
| .. | .. |
|---|
| 1116 | 1119 | |
|---|
| 1117 | 1120 | if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX]) |
|---|
| 1118 | 1121 | local->miux = cpu_to_be16(miux); |
|---|
| 1122 | + |
|---|
| 1123 | +put_local: |
|---|
| 1124 | + nfc_llcp_local_put(local); |
|---|
| 1119 | 1125 | |
|---|
| 1120 | 1126 | exit: |
|---|
| 1121 | 1127 | device_unlock(&dev->dev); |
|---|
| .. | .. |
|---|
| 1172 | 1178 | |
|---|
| 1173 | 1179 | if (rc != 0) { |
|---|
| 1174 | 1180 | rc = -EINVAL; |
|---|
| 1175 | | - goto exit; |
|---|
| 1181 | + goto put_local; |
|---|
| 1176 | 1182 | } |
|---|
| 1177 | 1183 | |
|---|
| 1178 | 1184 | if (!sdp_attrs[NFC_SDP_ATTR_URI]) |
|---|
| .. | .. |
|---|
| 1191 | 1197 | sdreq = nfc_llcp_build_sdreq_tlv(tid, uri, uri_len); |
|---|
| 1192 | 1198 | if (sdreq == NULL) { |
|---|
| 1193 | 1199 | rc = -ENOMEM; |
|---|
| 1194 | | - goto exit; |
|---|
| 1200 | + goto put_local; |
|---|
| 1195 | 1201 | } |
|---|
| 1196 | 1202 | |
|---|
| 1197 | 1203 | tlvs_len += sdreq->tlv_len; |
|---|
| .. | .. |
|---|
| 1201 | 1207 | |
|---|
| 1202 | 1208 | if (hlist_empty(&sdreq_list)) { |
|---|
| 1203 | 1209 | rc = -EINVAL; |
|---|
| 1204 | | - goto exit; |
|---|
| 1210 | + goto put_local; |
|---|
| 1205 | 1211 | } |
|---|
| 1206 | 1212 | |
|---|
| 1207 | 1213 | rc = nfc_llcp_send_snl_sdreq(local, &sdreq_list, tlvs_len); |
|---|
| 1214 | + |
|---|
| 1215 | +put_local: |
|---|
| 1216 | + nfc_llcp_local_put(local); |
|---|
| 1217 | + |
|---|
| 1208 | 1218 | exit: |
|---|
| 1209 | 1219 | device_unlock(&dev->dev); |
|---|
| 1210 | 1220 | |
|---|
| .. | .. |
|---|
| 1442 | 1452 | rc = dev->ops->se_io(dev, se_idx, apdu, |
|---|
| 1443 | 1453 | apdu_length, cb, cb_context); |
|---|
| 1444 | 1454 | |
|---|
| 1455 | + device_unlock(&dev->dev); |
|---|
| 1456 | + return rc; |
|---|
| 1457 | + |
|---|
| 1445 | 1458 | error: |
|---|
| 1446 | 1459 | device_unlock(&dev->dev); |
|---|
| 1460 | + kfree(cb_context); |
|---|
| 1447 | 1461 | return rc; |
|---|
| 1448 | 1462 | } |
|---|
| 1449 | 1463 | |
|---|
| .. | .. |
|---|
| 1497 | 1511 | u32 dev_idx, se_idx; |
|---|
| 1498 | 1512 | u8 *apdu; |
|---|
| 1499 | 1513 | size_t apdu_len; |
|---|
| 1514 | + int rc; |
|---|
| 1500 | 1515 | |
|---|
| 1501 | 1516 | if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || |
|---|
| 1502 | 1517 | !info->attrs[NFC_ATTR_SE_INDEX] || |
|---|
| .. | .. |
|---|
| 1510 | 1525 | if (!dev) |
|---|
| 1511 | 1526 | return -ENODEV; |
|---|
| 1512 | 1527 | |
|---|
| 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 | + } |
|---|
| 1515 | 1532 | |
|---|
| 1516 | 1533 | 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 | + } |
|---|
| 1519 | 1538 | |
|---|
| 1520 | 1539 | 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 | + } |
|---|
| 1523 | 1544 | |
|---|
| 1524 | 1545 | 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 | + } |
|---|
| 1527 | 1550 | |
|---|
| 1528 | 1551 | ctx->dev_idx = dev_idx; |
|---|
| 1529 | 1552 | ctx->se_idx = se_idx; |
|---|
| 1530 | 1553 | |
|---|
| 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; |
|---|
| 1532 | 1559 | } |
|---|
| 1533 | 1560 | |
|---|
| 1534 | 1561 | static int nfc_genl_vendor_cmd(struct sk_buff *skb, |
|---|
| .. | .. |
|---|
| 1551 | 1578 | subcmd = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_SUBCMD]); |
|---|
| 1552 | 1579 | |
|---|
| 1553 | 1580 | dev = nfc_get_device(dev_idx); |
|---|
| 1554 | | - if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds) |
|---|
| 1581 | + if (!dev) |
|---|
| 1555 | 1582 | return -ENODEV; |
|---|
| 1583 | + |
|---|
| 1584 | + if (!dev->vendor_cmds || !dev->n_vendor_cmds) { |
|---|
| 1585 | + err = -ENODEV; |
|---|
| 1586 | + goto put_dev; |
|---|
| 1587 | + } |
|---|
| 1556 | 1588 | |
|---|
| 1557 | 1589 | if (info->attrs[NFC_ATTR_VENDOR_DATA]) { |
|---|
| 1558 | 1590 | data = nla_data(info->attrs[NFC_ATTR_VENDOR_DATA]); |
|---|
| 1559 | 1591 | 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 | + } |
|---|
| 1562 | 1596 | } else { |
|---|
| 1563 | 1597 | data = NULL; |
|---|
| 1564 | 1598 | data_len = 0; |
|---|
| .. | .. |
|---|
| 1573 | 1607 | dev->cur_cmd_info = info; |
|---|
| 1574 | 1608 | err = cmd->doit(dev, data, data_len); |
|---|
| 1575 | 1609 | dev->cur_cmd_info = NULL; |
|---|
| 1576 | | - return err; |
|---|
| 1610 | + goto put_dev; |
|---|
| 1577 | 1611 | } |
|---|
| 1578 | 1612 | |
|---|
| 1579 | | - return -EOPNOTSUPP; |
|---|
| 1613 | + err = -EOPNOTSUPP; |
|---|
| 1614 | + |
|---|
| 1615 | +put_dev: |
|---|
| 1616 | + nfc_put_device(dev); |
|---|
| 1617 | + return err; |
|---|
| 1580 | 1618 | } |
|---|
| 1581 | 1619 | |
|---|
| 1582 | 1620 | /* message building helper */ |
|---|