Skip to content

Commit

Permalink
pwm: core: Simplify some devm_*pwm*() functions
Browse files Browse the repository at this point in the history
Use devm_add_action_or_reset() instead of devres_alloc() and
devres_add(), which works the same. This will simplify the
code. There is no functional changes.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Andy Shevchenko authored and Thierry Reding committed Jun 30, 2021
1 parent c333b93 commit 9ae241d
Showing 1 changed file with 25 additions and 35 deletions.
60 changes: 25 additions & 35 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,9 @@ void pwm_put(struct pwm_device *pwm)
}
EXPORT_SYMBOL_GPL(pwm_put);

static void devm_pwm_release(struct device *dev, void *res)
static void devm_pwm_release(void *pwm)
{
pwm_put(*(struct pwm_device **)res);
pwm_put(pwm);
}

/**
Expand All @@ -1083,19 +1083,16 @@ static void devm_pwm_release(struct device *dev, void *res)
*/
struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id)
{
struct pwm_device **ptr, *pwm;

ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
struct pwm_device *pwm;
int ret;

pwm = pwm_get(dev, con_id);
if (!IS_ERR(pwm)) {
*ptr = pwm;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}
if (IS_ERR(pwm))
return pwm;

ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
if (ret)
return ERR_PTR(ret);

return pwm;
}
Expand All @@ -1116,19 +1113,16 @@ EXPORT_SYMBOL_GPL(devm_pwm_get);
struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
const char *con_id)
{
struct pwm_device **ptr, *pwm;

ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
struct pwm_device *pwm;
int ret;

pwm = of_pwm_get(dev, np, con_id);
if (!IS_ERR(pwm)) {
*ptr = pwm;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}
if (IS_ERR(pwm))
return pwm;

ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
if (ret)
return ERR_PTR(ret);

return pwm;
}
Expand All @@ -1150,23 +1144,19 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
struct fwnode_handle *fwnode,
const char *con_id)
{
struct pwm_device **ptr, *pwm = ERR_PTR(-ENODEV);

ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
struct pwm_device *pwm = ERR_PTR(-ENODEV);
int ret;

if (is_of_node(fwnode))
pwm = of_pwm_get(dev, to_of_node(fwnode), con_id);
else if (is_acpi_node(fwnode))
pwm = acpi_pwm_get(fwnode);
if (IS_ERR(pwm))
return pwm;

if (!IS_ERR(pwm)) {
*ptr = pwm;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}
ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
if (ret)
return ERR_PTR(ret);

return pwm;
}
Expand Down

0 comments on commit 9ae241d

Please sign in to comment.