Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <krzysztof.kozlowski@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Krzysztof Kozlowski and committed by
David S. Miller
35d7a6f1 1e0dd56e

+67 -72
+2 -2
include/net/nfc/nci_core.h
··· 276 276 void nci_unregister_device(struct nci_dev *ndev); 277 277 int nci_request(struct nci_dev *ndev, 278 278 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); 281 281 int nci_prop_cmd(struct nci_dev *ndev, __u8 oid, size_t len, 282 282 const __u8 *payload); 283 283 int nci_core_cmd(struct nci_dev *ndev, __u16 opcode, size_t len,
+58 -61
net/nfc/nci/core.c
··· 95 95 96 96 /* Execute request and wait for completion. */ 97 97 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) 100 100 { 101 101 int rc = 0; 102 102 long completion_rc; ··· 139 139 140 140 inline int nci_request(struct nci_dev *ndev, 141 141 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) 144 144 { 145 145 int rc; 146 146 ··· 155 155 return rc; 156 156 } 157 157 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) 159 159 { 160 160 struct nci_core_reset_cmd cmd; 161 161 ··· 163 163 nci_send_cmd(ndev, NCI_OP_CORE_RESET_CMD, 1, &cmd); 164 164 } 165 165 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) 167 167 { 168 168 u8 plen = 0; 169 169 170 170 if (opt) 171 171 plen = sizeof(struct nci_core_init_v2_cmd); 172 172 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); 174 174 } 175 175 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) 177 177 { 178 178 struct nci_rf_disc_map_cmd cmd; 179 179 struct disc_map_config *cfg = cmd.mapping_configs; ··· 215 215 const __u8 *val; 216 216 }; 217 217 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) 219 219 { 220 - const struct nci_set_config_param *param = 221 - (struct nci_set_config_param *)opt; 220 + const struct nci_set_config_param *param = opt; 222 221 struct nci_core_set_config_cmd cmd; 223 222 224 223 BUG_ON(param->len > NCI_MAX_PARAM_LEN); ··· 235 236 __u32 tm_protocols; 236 237 }; 237 238 238 - static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt) 239 + static void nci_rf_discover_req(struct nci_dev *ndev, const void *opt) 239 240 { 240 - const struct nci_rf_discover_param *param = 241 - (struct nci_rf_discover_param *)opt; 241 + const struct nci_rf_discover_param *param = opt; 242 242 struct nci_rf_disc_cmd cmd; 243 243 244 244 cmd.num_disc_configs = 0; ··· 300 302 __u8 rf_protocol; 301 303 }; 302 304 303 - static void nci_rf_discover_select_req(struct nci_dev *ndev, unsigned long opt) 305 + static void nci_rf_discover_select_req(struct nci_dev *ndev, const void *opt) 304 306 { 305 - const struct nci_rf_discover_select_param *param = 306 - (struct nci_rf_discover_select_param *)opt; 307 + const struct nci_rf_discover_select_param *param = opt; 307 308 struct nci_rf_discover_select_cmd cmd; 308 309 309 310 cmd.rf_discovery_id = param->rf_discovery_id; ··· 326 329 sizeof(struct nci_rf_discover_select_cmd), &cmd); 327 330 } 328 331 329 - static void nci_rf_deactivate_req(struct nci_dev *ndev, unsigned long opt) 332 + static void nci_rf_deactivate_req(struct nci_dev *ndev, const void *opt) 330 333 { 331 334 struct nci_rf_deactivate_cmd cmd; 332 335 333 - cmd.type = opt; 336 + cmd.type = (unsigned long)opt; 334 337 335 338 nci_send_cmd(ndev, NCI_OP_RF_DEACTIVATE_CMD, 336 339 sizeof(struct nci_rf_deactivate_cmd), &cmd); ··· 342 345 const __u8 *payload; 343 346 }; 344 347 345 - static void nci_generic_req(struct nci_dev *ndev, unsigned long opt) 348 + static void nci_generic_req(struct nci_dev *ndev, const void *opt) 346 349 { 347 - const struct nci_cmd_param *param = 348 - (struct nci_cmd_param *)opt; 350 + const struct nci_cmd_param *param = opt; 349 351 350 352 nci_send_cmd(ndev, param->opcode, param->len, param->payload); 351 353 } ··· 357 361 param.len = len; 358 362 param.payload = payload; 359 363 360 - return __nci_request(ndev, nci_generic_req, (unsigned long)&param, 364 + return __nci_request(ndev, nci_generic_req, &param, 361 365 msecs_to_jiffies(NCI_CMD_TIMEOUT)); 362 366 } 363 367 EXPORT_SYMBOL(nci_prop_cmd); ··· 371 375 param.len = len; 372 376 param.payload = payload; 373 377 374 - return __nci_request(ndev, nci_generic_req, (unsigned long)&param, 378 + return __nci_request(ndev, nci_generic_req, &param, 375 379 msecs_to_jiffies(NCI_CMD_TIMEOUT)); 376 380 } 377 381 EXPORT_SYMBOL(nci_core_cmd); 378 382 379 383 int nci_core_reset(struct nci_dev *ndev) 380 384 { 381 - return __nci_request(ndev, nci_reset_req, 0, 385 + return __nci_request(ndev, nci_reset_req, (void *)0, 382 386 msecs_to_jiffies(NCI_RESET_TIMEOUT)); 383 387 } 384 388 EXPORT_SYMBOL(nci_core_reset); 385 389 386 390 int nci_core_init(struct nci_dev *ndev) 387 391 { 388 - return __nci_request(ndev, nci_init_req, 0, 392 + return __nci_request(ndev, nci_init_req, (void *)0, 389 393 msecs_to_jiffies(NCI_INIT_TIMEOUT)); 390 394 } 391 395 EXPORT_SYMBOL(nci_core_init); ··· 395 399 struct sk_buff *data; 396 400 }; 397 401 398 - static void nci_send_data_req(struct nci_dev *ndev, unsigned long opt) 402 + static void nci_send_data_req(struct nci_dev *ndev, const void *opt) 399 403 { 400 - const struct nci_loopback_data *data = (struct nci_loopback_data *)opt; 404 + const struct nci_loopback_data *data = opt; 401 405 402 406 nci_send_data(ndev, data->conn_id, data->data); 403 407 } ··· 458 462 loopback_data.data = skb; 459 463 460 464 ndev->cur_conn_id = conn_id; 461 - r = nci_request(ndev, nci_send_data_req, (unsigned long)&loopback_data, 465 + r = nci_request(ndev, nci_send_data_req, &loopback_data, 462 466 msecs_to_jiffies(NCI_DATA_TIMEOUT)); 463 467 if (r == NCI_STATUS_OK && resp) 464 468 *resp = conn_info->rx_skb; ··· 491 495 rc = ndev->ops->init(ndev); 492 496 493 497 if (!rc) { 494 - rc = __nci_request(ndev, nci_reset_req, 0, 498 + rc = __nci_request(ndev, nci_reset_req, (void *)0, 495 499 msecs_to_jiffies(NCI_RESET_TIMEOUT)); 496 500 } 497 501 ··· 504 508 .feature1 = NCI_FEATURE_DISABLE, 505 509 .feature2 = NCI_FEATURE_DISABLE 506 510 }; 507 - unsigned long opt = 0; 511 + const void *opt = NULL; 508 512 509 513 if (ndev->nci_ver & NCI_VER_2_MASK) 510 - opt = (unsigned long)&nci_init_v2_cmd; 514 + opt = &nci_init_v2_cmd; 511 515 512 516 rc = __nci_request(ndev, nci_init_req, opt, 513 517 msecs_to_jiffies(NCI_INIT_TIMEOUT)); ··· 517 521 rc = ndev->ops->post_setup(ndev); 518 522 519 523 if (!rc) { 520 - rc = __nci_request(ndev, nci_init_complete_req, 0, 524 + rc = __nci_request(ndev, nci_init_complete_req, (void *)0, 521 525 msecs_to_jiffies(NCI_INIT_TIMEOUT)); 522 526 } 523 527 ··· 567 571 atomic_set(&ndev->cmd_cnt, 1); 568 572 569 573 set_bit(NCI_INIT, &ndev->flags); 570 - __nci_request(ndev, nci_reset_req, 0, 574 + __nci_request(ndev, nci_reset_req, (void *)0, 571 575 msecs_to_jiffies(NCI_RESET_TIMEOUT)); 572 576 573 577 /* After this point our queues are empty ··· 633 637 param.len = len; 634 638 param.val = val; 635 639 636 - return __nci_request(ndev, nci_set_config_req, (unsigned long)&param, 640 + return __nci_request(ndev, nci_set_config_req, &param, 637 641 msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT)); 638 642 } 639 643 EXPORT_SYMBOL(nci_set_config); 640 644 641 - static void nci_nfcee_discover_req(struct nci_dev *ndev, unsigned long opt) 645 + static void nci_nfcee_discover_req(struct nci_dev *ndev, const void *opt) 642 646 { 643 647 struct nci_nfcee_discover_cmd cmd; 644 - __u8 action = opt; 648 + __u8 action = (unsigned long)opt; 645 649 646 650 cmd.discovery_action = action; 647 651 ··· 650 654 651 655 int nci_nfcee_discover(struct nci_dev *ndev, u8 action) 652 656 { 653 - return __nci_request(ndev, nci_nfcee_discover_req, action, 657 + unsigned long opt = action; 658 + 659 + return __nci_request(ndev, nci_nfcee_discover_req, (void *)opt, 654 660 msecs_to_jiffies(NCI_CMD_TIMEOUT)); 655 661 } 656 662 EXPORT_SYMBOL(nci_nfcee_discover); 657 663 658 - static void nci_nfcee_mode_set_req(struct nci_dev *ndev, unsigned long opt) 664 + static void nci_nfcee_mode_set_req(struct nci_dev *ndev, const void *opt) 659 665 { 660 - const struct nci_nfcee_mode_set_cmd *cmd = 661 - (struct nci_nfcee_mode_set_cmd *)opt; 666 + const struct nci_nfcee_mode_set_cmd *cmd = opt; 662 667 663 668 nci_send_cmd(ndev, NCI_OP_NFCEE_MODE_SET_CMD, 664 669 sizeof(struct nci_nfcee_mode_set_cmd), cmd); ··· 672 675 cmd.nfcee_id = nfcee_id; 673 676 cmd.nfcee_mode = nfcee_mode; 674 677 675 - return __nci_request(ndev, nci_nfcee_mode_set_req, 676 - (unsigned long)&cmd, 678 + return __nci_request(ndev, nci_nfcee_mode_set_req, &cmd, 677 679 msecs_to_jiffies(NCI_CMD_TIMEOUT)); 678 680 } 679 681 EXPORT_SYMBOL(nci_nfcee_mode_set); 680 682 681 - static void nci_core_conn_create_req(struct nci_dev *ndev, unsigned long opt) 683 + static void nci_core_conn_create_req(struct nci_dev *ndev, const void *opt) 682 684 { 683 - const struct core_conn_create_data *data = 684 - (struct core_conn_create_data *)opt; 685 + const struct core_conn_create_data *data = opt; 685 686 686 687 nci_send_cmd(ndev, NCI_OP_CORE_CONN_CREATE_CMD, data->length, data->cmd); 687 688 } ··· 716 721 } 717 722 ndev->cur_dest_type = destination_type; 718 723 719 - r = __nci_request(ndev, nci_core_conn_create_req, (unsigned long)&data, 724 + r = __nci_request(ndev, nci_core_conn_create_req, &data, 720 725 msecs_to_jiffies(NCI_CMD_TIMEOUT)); 721 726 kfree(cmd); 722 727 return r; 723 728 } 724 729 EXPORT_SYMBOL(nci_core_conn_create); 725 730 726 - static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt) 731 + static void nci_core_conn_close_req(struct nci_dev *ndev, const void *opt) 727 732 { 728 - __u8 conn_id = opt; 733 + __u8 conn_id = (unsigned long)opt; 729 734 730 735 nci_send_cmd(ndev, NCI_OP_CORE_CONN_CLOSE_CMD, 1, &conn_id); 731 736 } 732 737 733 738 int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id) 734 739 { 740 + unsigned long opt = conn_id; 741 + 735 742 ndev->cur_conn_id = conn_id; 736 - return __nci_request(ndev, nci_core_conn_close_req, conn_id, 743 + return __nci_request(ndev, nci_core_conn_close_req, (void *)opt, 737 744 msecs_to_jiffies(NCI_CMD_TIMEOUT)); 738 745 } 739 746 EXPORT_SYMBOL(nci_core_conn_close); ··· 755 758 756 759 param.id = NCI_PN_ATR_REQ_GEN_BYTES; 757 760 758 - rc = nci_request(ndev, nci_set_config_req, (unsigned long)&param, 761 + rc = nci_request(ndev, nci_set_config_req, &param, 759 762 msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT)); 760 763 if (rc) 761 764 return rc; 762 765 763 766 param.id = NCI_LN_ATR_RES_GEN_BYTES; 764 767 765 - return nci_request(ndev, nci_set_config_req, (unsigned long)&param, 768 + return nci_request(ndev, nci_set_config_req, &param, 766 769 msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT)); 767 770 } 768 771 ··· 812 815 pr_debug("target active or w4 select, implicitly deactivate\n"); 813 816 814 817 rc = nci_request(ndev, nci_rf_deactivate_req, 815 - NCI_DEACTIVATE_TYPE_IDLE_MODE, 818 + (void *)NCI_DEACTIVATE_TYPE_IDLE_MODE, 816 819 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); 817 820 if (rc) 818 821 return -EBUSY; ··· 834 837 835 838 param.im_protocols = im_protocols; 836 839 param.tm_protocols = tm_protocols; 837 - rc = nci_request(ndev, nci_rf_discover_req, (unsigned long)&param, 840 + rc = nci_request(ndev, nci_rf_discover_req, &param, 838 841 msecs_to_jiffies(NCI_RF_DISC_TIMEOUT)); 839 842 840 843 if (!rc) ··· 853 856 return; 854 857 } 855 858 856 - nci_request(ndev, nci_rf_deactivate_req, NCI_DEACTIVATE_TYPE_IDLE_MODE, 859 + nci_request(ndev, nci_rf_deactivate_req, 860 + (void *)NCI_DEACTIVATE_TYPE_IDLE_MODE, 857 861 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); 858 862 } 859 863 ··· 913 915 else 914 916 param.rf_protocol = NCI_RF_PROTOCOL_NFC_DEP; 915 917 916 - rc = nci_request(ndev, nci_rf_discover_select_req, 917 - (unsigned long)&param, 918 + rc = nci_request(ndev, nci_rf_discover_select_req, &param, 918 919 msecs_to_jiffies(NCI_RF_DISC_SELECT_TIMEOUT)); 919 920 } 920 921 ··· 928 931 __u8 mode) 929 932 { 930 933 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 931 - u8 nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE; 934 + unsigned long nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE; 932 935 933 936 pr_debug("entry\n"); 934 937 ··· 946 949 } 947 950 948 951 if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) { 949 - nci_request(ndev, nci_rf_deactivate_req, nci_mode, 952 + nci_request(ndev, nci_rf_deactivate_req, (void *)nci_mode, 950 953 msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); 951 954 } 952 955 } ··· 984 987 } else { 985 988 if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE || 986 989 atomic_read(&ndev->state) == NCI_DISCOVERY) { 987 - nci_request(ndev, nci_rf_deactivate_req, 0, 988 - msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); 990 + nci_request(ndev, nci_rf_deactivate_req, (void *)0, 991 + msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); 989 992 } 990 993 991 994 rc = nfc_tm_deactivated(nfc_dev);
+7 -9
net/nfc/nci/hci.c
··· 195 195 return i; 196 196 } 197 197 198 - static void nci_hci_send_data_req(struct nci_dev *ndev, unsigned long opt) 198 + static void nci_hci_send_data_req(struct nci_dev *ndev, const void *opt) 199 199 { 200 - const struct nci_data *data = (struct nci_data *)opt; 200 + const struct nci_data *data = opt; 201 201 202 202 nci_hci_send_data(ndev, data->pipe, data->cmd, 203 203 data->data, data->data_len); ··· 240 240 data.data = param; 241 241 data.data_len = param_len; 242 242 243 - r = nci_request(ndev, nci_hci_send_data_req, (unsigned long)&data, 243 + r = nci_request(ndev, nci_hci_send_data_req, &data, 244 244 msecs_to_jiffies(NCI_DATA_TIMEOUT)); 245 245 if (r == NCI_STATUS_OK) { 246 246 message = (struct nci_hcp_message *)conn_info->rx_skb->data; ··· 511 511 data.data = NULL; 512 512 data.data_len = 0; 513 513 514 - return nci_request(ndev, nci_hci_send_data_req, 515 - (unsigned long)&data, 516 - msecs_to_jiffies(NCI_DATA_TIMEOUT)); 514 + return nci_request(ndev, nci_hci_send_data_req, &data, 515 + msecs_to_jiffies(NCI_DATA_TIMEOUT)); 517 516 } 518 517 EXPORT_SYMBOL(nci_hci_open_pipe); 519 518 ··· 586 587 data.data = tmp; 587 588 data.data_len = param_len + 1; 588 589 589 - r = nci_request(ndev, nci_hci_send_data_req, 590 - (unsigned long)&data, 590 + r = nci_request(ndev, nci_hci_send_data_req, &data, 591 591 msecs_to_jiffies(NCI_DATA_TIMEOUT)); 592 592 if (r == NCI_STATUS_OK) { 593 593 message = (struct nci_hcp_message *)conn_info->rx_skb->data; ··· 625 627 data.data = &idx; 626 628 data.data_len = 1; 627 629 628 - r = nci_request(ndev, nci_hci_send_data_req, (unsigned long)&data, 630 + r = nci_request(ndev, nci_hci_send_data_req, &data, 629 631 msecs_to_jiffies(NCI_DATA_TIMEOUT)); 630 632 631 633 if (r == NCI_STATUS_OK) {