diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-11-02 16:39:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-02 19:07:02 -0400 |
commit | 3e5428177c74df7f3b8c59b2f27f46b82b077e94 (patch) | |
tree | 6f4ef832968fee3173f5cb6c2c0540981e8ced29 /drivers/w1 | |
parent | 79bc57463be2ad5020a53accbf26898e8ac04550 (diff) |
w1: ds2760 and ds2780, use ida for id and ida_simple_get() to get it
Straightforward. As an aside, the ida_init calls are not needed as far as
I can see needed. (DEFINE_IDA does the same already).
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Acked-by: Clifton Barnes <cabarnes@indesign-llc.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r-- | drivers/w1/slaves/w1_ds2760.c | 48 | ||||
-rw-r--r-- | drivers/w1/slaves/w1_ds2780.c | 48 |
2 files changed, 12 insertions, 84 deletions
diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c index 483d45180911..5754c9a4f58b 100644 --- a/drivers/w1/slaves/w1_ds2760.c +++ b/drivers/w1/slaves/w1_ds2760.c | |||
@@ -114,43 +114,7 @@ static struct bin_attribute w1_ds2760_bin_attr = { | |||
114 | .read = w1_ds2760_read_bin, | 114 | .read = w1_ds2760_read_bin, |
115 | }; | 115 | }; |
116 | 116 | ||
117 | static DEFINE_IDR(bat_idr); | 117 | static DEFINE_IDA(bat_ida); |
118 | static DEFINE_MUTEX(bat_idr_lock); | ||
119 | |||
120 | static int new_bat_id(void) | ||
121 | { | ||
122 | int ret; | ||
123 | |||
124 | while (1) { | ||
125 | int id; | ||
126 | |||
127 | ret = idr_pre_get(&bat_idr, GFP_KERNEL); | ||
128 | if (ret == 0) | ||
129 | return -ENOMEM; | ||
130 | |||
131 | mutex_lock(&bat_idr_lock); | ||
132 | ret = idr_get_new(&bat_idr, NULL, &id); | ||
133 | mutex_unlock(&bat_idr_lock); | ||
134 | |||
135 | if (ret == 0) { | ||
136 | ret = id & MAX_ID_MASK; | ||
137 | break; | ||
138 | } else if (ret == -EAGAIN) { | ||
139 | continue; | ||
140 | } else { | ||
141 | break; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | static void release_bat_id(int id) | ||
149 | { | ||
150 | mutex_lock(&bat_idr_lock); | ||
151 | idr_remove(&bat_idr, id); | ||
152 | mutex_unlock(&bat_idr_lock); | ||
153 | } | ||
154 | 118 | ||
155 | static int w1_ds2760_add_slave(struct w1_slave *sl) | 119 | static int w1_ds2760_add_slave(struct w1_slave *sl) |
156 | { | 120 | { |
@@ -158,7 +122,7 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) | |||
158 | int id; | 122 | int id; |
159 | struct platform_device *pdev; | 123 | struct platform_device *pdev; |
160 | 124 | ||
161 | id = new_bat_id(); | 125 | id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); |
162 | if (id < 0) { | 126 | if (id < 0) { |
163 | ret = id; | 127 | ret = id; |
164 | goto noid; | 128 | goto noid; |
@@ -187,7 +151,7 @@ bin_attr_failed: | |||
187 | pdev_add_failed: | 151 | pdev_add_failed: |
188 | platform_device_unregister(pdev); | 152 | platform_device_unregister(pdev); |
189 | pdev_alloc_failed: | 153 | pdev_alloc_failed: |
190 | release_bat_id(id); | 154 | ida_simple_remove(&bat_ida, id); |
191 | noid: | 155 | noid: |
192 | success: | 156 | success: |
193 | return ret; | 157 | return ret; |
@@ -199,7 +163,7 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl) | |||
199 | int id = pdev->id; | 163 | int id = pdev->id; |
200 | 164 | ||
201 | platform_device_unregister(pdev); | 165 | platform_device_unregister(pdev); |
202 | release_bat_id(id); | 166 | ida_simple_remove(&bat_ida, id); |
203 | sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr); | 167 | sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr); |
204 | } | 168 | } |
205 | 169 | ||
@@ -217,14 +181,14 @@ static int __init w1_ds2760_init(void) | |||
217 | { | 181 | { |
218 | printk(KERN_INFO "1-Wire driver for the DS2760 battery monitor " | 182 | printk(KERN_INFO "1-Wire driver for the DS2760 battery monitor " |
219 | " chip - (c) 2004-2005, Szabolcs Gyurko\n"); | 183 | " chip - (c) 2004-2005, Szabolcs Gyurko\n"); |
220 | idr_init(&bat_idr); | 184 | ida_init(&bat_ida); |
221 | return w1_register_family(&w1_ds2760_family); | 185 | return w1_register_family(&w1_ds2760_family); |
222 | } | 186 | } |
223 | 187 | ||
224 | static void __exit w1_ds2760_exit(void) | 188 | static void __exit w1_ds2760_exit(void) |
225 | { | 189 | { |
226 | w1_unregister_family(&w1_ds2760_family); | 190 | w1_unregister_family(&w1_ds2760_family); |
227 | idr_destroy(&bat_idr); | 191 | ida_destroy(&bat_ida); |
228 | } | 192 | } |
229 | 193 | ||
230 | EXPORT_SYMBOL(w1_ds2760_read); | 194 | EXPORT_SYMBOL(w1_ds2760_read); |
diff --git a/drivers/w1/slaves/w1_ds2780.c b/drivers/w1/slaves/w1_ds2780.c index 274c8f38303f..a134b38e34b2 100644 --- a/drivers/w1/slaves/w1_ds2780.c +++ b/drivers/w1/slaves/w1_ds2780.c | |||
@@ -99,43 +99,7 @@ static struct bin_attribute w1_ds2780_bin_attr = { | |||
99 | .read = w1_ds2780_read_bin, | 99 | .read = w1_ds2780_read_bin, |
100 | }; | 100 | }; |
101 | 101 | ||
102 | static DEFINE_IDR(bat_idr); | 102 | static DEFINE_IDA(bat_ida); |
103 | static DEFINE_MUTEX(bat_idr_lock); | ||
104 | |||
105 | static int new_bat_id(void) | ||
106 | { | ||
107 | int ret; | ||
108 | |||
109 | while (1) { | ||
110 | int id; | ||
111 | |||
112 | ret = idr_pre_get(&bat_idr, GFP_KERNEL); | ||
113 | if (ret == 0) | ||
114 | return -ENOMEM; | ||
115 | |||
116 | mutex_lock(&bat_idr_lock); | ||
117 | ret = idr_get_new(&bat_idr, NULL, &id); | ||
118 | mutex_unlock(&bat_idr_lock); | ||
119 | |||
120 | if (ret == 0) { | ||
121 | ret = id & MAX_ID_MASK; | ||
122 | break; | ||
123 | } else if (ret == -EAGAIN) { | ||
124 | continue; | ||
125 | } else { | ||
126 | break; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return ret; | ||
131 | } | ||
132 | |||
133 | static void release_bat_id(int id) | ||
134 | { | ||
135 | mutex_lock(&bat_idr_lock); | ||
136 | idr_remove(&bat_idr, id); | ||
137 | mutex_unlock(&bat_idr_lock); | ||
138 | } | ||
139 | 103 | ||
140 | static int w1_ds2780_add_slave(struct w1_slave *sl) | 104 | static int w1_ds2780_add_slave(struct w1_slave *sl) |
141 | { | 105 | { |
@@ -143,7 +107,7 @@ static int w1_ds2780_add_slave(struct w1_slave *sl) | |||
143 | int id; | 107 | int id; |
144 | struct platform_device *pdev; | 108 | struct platform_device *pdev; |
145 | 109 | ||
146 | id = new_bat_id(); | 110 | id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); |
147 | if (id < 0) { | 111 | if (id < 0) { |
148 | ret = id; | 112 | ret = id; |
149 | goto noid; | 113 | goto noid; |
@@ -172,7 +136,7 @@ bin_attr_failed: | |||
172 | pdev_add_failed: | 136 | pdev_add_failed: |
173 | platform_device_unregister(pdev); | 137 | platform_device_unregister(pdev); |
174 | pdev_alloc_failed: | 138 | pdev_alloc_failed: |
175 | release_bat_id(id); | 139 | ida_simple_remove(&bat_ida, id); |
176 | noid: | 140 | noid: |
177 | return ret; | 141 | return ret; |
178 | } | 142 | } |
@@ -183,7 +147,7 @@ static void w1_ds2780_remove_slave(struct w1_slave *sl) | |||
183 | int id = pdev->id; | 147 | int id = pdev->id; |
184 | 148 | ||
185 | platform_device_unregister(pdev); | 149 | platform_device_unregister(pdev); |
186 | release_bat_id(id); | 150 | ida_simple_remove(&bat_ida, id); |
187 | sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr); | 151 | sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr); |
188 | } | 152 | } |
189 | 153 | ||
@@ -199,14 +163,14 @@ static struct w1_family w1_ds2780_family = { | |||
199 | 163 | ||
200 | static int __init w1_ds2780_init(void) | 164 | static int __init w1_ds2780_init(void) |
201 | { | 165 | { |
202 | idr_init(&bat_idr); | 166 | ida_init(&bat_ida); |
203 | return w1_register_family(&w1_ds2780_family); | 167 | return w1_register_family(&w1_ds2780_family); |
204 | } | 168 | } |
205 | 169 | ||
206 | static void __exit w1_ds2780_exit(void) | 170 | static void __exit w1_ds2780_exit(void) |
207 | { | 171 | { |
208 | w1_unregister_family(&w1_ds2780_family); | 172 | w1_unregister_family(&w1_ds2780_family); |
209 | idr_destroy(&bat_idr); | 173 | ida_destroy(&bat_ida); |
210 | } | 174 | } |
211 | 175 | ||
212 | module_init(w1_ds2780_init); | 176 | module_init(w1_ds2780_init); |