diff options
-rw-r--r-- | include/net/nfc/nfc.h | 2 | ||||
-rw-r--r-- | net/nfc/core.c | 23 |
2 files changed, 17 insertions, 8 deletions
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h index f05b10682c9d..fce80b2f9be7 100644 --- a/include/net/nfc/nfc.h +++ b/include/net/nfc/nfc.h | |||
@@ -95,7 +95,7 @@ struct nfc_genl_data { | |||
95 | }; | 95 | }; |
96 | 96 | ||
97 | struct nfc_dev { | 97 | struct nfc_dev { |
98 | unsigned int idx; | 98 | int idx; |
99 | u32 target_next_idx; | 99 | u32 target_next_idx; |
100 | struct nfc_target *targets; | 100 | struct nfc_target *targets; |
101 | int n_targets; | 101 | int n_targets; |
diff --git a/net/nfc/core.c b/net/nfc/core.c index f1c33f233311..e94363dbbf4a 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c | |||
@@ -40,6 +40,9 @@ | |||
40 | int nfc_devlist_generation; | 40 | int nfc_devlist_generation; |
41 | DEFINE_MUTEX(nfc_devlist_mutex); | 41 | DEFINE_MUTEX(nfc_devlist_mutex); |
42 | 42 | ||
43 | /* NFC device ID bitmap */ | ||
44 | static DEFINE_IDA(nfc_index_ida); | ||
45 | |||
43 | /** | 46 | /** |
44 | * nfc_dev_up - turn on the NFC device | 47 | * nfc_dev_up - turn on the NFC device |
45 | * | 48 | * |
@@ -760,7 +763,6 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, | |||
760 | u32 supported_protocols, | 763 | u32 supported_protocols, |
761 | int tx_headroom, int tx_tailroom) | 764 | int tx_headroom, int tx_tailroom) |
762 | { | 765 | { |
763 | static atomic_t dev_no = ATOMIC_INIT(0); | ||
764 | struct nfc_dev *dev; | 766 | struct nfc_dev *dev; |
765 | 767 | ||
766 | if (!ops->start_poll || !ops->stop_poll || !ops->activate_target || | 768 | if (!ops->start_poll || !ops->stop_poll || !ops->activate_target || |
@@ -774,11 +776,6 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, | |||
774 | if (!dev) | 776 | if (!dev) |
775 | return NULL; | 777 | return NULL; |
776 | 778 | ||
777 | dev->dev.class = &nfc_class; | ||
778 | dev->idx = atomic_inc_return(&dev_no) - 1; | ||
779 | dev_set_name(&dev->dev, "nfc%d", dev->idx); | ||
780 | device_initialize(&dev->dev); | ||
781 | |||
782 | dev->ops = ops; | 779 | dev->ops = ops; |
783 | dev->supported_protocols = supported_protocols; | 780 | dev->supported_protocols = supported_protocols; |
784 | dev->tx_headroom = tx_headroom; | 781 | dev->tx_headroom = tx_headroom; |
@@ -814,6 +811,14 @@ int nfc_register_device(struct nfc_dev *dev) | |||
814 | 811 | ||
815 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); | 812 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
816 | 813 | ||
814 | dev->idx = ida_simple_get(&nfc_index_ida, 0, 0, GFP_KERNEL); | ||
815 | if (dev->idx < 0) | ||
816 | return dev->idx; | ||
817 | |||
818 | dev->dev.class = &nfc_class; | ||
819 | dev_set_name(&dev->dev, "nfc%d", dev->idx); | ||
820 | device_initialize(&dev->dev); | ||
821 | |||
817 | mutex_lock(&nfc_devlist_mutex); | 822 | mutex_lock(&nfc_devlist_mutex); |
818 | nfc_devlist_generation++; | 823 | nfc_devlist_generation++; |
819 | rc = device_add(&dev->dev); | 824 | rc = device_add(&dev->dev); |
@@ -842,10 +847,12 @@ EXPORT_SYMBOL(nfc_register_device); | |||
842 | */ | 847 | */ |
843 | void nfc_unregister_device(struct nfc_dev *dev) | 848 | void nfc_unregister_device(struct nfc_dev *dev) |
844 | { | 849 | { |
845 | int rc; | 850 | int rc, id; |
846 | 851 | ||
847 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); | 852 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
848 | 853 | ||
854 | id = dev->idx; | ||
855 | |||
849 | mutex_lock(&nfc_devlist_mutex); | 856 | mutex_lock(&nfc_devlist_mutex); |
850 | nfc_devlist_generation++; | 857 | nfc_devlist_generation++; |
851 | 858 | ||
@@ -864,6 +871,8 @@ void nfc_unregister_device(struct nfc_dev *dev) | |||
864 | pr_debug("The userspace won't be notified that the device %s was removed\n", | 871 | pr_debug("The userspace won't be notified that the device %s was removed\n", |
865 | dev_name(&dev->dev)); | 872 | dev_name(&dev->dev)); |
866 | 873 | ||
874 | ida_simple_remove(&nfc_index_ida, id); | ||
875 | |||
867 | } | 876 | } |
868 | EXPORT_SYMBOL(nfc_unregister_device); | 877 | EXPORT_SYMBOL(nfc_unregister_device); |
869 | 878 | ||