Skip to content

Commit dad35f7

Browse files
committed
reset: replace boolean parameters with flags parameter
Introduce enum reset_control_flags and replace the list of boolean parameters to the internal reset_control_get functions with a single flags parameter, before adding more boolean options. The separate boolean parameters have been shown to be error prone in the past. See for example commit a57f68d ("reset: Fix devm bulk optional exclusive control getter"). Acked-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Philipp Zabel <[email protected]>
1 parent 5f79c4b commit dad35f7

File tree

2 files changed

+139
-93
lines changed

2 files changed

+139
-93
lines changed

drivers/reset/core.c

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,19 @@ EXPORT_SYMBOL_GPL(reset_control_bulk_release);
773773

774774
static struct reset_control *
775775
__reset_control_get_internal(struct reset_controller_dev *rcdev,
776-
unsigned int index, bool shared, bool acquired)
776+
unsigned int index, enum reset_control_flags flags)
777777
{
778+
bool shared = flags & RESET_CONTROL_FLAGS_BIT_SHARED;
779+
bool acquired = flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED;
778780
struct reset_control *rstc;
779781

780782
lockdep_assert_held(&reset_list_mutex);
781783

784+
/* Expect callers to filter out OPTIONAL and DEASSERTED bits */
785+
if (WARN_ON(flags & ~(RESET_CONTROL_FLAGS_BIT_SHARED |
786+
RESET_CONTROL_FLAGS_BIT_ACQUIRED)))
787+
return ERR_PTR(-EINVAL);
788+
782789
list_for_each_entry(rstc, &rcdev->reset_control_head, list) {
783790
if (rstc->id == index) {
784791
/*
@@ -994,8 +1001,9 @@ static struct reset_controller_dev *__reset_find_rcdev(const struct of_phandle_a
9941001

9951002
struct reset_control *
9961003
__of_reset_control_get(struct device_node *node, const char *id, int index,
997-
bool shared, bool optional, bool acquired)
1004+
enum reset_control_flags flags)
9981005
{
1006+
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
9991007
bool gpio_fallback = false;
10001008
struct reset_control *rstc;
10011009
struct reset_controller_dev *rcdev;
@@ -1059,8 +1067,10 @@ __of_reset_control_get(struct device_node *node, const char *id, int index,
10591067
goto out_unlock;
10601068
}
10611069

1070+
flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL;
1071+
10621072
/* reset_list_mutex also protects the rcdev's reset_control list */
1063-
rstc = __reset_control_get_internal(rcdev, rstc_id, shared, acquired);
1073+
rstc = __reset_control_get_internal(rcdev, rstc_id, flags);
10641074

10651075
out_unlock:
10661076
mutex_unlock(&reset_list_mutex);
@@ -1091,8 +1101,9 @@ __reset_controller_by_name(const char *name)
10911101

10921102
static struct reset_control *
10931103
__reset_control_get_from_lookup(struct device *dev, const char *con_id,
1094-
bool shared, bool optional, bool acquired)
1104+
enum reset_control_flags flags)
10951105
{
1106+
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
10961107
const struct reset_control_lookup *lookup;
10971108
struct reset_controller_dev *rcdev;
10981109
const char *dev_id = dev_name(dev);
@@ -1116,9 +1127,11 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id,
11161127
return ERR_PTR(-EPROBE_DEFER);
11171128
}
11181129

1130+
flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL;
1131+
11191132
rstc = __reset_control_get_internal(rcdev,
11201133
lookup->index,
1121-
shared, acquired);
1134+
flags);
11221135
mutex_unlock(&reset_list_mutex);
11231136
break;
11241137
}
@@ -1133,30 +1146,29 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id,
11331146
}
11341147

11351148
struct reset_control *__reset_control_get(struct device *dev, const char *id,
1136-
int index, bool shared, bool optional,
1137-
bool acquired)
1149+
int index, enum reset_control_flags flags)
11381150
{
1151+
bool shared = flags & RESET_CONTROL_FLAGS_BIT_SHARED;
1152+
bool acquired = flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED;
1153+
11391154
if (WARN_ON(shared && acquired))
11401155
return ERR_PTR(-EINVAL);
11411156

11421157
if (dev->of_node)
1143-
return __of_reset_control_get(dev->of_node, id, index, shared,
1144-
optional, acquired);
1158+
return __of_reset_control_get(dev->of_node, id, index, flags);
11451159

1146-
return __reset_control_get_from_lookup(dev, id, shared, optional,
1147-
acquired);
1160+
return __reset_control_get_from_lookup(dev, id, flags);
11481161
}
11491162
EXPORT_SYMBOL_GPL(__reset_control_get);
11501163

