Skip to content

Commit

Permalink
leds: led-class: Add __devm_led_get() helper
Browse files Browse the repository at this point in the history
Add a __devm_led_get() helper which registers a passed in led_classdev
with devm for unregistration.

This is a preparation patch for adding a generic (non devicetree specific)
devm_led_get() function.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/20230120114524.408368-4-hdegoede@redhat.com
  • Loading branch information
Hans de Goede authored and Lee Jones committed Jan 27, 2023
1 parent fafef58 commit 537bdca
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions drivers/leds/led-class.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ static void devm_led_release(struct device *dev, void *res)
led_put(*p);
}

static struct led_classdev *__devm_led_get(struct device *dev, struct led_classdev *led)
{
struct led_classdev **dr;

dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *), GFP_KERNEL);
if (!dr) {
led_put(led);
return ERR_PTR(-ENOMEM);
}

*dr = led;
devres_add(dev, dr);

return led;
}

/**
* devm_of_led_get - Resource-managed request of a LED device
* @dev: LED consumer
Expand All @@ -289,7 +305,6 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev,
int index)
{
struct led_classdev *led;
struct led_classdev **dr;

if (!dev)
return ERR_PTR(-EINVAL);
Expand All @@ -298,17 +313,7 @@ struct led_classdev *__must_check devm_of_led_get(struct device *dev,
if (IS_ERR(led))
return led;

dr = devres_alloc(devm_led_release, sizeof(struct led_classdev *),
GFP_KERNEL);
if (!dr) {
led_put(led);
return ERR_PTR(-ENOMEM);
}

*dr = led;
devres_add(dev, dr);

return led;
return __devm_led_get(dev, led);
}
EXPORT_SYMBOL_GPL(devm_of_led_get);

Expand Down

0 comments on commit 537bdca

Please sign in to comment.