Skip to content

Commit 9ae241d

Browse files
andy-shevthierryreding
authored andcommitted
pwm: core: Simplify some devm_*pwm*() functions
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 <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent c333b93 commit 9ae241d

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

drivers/pwm/core.c

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,9 @@ void pwm_put(struct pwm_device *pwm)
10651065
}
10661066
EXPORT_SYMBOL_GPL(pwm_put);
10671067

1068-
static void devm_pwm_release(struct device *dev, void *res)
1068+
static void devm_pwm_release(void *pwm)
10691069
{
1070-
pwm_put(*(struct pwm_device **)res);
1070+
pwm_put(pwm);
10711071
}
10721072

10731073
/**
@@ -1083,19 +1083,16 @@ static void devm_pwm_release(struct device *dev, void *res)
10831083
*/
10841084
struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id)
10851085
{
1086-
struct pwm_device **ptr, *pwm;
1087-
1088-
ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
1089-
if (!ptr)
1090-
return ERR_PTR(-ENOMEM);
1086+
struct pwm_device *pwm;
1087+
int ret;
10911088

10921089
pwm = pwm_get(dev, con_id);
1093-
if (!IS_ERR(pwm)) {
1094-
*ptr = pwm;
1095-
devres_add(dev, ptr);
1096-
} else {
1097-
devres_free(ptr);
1098-
}
1090+
if (IS_ERR(pwm))
1091+
return pwm;
1092+
1093+
ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
1094+
if (ret)
1095+
return ERR_PTR(ret);
10991096

11001097
return pwm;
11011098
}
@@ -1116,19 +1113,16 @@ EXPORT_SYMBOL_GPL(devm_pwm_get);
11161113
struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
11171114
const char *con_id)
11181115
{
1119-
struct pwm_device **ptr, *pwm;
1120-
1121-
ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
1122-
if (!ptr)
1123-
return ERR_PTR(-ENOMEM);
1116+
struct pwm_device *pwm;
1117+
int ret;
11241118

11251119
pwm = of_pwm_get(dev, np, con_id);
1126-
if (!IS_ERR(pwm)) {
1127-
*ptr = pwm;
1128-
devres_add(dev, ptr);
1129-
} else {
1130-
devres_free(ptr);
1131-
}
1120+
if (IS_ERR(pwm))
1121+
return pwm;
1122+
1123+
ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
1124+
if (ret)
1125+
return ERR_PTR(ret);
11321126

11331127
return pwm;
11341128
}
@@ -1150,23 +1144,19 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
11501144
struct fwnode_handle *fwnode,
11511145
const char *con_id)
11521146
{
1153-
struct pwm_device **ptr, *pwm = ERR_PTR(-ENODEV);
1154-
1155-
ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
1156-
if (!ptr)
1157-
return ERR_PTR(-ENOMEM);
1147+
struct pwm_device *pwm = ERR_PTR(-ENODEV);
1148+
int ret;
11581149

11591150
if (is_of_node(fwnode))
11601151
pwm = of_pwm_get(dev, to_of_node(fwnode), con_id);
11611152
else if (is_acpi_node(fwnode))
11621153
pwm = acpi_pwm_get(fwnode);
1154+
if (IS_ERR(pwm))
1155+
return pwm;
11631156

1164-
if (!IS_ERR(pwm)) {
1165-
*ptr = pwm;
1166-
devres_add(dev, ptr);
1167-
} else {
1168-
devres_free(ptr);
1169-
}
1157+
ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
1158+
if (ret)
1159+
return ERR_PTR(ret);
11701160

11711161
return pwm;
11721162
}

0 commit comments

Comments
 (0)