Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
regulator: cleanup regulator_ena_gpio_free()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/r/3ff002c7aa3bd774491af4291a9df23541fcf892.1597195321.git.mirq-linux@rere.qmqm.pl
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
osctobe authored and broonie committed Aug 17, 2020
1 parent d3c7315 commit 2dbf085
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2287,19 +2287,19 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)

/* Free the GPIO only in case of no use */
list_for_each_entry_safe(pin, n, &regulator_ena_gpio_list, list) {
if (pin->gpiod == rdev->ena_pin->gpiod) {
if (pin->request_count <= 1) {
pin->request_count = 0;
gpiod_put(pin->gpiod);
list_del(&pin->list);
kfree(pin);
rdev->ena_pin = NULL;
return;
} else {
pin->request_count--;
}
}
if (pin != rdev->ena_pin)
continue;

if (--pin->request_count)
break;

gpiod_put(pin->gpiod);
list_del(&pin->list);
kfree(pin);
break;
}

rdev->ena_pin = NULL;
}

/**
Expand Down

0 comments on commit 2dbf085

Please sign in to comment.