diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2012-10-22 09:57:58 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-10-26 12:26:51 -0400 |
commit | 7eda8b8e967781cfa5a04962502f9aa428f67e5f (patch) | |
tree | 9ae63d4aee01fc7bf38545bd6b81350962adacfc /net/nfc | |
parent | ab34a1813ca16bfbc672a21ca354164c8b941922 (diff) |
NFC: Use IDR library to assing NFC devices IDs
As a consequence the NFC device IDs won't be increasing all the time,
as IDR provides the first available ID.
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'net/nfc')
-rw-r--r-- | net/nfc/core.c | 23 |
1 files changed, 16 insertions, 7 deletions
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 | ||