Commit 8318fde4 authored by Jingoo Han's avatar Jingoo Han Committed by Linus Torvalds
Browse files

backlight: add devm_backlight_device_{register,unregister}()

These functions allow the driver core to automatically clean up any
allocation made by backlight drivers.  Thus it simplifies the error
Signed-off-by: default avatarJingoo Han <>
Cc: Tejun Heo <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 9ed3936f
......@@ -370,6 +370,81 @@ void backlight_device_unregister(struct backlight_device *bd)
static void devm_backlight_device_release(struct device *dev, void *res)
struct backlight_device *backlight = *(struct backlight_device **)res;
static int devm_backlight_device_match(struct device *dev, void *res,
void *data)
struct backlight_device **r = res;
return *r == data;
* devm_backlight_device_register - resource managed backlight_device_register()
* @dev: the device to register
* @name: the name of the device
* @parent: a pointer to the parent device
* @devdata: an optional pointer to be stored for private driver use
* @ops: the backlight operations structure
* @props: the backlight properties
* @return a struct backlight on success, or an ERR_PTR on error
* Managed backlight_device_register(). The backlight_device returned
* from this function are automatically freed on driver detach.
* See backlight_device_register() for more information.
struct backlight_device *devm_backlight_device_register(struct device *dev,
const char *name, struct device *parent, void *devdata,
const struct backlight_ops *ops,
const struct backlight_properties *props)
struct backlight_device **ptr, *backlight;
ptr = devres_alloc(devm_backlight_device_release, sizeof(*ptr),
if (!ptr)
return ERR_PTR(-ENOMEM);
backlight = backlight_device_register(name, parent, devdata, ops,
if (!IS_ERR(backlight)) {
*ptr = backlight;
devres_add(dev, ptr);
} else {
return backlight;
* devm_backlight_device_unregister - resource managed backlight_device_unregister()
* @dev: the device to unregister
* @bd: the backlight device to unregister
* Deallocated a backlight allocated with devm_backlight_device_register().
* Normally this function will not need to be called and the resource management
* code will ensure that the resource is freed.
void devm_backlight_device_unregister(struct device *dev,
struct backlight_device *bd)
int rc;
rc = devres_release(dev, devm_backlight_device_release,
devm_backlight_device_match, bd);
#ifdef CONFIG_OF
static int of_parent_match(struct device *dev, const void *data)
......@@ -114,7 +114,13 @@ static inline void backlight_update_status(struct backlight_device *bd)
extern struct backlight_device *backlight_device_register(const char *name,
struct device *dev, void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);
extern struct backlight_device *devm_backlight_device_register(
struct device *dev, const char *name, struct device *parent,
void *devdata, const struct backlight_ops *ops,
const struct backlight_properties *props);
extern void backlight_device_unregister(struct backlight_device *bd);
extern void devm_backlight_device_unregister(struct device *dev,
struct backlight_device *bd);
extern void backlight_force_update(struct backlight_device *bd,
enum backlight_update_reason reason);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment