diff options
author | Jingoo Han <jg1.han@samsung.com> | 2013-07-03 18:05:14 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-03 19:07:43 -0400 |
commit | 1d0c48e66b3f1cf40660f69a87f55af3df0b2ae3 (patch) | |
tree | 0b3531877c44659181ae17098ee581f09833f40e | |
parent | 8318fde4ac78f6793b1cbaf57659902253a61617 (diff) |
lcd: add devm_lcd_device_{register,unregister}()
These functions allow the driver core to automatically clean up any
allocation made by lcd drivers. Thus it simplifies the error paths.
Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/video/backlight/lcd.c | 70 | ||||
-rw-r--r-- | include/linux/lcd.h | 5 |
2 files changed, 75 insertions, 0 deletions
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index 3649fd9ddb3a..41964a71a036 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c | |||
@@ -260,6 +260,76 @@ void lcd_device_unregister(struct lcd_device *ld) | |||
260 | } | 260 | } |
261 | EXPORT_SYMBOL(lcd_device_unregister); | 261 | EXPORT_SYMBOL(lcd_device_unregister); |
262 | 262 | ||
263 | static void devm_lcd_device_release(struct device *dev, void *res) | ||
264 | { | ||
265 | struct lcd_device *lcd = *(struct lcd_device **)res; | ||
266 | |||
267 | lcd_device_unregister(lcd); | ||
268 | } | ||
269 | |||
270 | static int devm_lcd_device_match(struct device *dev, void *res, void *data) | ||
271 | { | ||
272 | struct lcd_device **r = res; | ||
273 | |||
274 | return *r == data; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * devm_lcd_device_register - resource managed lcd_device_register() | ||
279 | * @dev: the device to register | ||
280 | * @name: the name of the device | ||
281 | * @parent: a pointer to the parent device | ||
282 | * @devdata: an optional pointer to be stored for private driver use | ||
283 | * @ops: the lcd operations structure | ||
284 | * | ||
285 | * @return a struct lcd on success, or an ERR_PTR on error | ||
286 | * | ||
287 | * Managed lcd_device_register(). The lcd_device returned from this function | ||
288 | * are automatically freed on driver detach. See lcd_device_register() | ||
289 | * for more information. | ||
290 | */ | ||
291 | struct lcd_device *devm_lcd_device_register(struct device *dev, | ||
292 | const char *name, struct device *parent, | ||
293 | void *devdata, struct lcd_ops *ops) | ||
294 | { | ||
295 | struct lcd_device **ptr, *lcd; | ||
296 | |||
297 | ptr = devres_alloc(devm_lcd_device_release, sizeof(*ptr), GFP_KERNEL); | ||
298 | if (!ptr) | ||
299 | return ERR_PTR(-ENOMEM); | ||
300 | |||
301 | lcd = lcd_device_register(name, parent, devdata, ops); | ||
302 | if (!IS_ERR(lcd)) { | ||
303 | *ptr = lcd; | ||
304 | devres_add(dev, ptr); | ||
305 | } else { | ||
306 | devres_free(ptr); | ||
307 | } | ||
308 | |||
309 | return lcd; | ||
310 | } | ||
311 | EXPORT_SYMBOL(devm_lcd_device_register); | ||
312 | |||
313 | /** | ||
314 | * devm_lcd_device_unregister - resource managed lcd_device_unregister() | ||
315 | * @dev: the device to unregister | ||
316 | * @ld: the lcd device to unregister | ||
317 | * | ||
318 | * Deallocated a lcd allocated with devm_lcd_device_register(). Normally | ||
319 | * this function will not need to be called and the resource management | ||
320 | * code will ensure that the resource is freed. | ||
321 | */ | ||
322 | void devm_lcd_device_unregister(struct device *dev, struct lcd_device *ld) | ||
323 | { | ||
324 | int rc; | ||
325 | |||
326 | rc = devres_release(dev, devm_lcd_device_release, | ||
327 | devm_lcd_device_match, ld); | ||
328 | WARN_ON(rc); | ||
329 | } | ||
330 | EXPORT_SYMBOL(devm_lcd_device_unregister); | ||
331 | |||
332 | |||
263 | static void __exit lcd_class_exit(void) | 333 | static void __exit lcd_class_exit(void) |
264 | { | 334 | { |
265 | class_destroy(lcd_class); | 335 | class_destroy(lcd_class); |
diff --git a/include/linux/lcd.h b/include/linux/lcd.h index e00c3b0ebc6b..504f6246f38f 100644 --- a/include/linux/lcd.h +++ b/include/linux/lcd.h | |||
@@ -112,7 +112,12 @@ static inline void lcd_set_power(struct lcd_device *ld, int power) | |||
112 | 112 | ||
113 | extern struct lcd_device *lcd_device_register(const char *name, | 113 | extern struct lcd_device *lcd_device_register(const char *name, |
114 | struct device *parent, void *devdata, struct lcd_ops *ops); | 114 | struct device *parent, void *devdata, struct lcd_ops *ops); |
115 | extern struct lcd_device *devm_lcd_device_register(struct device *dev, | ||
116 | const char *name, struct device *parent, | ||
117 | void *devdata, struct lcd_ops *ops); | ||
115 | extern void lcd_device_unregister(struct lcd_device *ld); | 118 | extern void lcd_device_unregister(struct lcd_device *ld); |
119 | extern void devm_lcd_device_unregister(struct device *dev, | ||
120 | struct lcd_device *ld); | ||
116 | 121 | ||
117 | #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev) | 122 | #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev) |
118 | 123 | ||