11511164
int __reset_control_bulk_get(struct device *dev, int num_rstcs,
11521165
struct reset_control_bulk_data *rstcs,
1153-
bool shared, bool optional, bool acquired)
1166+
enum reset_control_flags flags)
11541167
{
11551168
int ret, i;
11561169

11571170
for (i = 0; i < num_rstcs; i++) {
1158-
rstcs[i].rstc = __reset_control_get(dev, rstcs[i].id, 0,
1159-
shared, optional, acquired);
1171+
rstcs[i].rstc = __reset_control_get(dev, rstcs[i].id, 0, flags);
11601172
if (IS_ERR(rstcs[i].rstc)) {
11611173
ret = PTR_ERR(rstcs[i].rstc);
11621174
goto err;
@@ -1226,7 +1238,7 @@ static void devm_reset_control_release(struct device *dev, void *res)
12261238

12271239
struct reset_control *
12281240
__devm_reset_control_get(struct device *dev, const char *id, int index,
1229-
bool shared, bool optional, bool acquired)
1241+
enum reset_control_flags flags)
12301242
{
12311243
struct reset_control **ptr, *rstc;
12321244

@@ -1235,7 +1247,7 @@ __devm_reset_control_get(struct device *dev, const char *id, int index,
12351247
if (!ptr)
12361248
return ERR_PTR(-ENOMEM);
12371249

1238-
rstc = __reset_control_get(dev, id, index, shared, optional, acquired);
1250+
rstc = __reset_control_get(dev, id, index, flags);
12391251
if (IS_ERR_OR_NULL(rstc)) {
12401252
devres_free(ptr);
12411253
return rstc;
@@ -1262,7 +1274,7 @@ static void devm_reset_control_bulk_release(struct device *dev, void *res)
12621274

12631275
int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
12641276
struct reset_control_bulk_data *rstcs,
1265-
bool shared, bool optional, bool acquired)
1277+
enum reset_control_flags flags)
12661278
{
12671279
struct reset_control_bulk_devres *ptr;
12681280
int ret;
@@ -1272,7 +1284,7 @@ int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
12721284
if (!ptr)
12731285
return -ENOMEM;
12741286

1275-
ret = __reset_control_bulk_get(dev, num_rstcs, rstcs, shared, optional, acquired);
1287+
ret = __reset_control_bulk_get(dev, num_rstcs, rstcs, flags);
12761288
if (ret < 0) {
12771289
devres_free(ptr);
12781290
return ret;
@@ -1298,6 +1310,7 @@ EXPORT_SYMBOL_GPL(__devm_reset_control_bulk_get);
12981310
*/
12991311
int __device_reset(struct device *dev, bool optional)
13001312
{
1313+
enum reset_control_flags flags;
13011314
struct reset_control *rstc;
13021315
int ret;
13031316

@@ -1313,7 +1326,8 @@ int __device_reset(struct device *dev, bool optional)
13131326
}
13141327
#endif
13151328

1316-
rstc = __reset_control_get(dev, NULL, 0, 0, optional, true);
1329+
flags = optional ? RESET_CONTROL_OPTIONAL_EXCLUSIVE : RESET_CONTROL_EXCLUSIVE;
1330+
rstc = __reset_control_get(dev, NULL, 0, flags);
13171331
if (IS_ERR(rstc))
13181332
return PTR_ERR(rstc);
13191333

@@ -1356,17 +1370,14 @@ static int of_reset_control_get_count(struct device_node *node)
13561370
* device node.
13571371
*
13581372
* @np: device node for the device that requests the reset controls array
1359-
* @shared: whether reset controls are shared or not
1360-
* @optional: whether it is optional to get the reset controls
1361-
* @acquired: only one reset control may be acquired for a given controller
1362-
* and ID
1373+
* @flags: whether reset controls are shared, optional, acquired
13631374
*
13641375
* Returns pointer to allocated reset_control on success or error on failure
13651376
*/
13661377
struct reset_control *
1367-
of_reset_control_array_get(struct device_node *np, bool shared, bool optional,
1368-
bool acquired)
1378+
of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags)
13691379
{
1380+
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
13701381
struct reset_control_array *resets;
13711382
struct reset_control *rstc;
13721383
int num, i;
@@ -1381,8 +1392,7 @@ of_reset_control_array_get(struct device_node *np, bool shared, bool optional,
13811392
resets->num_rstcs = num;
13821393

13831394
for (i = 0; i < num; i++) {
1384-
rstc = __of_reset_control_get(np, NULL, i, shared, optional,
1385-
acquired);
1395+
rstc = __of_reset_control_get(np, NULL, i, flags);
13861396
if (IS_ERR(rstc))
13871397
goto err_rst;
13881398
resets->rstc[i] = rstc;
@@ -1407,8 +1417,7 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get);
14071417
* devm_reset_control_array_get - Resource managed reset control array get
14081418
*
14091419
* @dev: device that requests the list of reset controls
1410-
* @shared: whether reset controls are shared or not
1411-
* @optional: whether it is optional to get the reset controls
1420+
* @flags: whether reset controls are shared, optional, acquired
14121421
*
14131422
* The reset control array APIs are intended for a list of resets
14141423
* that just have to be asserted or deasserted, without any
@@ -1417,7 +1426,7 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get);
14171426
* Returns pointer to allocated reset_control on success or error on failure
14181427
*/
14191428
struct reset_control *
1420-
devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
1429+
devm_reset_control_array_get(struct device *dev, enum reset_control_flags flags)
14211430
{
14221431
struct reset_control **ptr, *rstc;
14231432

@@ -1426,7 +1435,7 @@ devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
14261435
if (!ptr)
14271436
return ERR_PTR(-ENOMEM);
14281437

1429-
rstc = of_reset_control_array_get(dev->of_node, shared, optional, true);
1438+
rstc = of_reset_control_array_get(dev->of_node, flags);
14301439
if (IS_ERR_OR_NULL(rstc)) {
14311440
devres_free(ptr);
14321441
return rstc;

0 commit comments

Comments
 (0)