hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/net/nfc/llcp_commands.c
....@@ -1,18 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2011 Intel Corporation. All rights reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
164 */
175
186 #define pr_fmt(fmt) "llcp: %s: " fmt, __func__
....@@ -27,7 +15,7 @@
2715 #include "nfc.h"
2816 #include "llcp.h"
2917
30
-static u8 llcp_tlv_length[LLCP_TLV_MAX] = {
18
+static const u8 llcp_tlv_length[LLCP_TLV_MAX] = {
3119 0,
3220 1, /* VERSION */
3321 2, /* MIUX */
....@@ -41,7 +29,7 @@
4129
4230 };
4331
44
-static u8 llcp_tlv8(u8 *tlv, u8 type)
32
+static u8 llcp_tlv8(const u8 *tlv, u8 type)
4533 {
4634 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]])
4735 return 0;
....@@ -49,7 +37,7 @@
4937 return tlv[2];
5038 }
5139
52
-static u16 llcp_tlv16(u8 *tlv, u8 type)
40
+static u16 llcp_tlv16(const u8 *tlv, u8 type)
5341 {
5442 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]])
5543 return 0;
....@@ -58,37 +46,37 @@
5846 }
5947
6048
61
-static u8 llcp_tlv_version(u8 *tlv)
49
+static u8 llcp_tlv_version(const u8 *tlv)
6250 {
6351 return llcp_tlv8(tlv, LLCP_TLV_VERSION);
6452 }
6553
66
-static u16 llcp_tlv_miux(u8 *tlv)
54
+static u16 llcp_tlv_miux(const u8 *tlv)
6755 {
6856 return llcp_tlv16(tlv, LLCP_TLV_MIUX) & 0x7ff;
6957 }
7058
71
-static u16 llcp_tlv_wks(u8 *tlv)
59
+static u16 llcp_tlv_wks(const u8 *tlv)
7260 {
7361 return llcp_tlv16(tlv, LLCP_TLV_WKS);
7462 }
7563
76
-static u16 llcp_tlv_lto(u8 *tlv)
64
+static u16 llcp_tlv_lto(const u8 *tlv)
7765 {
7866 return llcp_tlv8(tlv, LLCP_TLV_LTO);
7967 }
8068
81
-static u8 llcp_tlv_opt(u8 *tlv)
69
+static u8 llcp_tlv_opt(const u8 *tlv)
8270 {
8371 return llcp_tlv8(tlv, LLCP_TLV_OPT);
8472 }
8573
86
-static u8 llcp_tlv_rw(u8 *tlv)
74
+static u8 llcp_tlv_rw(const u8 *tlv)
8775 {
8876 return llcp_tlv8(tlv, LLCP_TLV_RW) & 0xf;
8977 }
9078
91
-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)
9280 {
9381 u8 *tlv, length;
9482
....@@ -142,7 +130,7 @@
142130 return sdres;
143131 }
144132
145
-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,
146134 size_t uri_len)
147135 {
148136 struct nfc_llcp_sdp_tlv *sdreq;
....@@ -202,9 +190,10 @@
202190 }
203191
204192 int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local,
205
- u8 *tlv_array, u16 tlv_array_len)
193
+ const u8 *tlv_array, u16 tlv_array_len)
206194 {
207
- u8 *tlv = tlv_array, type, length, offset = 0;
195
+ const u8 *tlv = tlv_array;
196
+ u8 type, length, offset = 0;
208197
209198 pr_debug("TLV array length %d\n", tlv_array_len);
210199
....@@ -251,9 +240,10 @@
251240 }
252241
253242 int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock,
254
- u8 *tlv_array, u16 tlv_array_len)
243
+ const u8 *tlv_array, u16 tlv_array_len)
255244 {
256
- u8 *tlv = tlv_array, type, length, offset = 0;
245
+ const u8 *tlv = tlv_array;
246
+ u8 type, length, offset = 0;
257247
258248 pr_debug("TLV array length %d\n", tlv_array_len);
259249
....@@ -307,7 +297,7 @@
307297 return pdu;
308298 }
309299
310
-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,
311301 u8 tlv_length)
312302 {
313303 /* XXX Add an skb length check */
....@@ -371,6 +361,7 @@
371361 struct sk_buff *skb;
372362 struct nfc_llcp_local *local;
373363 u16 size = 0;
364
+ int err;
374365
375366 pr_debug("Sending SYMM\n");
376367
....@@ -382,8 +373,10 @@
382373 size += dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE;
383374
384375 skb = alloc_skb(size, GFP_KERNEL);
385
- if (skb == NULL)
386
- return -ENOMEM;
376
+ if (skb == NULL) {
377
+ err = -ENOMEM;
378
+ goto out;
379
+ }
387380
388381 skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
389382
....@@ -393,17 +386,22 @@
393386
394387 nfc_llcp_send_to_raw_sock(local, skb, NFC_DIRECTION_TX);
395388
396
- return nfc_data_exchange(dev, local->target_idx, skb,
389
+ err = nfc_data_exchange(dev, local->target_idx, skb,
397390 nfc_llcp_recv, local);
391
+out:
392
+ nfc_llcp_local_put(local);
393
+ return err;
398394 }
399395
400396 int nfc_llcp_send_connect(struct nfc_llcp_sock *sock)
401397 {
402398 struct nfc_llcp_local *local;
403399 struct sk_buff *skb;
404
- u8 *service_name_tlv = NULL, service_name_tlv_length;
405
- u8 *miux_tlv = NULL, miux_tlv_length;
406
- 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;
407405 int err;
408406 u16 size = 0;
409407 __be16 miux;
....@@ -477,8 +475,9 @@
477475 {
478476 struct nfc_llcp_local *local;
479477 struct sk_buff *skb;
480
- u8 *miux_tlv = NULL, miux_tlv_length;
481
- 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;
482481 int err;
483482 u16 size = 0;
484483 __be16 miux;