Skip to content

Commit 35d7a6f

Browse files
krzkdavem330
authored andcommitted
nfc: hci: pass callback data param as pointer in nci_request()
The nci_request() receives a callback function and unsigned long data argument "opt" which is passed to the callback. Almost all of the nci_request() callers pass pointer to a stack variable as data argument. Only few pass scalar value (e.g. u8). All such callbacks do not modify passed data argument and in previous commit they were made as const. However passing pointers via unsigned long removes the const annotation. The callback could simply cast unsigned long to a pointer to writeable memory. Use "const void *" as type of this "opt" argument to solve this and prevent modifying the pointed contents. This is also consistent with generic pattern of passing data arguments - via "void *". In few places which pass scalar values, use casts via "unsigned long" to suppress any warnings. Signed-off-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1e0dd56 commit 35d7a6f

File tree

3 files changed

+67
-72
lines changed

3 files changed

+67
-72
lines changed

include/net/nfc/nci_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ int nci_register_device(struct nci_dev *ndev);
276276
void nci_unregister_device(struct nci_dev *ndev);
277277
int nci_request(struct nci_dev *ndev,
278278
void (*req)(struct nci_dev *ndev,
279-
unsigned long opt),
280-
unsigned long opt, __u32 timeout);
279+
const void *opt),
280+
const void *opt, __u32 timeout);
281281
int nci_prop_cmd(struct nci_dev *ndev, __u8 oid, size_t len,
282282
const __u8 *payload);
283283
int nci_core_cmd(struct nci_dev *ndev, __u16 opcode, size_t len,

net/nfc/nci/core.c

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ static void nci_req_cancel(struct nci_dev *ndev, int err)
9595

9696
/* Execute request and wait for completion. */
9797
static int __nci_request(struct nci_dev *ndev,
98-
void (*req)(struct nci_dev *ndev, unsigned long opt),
99-
unsigned long opt, __u32 timeout)
98+
void (*req)(struct nci_dev *ndev, const void *opt),
99+
const void *opt, __u32 timeout)
100100
{
101101
int rc = 0;
102102
long completion_rc;
@@ -139,8 +139,8 @@ static int __nci_request(struct nci_dev *ndev,
139139

140140
inline int nci_request(struct nci_dev *ndev,
141141
void (*req)(struct nci_dev *ndev,
142-
unsigned long opt),
143-
unsigned long opt, __u32 timeout)
142+
const void *opt),
143+
const void *opt, __u32 timeout)
144144
{
145145
int rc;
146146

@@ -155,25 +155,25 @@ inline int nci_request(struct nci_dev *ndev,
155155
return rc;
156156
}
157157

158-
static void nci_reset_req(struct nci_dev *ndev, unsigned long opt)
158+
static void nci_reset_req(struct nci_dev *ndev, const void *opt)
159159
{
160160
struct nci_core_reset_cmd cmd;
161161

162162
cmd.reset_type = NCI_RESET_TYPE_RESET_CONFIG;
163163
nci_send_cmd(ndev, NCI_OP_CORE_RESET_CMD, 1, &cmd);
164164
}
165165

166-
static void nci_init_req(struct nci_dev *ndev, unsigned long opt)
166+
static void nci_init_req(struct nci_dev *ndev, const void *opt)
167167
{
168168
u8 plen = 0;
169169

170170
if (opt)
171171
plen = sizeof(struct nci_core_init_v2_cmd);
172172

173-
nci_send_cmd(ndev, NCI_OP_CORE_INIT_CMD, plen, (void *)opt);
173+
nci_send_cmd(ndev, NCI_OP_CORE_INIT_CMD, plen, opt);
174174
}
175175

176-
static void nci_init_complete_req(struct nci_dev *ndev, unsigned long opt)
176+
static void nci_init_complete_req(struct nci_dev *ndev, const void *opt)
177177
{
178178
struct nci_rf_disc_map_cmd cmd;
179179
struct disc_map_config *cfg = cmd.mapping_configs;
@@ -215,10 +215,9 @@ struct nci_set_config_param {
215215
const __u8 *val;
216216
};
217217

218-
static void nci_set_config_req(struct nci_dev *ndev, unsigned long opt)
218+
static void nci_set_config_req(struct nci_dev *ndev, const void *opt)
219219
{
220-
const struct nci_set_config_param *param =
221-
(struct nci_set_config_param *)opt;
220+
const struct nci_set_config_param *param = opt;
222221
struct nci_core_set_config_cmd cmd;
223222

224223
BUG_ON(param->len > NCI_MAX_PARAM_LEN);
@@ -236,10 +235,9 @@ struct nci_rf_discover_param {
236235
__u32 tm_protocols;
237236
};
238237

239-
static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt)
238+
static void nci_rf_discover_req(struct nci_dev *ndev, const void *opt)
240239
{
241-
const struct nci_rf_discover_param *param =
242-
(struct nci_rf_discover_param *)opt;
240+
const struct nci_rf_discover_param *param = opt;
243241
struct nci_rf_disc_cmd cmd;
244242

245243
cmd.num_disc_configs = 0;
@@ -302,10 +300,9 @@ struct nci_rf_discover_select_param {
302300
__u8 rf_protocol;
303301
};
304302

305-
static void nci_rf_discover_select_req(struct nci_dev *ndev, unsigned long opt)
303+
static void nci_rf_discover_select_req(struct nci_dev *ndev, const void *opt)
306304
{
307-
const struct nci_rf_discover_select_param *param =
308-
(struct nci_rf_discover_select_param *)opt;
305+
const struct nci_rf_discover_select_param *param = opt;
309306
struct nci_rf_discover_select_cmd cmd;
310307

311308
cmd.rf_discovery_id = param->rf_discovery_id;
@@ -329,11 +326,11 @@ static void nci_rf_discover_select_req(struct nci_dev *ndev, unsigned long opt)
329326
sizeof(struct nci_rf_discover_select_cmd), &cmd);
330327
}
331328

332-
static void nci_rf_deactivate_req(struct nci_dev *ndev, unsigned long opt)
329+
static void nci_rf_deactivate_req(struct nci_dev *ndev, const void *opt)
333330
{
334331
struct nci_rf_deactivate_cmd cmd;
335332

336-
cmd.type = opt;
333+
cmd.type = (unsigned long)opt;
337334

338335
nci_send_cmd(ndev, NCI_OP_RF_DEACTIVATE_CMD,
339336
sizeof(struct nci_rf_deactivate_cmd), &cmd);
@@ -345,10 +342,9 @@ struct nci_cmd_param {
345342
const __u8 *payload;
346343
};
347344

348-
static void nci_generic_req(struct nci_dev *ndev, unsigned long opt)
345+
static void nci_generic_req(struct nci_dev *ndev, const void *opt)
349346
{
350-
const struct nci_cmd_param *param =
351-
(struct nci_cmd_param *)opt;
347+
const struct nci_cmd_param *param = opt;
352348

353349
nci_send_cmd(ndev, param->opcode, param->len, param->payload);
354350
}
@@ -361,7 +357,7 @@ int nci_prop_cmd(struct nci_dev *ndev, __u8 oid, size_t len, const __u8 *payload
361357
param.len = len;
362358
param.payload = payload;
363359

364-
return __nci_request(ndev, nci_generic_req, (unsigned long)&param,
360+
return __nci_request(ndev, nci_generic_req, &param,
365361
msecs_to_jiffies(NCI_CMD_TIMEOUT));
366362
}
367363
EXPORT_SYMBOL(nci_prop_cmd);
@@ -375,21 +371,21 @@ int nci_core_cmd(struct nci_dev *ndev, __u16 opcode, size_t len,
375371
param.len = len;
376372
param.payload = payload;
377373

378-
return __nci_request(ndev, nci_generic_req, (unsigned long)&param,
374+
return __nci_request(ndev, nci_generic_req, &param,
379375
msecs_to_jiffies(NCI_CMD_TIMEOUT));
380376
}
381377
EXPORT_SYMBOL(nci_core_cmd);
382378

383379
int nci_core_reset(struct nci_dev *ndev)
384380
{
385-
return __nci_request(ndev, nci_reset_req, 0,
381+
return __nci_request(ndev, nci_reset_req, (void *)0,
386382
msecs_to_jiffies(NCI_RESET_TIMEOUT));
387383
}
388384
EXPORT_SYMBOL(nci_core_reset);
389385

390386
int nci_core_init(struct nci_dev *ndev)
391387
{
392-
return __nci_request(ndev, nci_init_req, 0,
388+
return __nci_request(ndev, nci_init_req, (void *)0,
393389
msecs_to_jiffies(NCI_INIT_TIMEOUT));
394390
}
395391
EXPORT_SYMBOL(nci_core_init);
@@ -399,9 +395,9 @@ struct nci_loopback_data {
399395
struct sk_buff *data;
400396
};
401397

402-
static void nci_send_data_req(struct nci_dev *ndev, unsigned long opt)
398+
static void nci_send_data_req(struct nci_dev *ndev, const void *opt)
403399
{
404-
const struct nci_loopback_data *data = (struct nci_loopback_data *)opt;
400+
const struct nci_loopback_data *data = opt;
405401

406402
nci_send_data(ndev, data->conn_id, data->data);
407403
}
@@ -462,7 +458,7 @@ int nci_nfcc_loopback(struct nci_dev *ndev, const void *data, size_t data_len,
462458
loopback_data.data = skb;
463459

464460
ndev->cur_conn_id = conn_id;
465-
r = nci_request(ndev, nci_send_data_req, (unsigned long)&loopback_data,
461+
r = nci_request(ndev, nci_send_data_req, &loopback_data,
466462
msecs_to_jiffies(NCI_DATA_TIMEOUT));
467463
if (r == NCI_STATUS_OK && resp)
468464
*resp = conn_info->rx_skb;
@@ -495,7 +491,7 @@ static int nci_open_device(struct nci_dev *ndev)
495491
rc = ndev->ops->init(ndev);
496492

497493
if (!rc) {
498-
rc = __nci_request(ndev, nci_reset_req, 0,
494+
rc = __nci_request(ndev, nci_reset_req, (void *)0,
499495
msecs_to_jiffies(NCI_RESET_TIMEOUT));
500496
}
501497

@@ -508,10 +504,10 @@ static int nci_open_device(struct nci_dev *ndev)
508504
.feature1 = NCI_FEATURE_DISABLE,
509505
.feature2 = NCI_FEATURE_DISABLE
510506
};
511-
unsigned long opt = 0;
507+
const void *opt = NULL;
512508

513509
if (ndev->nci_ver & NCI_VER_2_MASK)
514-
opt = (unsigned long)&nci_init_v2_cmd;
510+
opt = &nci_init_v2_cmd;
515511

516512
rc = __nci_request(ndev, nci_init_req, opt,
517513
msecs_to_jiffies(NCI_INIT_TIMEOUT));
@@ -521,7 +517,7 @@ static int nci_open_device(struct nci_dev *ndev)
521517
rc = ndev->ops->post_setup(ndev);
522518

523519
if (!rc) {
524-
rc = __nci_request(ndev, nci_init_complete_req, 0,
520+
rc = __nci_request(ndev, nci_init_complete_req, (void *)0,
525521
msecs_to_jiffies(NCI_INIT_TIMEOUT));
526522
}
527523

@@ -571,7 +567,7 @@ static int nci_close_device(struct nci_dev *ndev)
571567
atomic_set(&ndev->cmd_cnt, 1);
572568

573569
set_bit(NCI_INIT, &ndev->flags);
574-
__nci_request(ndev, nci_reset_req, 0,
570+
__nci_request(ndev, nci_reset_req, (void *)0,
575571
msecs_to_jiffies(NCI_RESET_TIMEOUT));
576572

577573
/* After this point our queues are empty
@@ -637,15 +633,15 @@ int nci_set_config(struct nci_dev *ndev, __u8 id, size_t len, const __u8 *val)
637633
param.len = len;
638634
param.val = val;
639635

640-
return __nci_request(ndev, nci_set_config_req, (unsigned long)&param,
636+
return __nci_request(ndev, nci_set_config_req, &param,
641637
msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT));
642638
}
643639
EXPORT_SYMBOL(nci_set_config);
644640

645-
static void nci_nfcee_discover_req(struct nci_dev *ndev, unsigned long opt)
641+
static void nci_nfcee_discover_req(struct nci_dev *ndev, const void *opt)
646642
{
647643
struct nci_nfcee_discover_cmd cmd;
648-
__u8 action = opt;
644+
__u8 action = (unsigned long)opt;
649645

650646
cmd.discovery_action = action;
651647

@@ -654,15 +650,16 @@ static void nci_nfcee_discover_req(struct nci_dev *ndev, unsigned long opt)
654650

655651
int nci_nfcee_discover(struct nci_dev *ndev, u8 action)
656652
{
657-
return __nci_request(ndev, nci_nfcee_discover_req, action,
653+
unsigned long opt = action;
654+
655+
return __nci_request(ndev, nci_nfcee_discover_req, (void *)opt,
658656
msecs_to_jiffies(NCI_CMD_TIMEOUT));
659657
}
660658
EXPORT_SYMBOL(nci_nfcee_discover);
661659

662-
static void nci_nfcee_mode_set_req(struct nci_dev *ndev, unsigned long opt)
660+
static void nci_nfcee_mode_set_req(struct nci_dev *ndev, const void *opt)
663661
{
664-
const struct nci_nfcee_mode_set_cmd *cmd =
665-
(struct nci_nfcee_mode_set_cmd *)opt;
662+
const struct nci_nfcee_mode_set_cmd *cmd = opt;
666663

667664
nci_send_cmd(ndev, NCI_OP_NFCEE_MODE_SET_CMD,
668665
sizeof(struct nci_nfcee_mode_set_cmd), cmd);
@@ -675,16 +672,14 @@ int nci_nfcee_mode_set(struct nci_dev *ndev, u8 nfcee_id, u8 nfcee_mode)
675672
cmd.nfcee_id = nfcee_id;
676673
cmd.nfcee_mode = nfcee_mode;
677674

678-
return __nci_request(ndev, nci_nfcee_mode_set_req,
679-
(unsigned long)&cmd,
675+
return __nci_request(ndev, nci_nfcee_mode_set_req, &cmd,
680676
msecs_to_jiffies(NCI_CMD_TIMEOUT));
681677
}
682678
EXPORT_SYMBOL(nci_nfcee_mode_set);
683679

684-
static void nci_core_conn_create_req(struct nci_dev *ndev, unsigned long opt)
680+
static void nci_core_conn_create_req(struct nci_dev *ndev, const void *opt)
685681
{
686-
const struct core_conn_create_data *data =
687-
(struct core_conn_create_data *)opt;
682+
const struct core_conn_create_data *data = opt;
688683

689684
nci_send_cmd(ndev, NCI_OP_CORE_CONN_CREATE_CMD, data->length, data->cmd);
690685
}
@@ -721,24 +716,26 @@ int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type,
721716
}
722717
ndev->cur_dest_type = destination_type;
723718

724-
r = __nci_request(ndev, nci_core_conn_create_req, (unsigned long)&data,
719+
r = __nci_request(ndev, nci_core_conn_create_req, &data,
725720
msecs_to_jiffies(NCI_CMD_TIMEOUT));
726721
kfree(cmd);
727722
return r;
728723
}
729724
EXPORT_SYMBOL(nci_core_conn_create);
730725

731-
static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt)
726+
static void nci_core_conn_close_req(struct nci_dev *ndev, const void *opt)
732727
{
733-
__u8 conn_id = opt;
728+
__u8 conn_id = (unsigned long)opt;
734729

735730
nci_send_cmd(ndev, NCI_OP_CORE_CONN_CLOSE_CMD, 1, &conn_id);
736731
}
737732

738733
int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id)
739734
{
735+
unsigned long opt = conn_id;
736+
740737
ndev->cur_conn_id = conn_id;
741-
return __nci_request(ndev, nci_core_conn_close_req, conn_id,
738+
return __nci_request(ndev, nci_core_conn_close_req, (void *)opt,
742739
msecs_to_jiffies(NCI_CMD_TIMEOUT));
743740
}
744741
EXPORT_SYMBOL(nci_core_conn_close);
@@ -758,14 +755,14 @@ static int nci_set_local_general_bytes(struct nfc_dev *nfc_dev)
758755

759756
param.id = NCI_PN_ATR_REQ_GEN_BYTES;
760757

761-
rc = nci_request(ndev, nci_set_config_req, (unsigned long)&param,
758+
rc = nci_request(ndev, nci_set_config_req, &param,
762759
msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT));
763760
if (rc)
764761
return rc;
765762

766763
param.id = NCI_LN_ATR_RES_GEN_BYTES;
767764

768-
return nci_request(ndev, nci_set_config_req, (unsigned long)&param,
765+
return nci_request(ndev, nci_set_config_req, &param,
769766
msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT));
770767
}
771768

@@ -815,7 +812,7 @@ static int nci_start_poll(struct nfc_dev *nfc_dev,
815812
pr_debug("target active or w4 select, implicitly deactivate\n");
816813

817814
rc = nci_request(ndev, nci_rf_deactivate_req,
818-
NCI_DEACTIVATE_TYPE_IDLE_MODE,
815+
(void *)NCI_DEACTIVATE_TYPE_IDLE_MODE,
819816
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
820817
if (rc)
821818
return -EBUSY;
@@ -837,7 +834,7 @@ static int nci_start_poll(struct nfc_dev *nfc_dev,
837834

838835
param.im_protocols = im_protocols;
839836
param.tm_protocols = tm_protocols;
840-
rc = nci_request(ndev, nci_rf_discover_req, (unsigned long)&param,
837+
rc = nci_request(ndev, nci_rf_discover_req, &param,
841838
msecs_to_jiffies(NCI_RF_DISC_TIMEOUT));
842839

843840
if (!rc)
@@ -856,7 +853,8 @@ static void nci_stop_poll(struct nfc_dev *nfc_dev)
856853
return;
857854
}
858855

859-
nci_request(ndev, nci_rf_deactivate_req, NCI_DEACTIVATE_TYPE_IDLE_MODE,
856+
nci_request(ndev, nci_rf_deactivate_req,
857+
(void *)NCI_DEACTIVATE_TYPE_IDLE_MODE,
860858
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
861859
}
862860

@@ -915,8 +913,7 @@ static int nci_activate_target(struct nfc_dev *nfc_dev,
915913
else
916914
param.rf_protocol = NCI_RF_PROTOCOL_NFC_DEP;
917915

918-
rc = nci_request(ndev, nci_rf_discover_select_req,
919-
(unsigned long)&param,
916+
rc = nci_request(ndev, nci_rf_discover_select_req, &param,
920917
msecs_to_jiffies(NCI_RF_DISC_SELECT_TIMEOUT));
921918
}
922919

@@ -931,7 +928,7 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
931928
__u8 mode)
932929
{
933930
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
934-
u8 nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE;
931+
unsigned long nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE;
935932

936933
pr_debug("entry\n");
937934

@@ -949,7 +946,7 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
949946
}
950947

951948
if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
952-
nci_request(ndev, nci_rf_deactivate_req, nci_mode,
949+
nci_request(ndev, nci_rf_deactivate_req, (void *)nci_mode,
953950
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
954951
}
955952
}
@@ -987,8 +984,8 @@ static int nci_dep_link_down(struct nfc_dev *nfc_dev)
987984
} else {
988985
if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE ||
989986
atomic_read(&ndev->state) == NCI_DISCOVERY) {
990-
nci_request(ndev, nci_rf_deactivate_req, 0,
991-
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
987+
nci_request(ndev, nci_rf_deactivate_req, (void *)0,
988+
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
992989
}
993990

994991
rc = nfc_tm_deactivated(nfc_dev);

0 commit comments

Comments
 (0)