Skip to content

Commit 2dbf085

Browse files
osctobebroonie
authored andcommitted
regulator: cleanup regulator_ena_gpio_free()
Since only regulator_ena_gpio_request() allocates rdev->ena_pin, and it guarantees that same gpiod gets same pin structure, it is enough to compare just the pointers. Also we know there can be only one matching entry on the list. Rework the code take advantage of the facts. Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Link: https://lore.kernel.org/r/3ff002c7aa3bd774491af4291a9df23541fcf892.1597195321.git.mirq-linux@rere.qmqm.pl Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent d3c7315 commit 2dbf085

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

drivers/regulator/core.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,19 +2287,19 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)
22872287

22882288
/* Free the GPIO only in case of no use */
22892289
list_for_each_entry_safe(pin, n, &regulator_ena_gpio_list, list) {
2290-
if (pin->gpiod == rdev->ena_pin->gpiod) {
2291-
if (pin->request_count <= 1) {
2292-
pin->request_count = 0;
2293-
gpiod_put(pin->gpiod);
2294-
list_del(&pin->list);
2295-
kfree(pin);
2296-
rdev->ena_pin = NULL;
2297-
return;
2298-
} else {
2299-
pin->request_count--;
2300-
}
2301-
}
2290+
if (pin != rdev->ena_pin)
2291+
continue;
2292+
2293+
if (--pin->request_count)
2294+
break;
2295+
2296+
gpiod_put(pin->gpiod);
2297+
list_del(&pin->list);
2298+
kfree(pin);
2299+
break;
23022300
}
2301+
2302+
rdev->ena_pin = NULL;
23032303
}
23042304

23052305
/**

0 commit comments

Comments
 (0)