2024-04-29 14:51:10

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH v2 00/12] regulator/core: Trivial cleanups and improvements

This is a random set of cleanups, dead code removal and minor
optimizations. This is a v2 of patchset sent long time ago, extended
with a couple more entries (one including a driver cleanup to enable
further changes). Tested on Tegra3 (ARM) and x86 devices.

v2:
- added regulator_dev.reg_data cleanup patches
- added a missing hunk in patch 6
- removed an extra change from patch 5
(Note: skipping changelogs in the patches, as the update has no relevant
material changes there)

Michał Mirosław (12):
regulator/core: _regulator_get: simplify error returns
regulator/core: set_consumer_device_supply: remove `has_dev`
regulator/core: of_get_child_regulator: remove goto
regulator/core: regulator_bulk_get: remove redundant NULL stores
regulator/core: regulator_ena_gpio_ctrl: pull in ena_gpio state
handling
regulator/core: remove regulator_init callback
regulator/core: remove regulator_get_init_drvdata()
regulator/core: set_consumer_device_supply: avoid copying const data
regulator/tps68470: use rdev_get_drvdata()
regulator/core: use dev_to_rdev() for device -> regulator_dev cast
regulator/core: remove regulator_get/set_drvdata
regulator/core: use rdev->dev.driver_data

drivers/regulator/core.c | 180 ++++++++-----------------
drivers/regulator/tps68470-regulator.c | 4 +-
include/linux/regulator/consumer.h | 14 --
include/linux/regulator/driver.h | 9 +-
include/linux/regulator/machine.h | 7 +-
5 files changed, 62 insertions(+), 152 deletions(-)

--
2.39.2



2024-04-29 14:56:06

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH v2 03/12] regulator/core: of_get_child_regulator: remove goto

Because of_node_put() handles NULL properly (like kfree() et al)
we can call it also after the loop ends (due to child == NULL).
This makes the gotos redundant.

Signed-off-by: Michał Mirosław <[email protected]>
---
drivers/regulator/core.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 5db3bf08145c..3d7147fabbed 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -438,18 +438,15 @@ static struct device_node *of_get_child_regulator(struct device_node *parent,

for_each_child_of_node(parent, child) {
regnode = of_parse_phandle(child, prop_name, 0);
+ if (regnode)
+ break;

- if (!regnode) {
- regnode = of_get_child_regulator(child, prop_name);
- if (regnode)
- goto err_node_put;
- } else {
- goto err_node_put;
- }
+ regnode = of_get_child_regulator(child, prop_name);
+ if (regnode)
+ break;
}
- return NULL;

-err_node_put:
+ /* Release the node if the loop was exited early. */
of_node_put(child);
return regnode;
}
--
2.39.2


2024-04-29 14:57:00

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH v2 01/12] regulator/core: _regulator_get: simplify error returns

Remove unnecessary stores to `regulator`.

Signed-off-by: Michał Mirosław <[email protected]>
---
drivers/regulator/core.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index dabac9772741..62dd3ac19e6d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2222,15 +2222,13 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
}

if (rdev->exclusive) {
- regulator = ERR_PTR(-EPERM);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EPERM);
}

if (get_type == EXCLUSIVE_GET && rdev->open_count) {
- regulator = ERR_PTR(-EBUSY);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EBUSY);
}

mutex_lock(&regulator_list_mutex);
@@ -2238,32 +2236,28 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
mutex_unlock(&regulator_list_mutex);

if (ret != 0) {
- regulator = ERR_PTR(-EPROBE_DEFER);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EPROBE_DEFER);
}

ret = regulator_resolve_supply(rdev);
if (ret < 0) {
- regulator = ERR_PTR(ret);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(ret);
}

if (!try_module_get(rdev->owner)) {
- regulator = ERR_PTR(-EPROBE_DEFER);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-EPROBE_DEFER);
}

regulator_lock(rdev);
regulator = create_regulator(rdev, dev, id);
regulator_unlock(rdev);
if (regulator == NULL) {
- regulator = ERR_PTR(-ENOMEM);
module_put(rdev->owner);
put_device(&rdev->dev);
- return regulator;
+ return ERR_PTR(-ENOMEM);
}

rdev->open_count++;
--
2.39.2


2024-04-29 15:19:19

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH v2 05/12] regulator/core: regulator_ena_gpio_ctrl: pull in ena_gpio state handling

Deduplicate `ena_gpio_state` handling by pulling it into
regulator_ena_gpio_ctrl().

Signed-off-by: Michał Mirosław <[email protected]>
---
drivers/regulator/core.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a1573a7ff2b2..4cb30e49c03d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2625,6 +2625,10 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
if (!pin)
return -EINVAL;

+ if (rdev->ena_gpio_state == enable)
+ return 0;
+ rdev->ena_gpio_state = enable;
+
if (enable) {
/* Enable GPIO at initial use */
if (pin->enable_count == 0)
@@ -2744,12 +2748,9 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
}

if (rdev->ena_pin) {
- if (!rdev->ena_gpio_state) {
- ret = regulator_ena_gpio_ctrl(rdev, true);
- if (ret < 0)
- return ret;
- rdev->ena_gpio_state = 1;
- }
+ ret = regulator_ena_gpio_ctrl(rdev, true);
+ if (ret < 0)
+ return ret;
} else if (rdev->desc->ops->enable) {
ret = rdev->desc->ops->enable(rdev);
if (ret < 0)
@@ -2963,13 +2964,9 @@ static int _regulator_do_disable(struct regulator_dev *rdev)
trace_regulator_disable(rdev_get_name(rdev));

if (rdev->ena_pin) {
- if (rdev->ena_gpio_state) {
- ret = regulator_ena_gpio_ctrl(rdev, false);
- if (ret < 0)
- return ret;
- rdev->ena_gpio_state = 0;
- }
-
+ ret = regulator_ena_gpio_ctrl(rdev, false);
+ if (ret < 0)
+ return ret;
} else if (rdev->desc->ops->disable) {
ret = rdev->desc->ops->disable(rdev);
if (ret != 0)
--
2.39.2


2024-04-29 15:23:04

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH v2 02/12] regulator/core: set_consumer_device_supply: remove `has_dev`

`has_dev` is only ever used once to check if the name is non-NULL.
Inline the check and make the intent obvious.

Signed-off-by: Michał Mirosław <[email protected]>
---
drivers/regulator/core.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 62dd3ac19e6d..5db3bf08145c 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1738,16 +1738,10 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
const char *supply)
{
struct regulator_map *node, *new_node;
- int has_dev;

if (supply == NULL)
return -EINVAL;

- if (consumer_dev_name != NULL)
- has_dev = 1;
- else
- has_dev = 0;
-
new_node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
if (new_node == NULL)
return -ENOMEM;
@@ -1755,7 +1749,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
new_node->regulator = rdev;
new_node->supply = supply;

- if (has_dev) {
+ if (consumer_dev_name != NULL) {
new_node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
if (new_node->dev_name == NULL) {
kfree(new_node);
--
2.39.2