hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/net/nfc/llcp_commands.c
....@@ -15,7 +15,7 @@
1515 #include "nfc.h"
1616 #include "llcp.h"
1717
18
-static u8 llcp_tlv_length[LLCP_TLV_MAX] = {
18
+static const u8 llcp_tlv_length[LLCP_TLV_MAX] = {
1919 0,
2020 1, /* VERSION */
2121 2, /* MIUX */
....@@ -29,7 +29,7 @@
2929
3030 };
3131
32
-static u8 llcp_tlv8(u8 *tlv, u8 type)
32
+static u8 llcp_tlv8(const u8 *tlv, u8 type)
3333 {
3434 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]])
3535 return 0;
....@@ -37,7 +37,7 @@
3737 return tlv[2];
3838 }
3939
40
-static u16 llcp_tlv16(u8 *tlv, u8 type)
40
+static u16 llcp_tlv16(const u8 *tlv, u8 type)
4141 {
4242 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]])
4343 return 0;
....@@ -46,37 +46,37 @@
4646 }
4747
4848
49
-static u8 llcp_tlv_version(u8 *tlv)
49
+static u8 llcp_tlv_version(const u8 *tlv)
5050 {
5151 return llcp_tlv8(tlv, LLCP_TLV_VERSION);
5252 }
5353
54
-static u16 llcp_tlv_miux(u8 *tlv)
54
+static u16 llcp_tlv_miux(const u8 *tlv)
5555 {
5656 return llcp_tlv16(tlv, LLCP_TLV_MIUX) & 0x7ff;
5757 }
5858
59
-static u16 llcp_tlv_wks(u8 *tlv)
59
+static u16 llcp_tlv_wks(const u8 *tlv)
6060 {
6161 return llcp_tlv16(tlv, LLCP_TLV_WKS);
6262 }
6363
64
-static u16 llcp_tlv_lto(u8 *tlv)
64
+static u16 llcp_tlv_lto(const u8 *tlv)
6565 {
6666 return llcp_tlv8(tlv, LLCP_TLV_LTO);
6767 }
6868
69
-static u8 llcp_tlv_opt(u8 *tlv)
69
+static u8 llcp_tlv_opt(const u8 *tlv)
7070 {
7171 return llcp_tlv8(tlv, LLCP_TLV_OPT);
7272 }
7373
74
-static u8 llcp_tlv_rw(u8 *tlv)
74
+static u8 llcp_tlv_rw(const u8 *tlv)
7575 {
7676 return llcp_tlv8(tlv, LLCP_TLV_RW) & 0xf;
7777 }
7878
79
-u8 *nfc_llcp_build_tlv(u8 type, u8 *value, u8 value_length, u8 *tlv_length)
79
+u8 *nfc_llcp_build_tlv(u8 type, const u8 *value, u8 value_length, u8 *tlv_length)
8080 {
8181 u8 *tlv, length;
8282
....@@ -130,7 +130,7 @@
130130 return sdres;
131131 }
132132
133
-struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, char *uri,
133
+struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, const char *uri,
134134 size_t uri_len)
135135 {
136136 struct nfc_llcp_sdp_tlv *sdreq;
....@@ -190,9 +190,10 @@
190190 }
191191
192192 int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local,
193
- u8 *tlv_array, u16 tlv_array_len)
193
+ const u8 *tlv_array, u16 tlv_array_len)
194194 {
195
- u8 *tlv = tlv_array, type, length, offset = 0;
195
+ const u8 *tlv = tlv_array;
196
+ u8 type, length, offset = 0;
196197
197198 pr_debug("TLV array length %d\n", tlv_array_len);
198199
....@@ -239,9 +240,10 @@
239240 }
240241
241242 int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock,
242
- u8 *tlv_array, u16 tlv_array_len)
243
+ const u8 *tlv_array, u16 tlv_array_len)
243244 {
244
- u8 *tlv = tlv_array, type, length, offset = 0;
245
+ const u8 *tlv = tlv_array;
246
+ u8 type, length, offset = 0;
245247
246248 pr_debug("TLV array length %d\n", tlv_array_len);
247249
....@@ -295,7 +297,7 @@
295297 return pdu;
296298 }
297299
298
-static struct sk_buff *llcp_add_tlv(struct sk_buff *pdu, u8 *tlv,
300
+static struct sk_buff *llcp_add_tlv(struct sk_buff *pdu, const u8 *tlv,
299301 u8 tlv_length)
300302 {
301303 /* XXX Add an skb length check */
....@@ -359,6 +361,7 @@
359361 struct sk_buff *skb;
360362 struct nfc_llcp_local *local;
361363 u16 size = 0;
364
+ int err;
362365
363366 pr_debug("Sending SYMM\n");
364367
....@@ -370,8 +373,10 @@
370373 size += dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE;
371374
372375 skb = alloc_skb(size, GFP_KERNEL);
373
- if (skb == NULL)
374
- return -ENOMEM;
376
+ if (skb == NULL) {
377
+ err = -ENOMEM;
378
+ goto out;
379
+ }
375380
376381 skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
377382
....@@ -381,17 +386,22 @@
381386
382387 nfc_llcp_send_to_raw_sock(local, skb, NFC_DIRECTION_TX);
383388
384
- return nfc_data_exchange(dev, local->target_idx, skb,
389
+ err = nfc_data_exchange(dev, local->target_idx, skb,
385390 nfc_llcp_recv, local);
391
+out:
392
+ nfc_llcp_local_put(local);
393
+ return err;
386394 }
387395
388396 int nfc_llcp_send_connect(struct nfc_llcp_sock *sock)
389397 {
390398 struct nfc_llcp_local *local;
391399 struct sk_buff *skb;
392
- u8 *service_name_tlv = NULL, service_name_tlv_length;
393
- u8 *miux_tlv = NULL, miux_tlv_length;
394
- u8 *rw_tlv = NULL, rw_tlv_length, rw;
400
+ const u8 *service_name_tlv = NULL;
401
+ const u8 *miux_tlv = NULL;
402
+ const u8 *rw_tlv = NULL;
403
+ u8 service_name_tlv_length = 0;
404
+ u8 miux_tlv_length, rw_tlv_length, rw;
395405 int err;
396406 u16 size = 0;
397407 __be16 miux;
....@@ -465,8 +475,9 @@
465475 {
466476 struct nfc_llcp_local *local;
467477 struct sk_buff *skb;
468
- u8 *miux_tlv = NULL, miux_tlv_length;
469
- u8 *rw_tlv = NULL, rw_tlv_length, rw;
478
+ const u8 *miux_tlv = NULL;
479
+ const u8 *rw_tlv = NULL;
480
+ u8 miux_tlv_length, rw_tlv_length, rw;
470481 int err;
471482 u16 size = 0;
472483 __be16 miux;