regulator: add and use a helper for setting supply names
Subsystems (7)
cover regulator: add and use a helper for setting supply names
From: Bartosz Golaszewski <[email protected]>
There are ~80 users of regulator bulk APIs that set the supply names in a for loop before using the bulk helpers.
This series proposes to add a helper function for setting supply names and uses it in a couple tegra drivers. If accepted: a coccinelle script should be easy to develop that would address this in other drivers.
Bartosz Golaszewski (4):
regulator: provide regulator_bulk_set_supply_names()
ahci: tegra: use regulator_bulk_set_supply_names()
phy: tegra: use regulator_bulk_set_supply_names()
usb: host: xhci-tegra: use regulator_bulk_set_supply_names()
drivers/ata/ahci_tegra.c | 6 +++--- drivers/phy/tegra/xusb.c | 6 +++--- drivers/regulator/helpers.c | 21 +++++++++++++++++++++ drivers/usb/host/xhci-tegra.c | 5 +++-- include/linux/regulator/consumer.h | 12 ++++++++++++ 5 files changed, 42 insertions(+), 8 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/4 regulator: provide regulator_bulk_set_supply_names()
From: Bartosz Golaszewski <[email protected]>
There are many regulator consumers who - before using the regulator bulk functions - set the supply names in regulator_bulk_data using a for loop.
Let's provide a simple helper in the consumer API that allows users to do the same with a single function call.
--- drivers/regulator/helpers.c | 21 +++++++++++++++++++++ include/linux/regulator/consumer.h | 12 ++++++++++++ 2 files changed, 33 insertions(+)
drivers/regulator/helpers.c +21 -0
@@ -860,3 +860,24 @@ int regulator_get_current_limit_regmap(struct regulator_dev *rdev)return -EINVAL ; }EXPORT_SYMBOL_GPL (regulator_get_current_limit_regmap); + +/** +* regulator_bulk_set_supply_names - initialize the 'supply' fields in an array +* of regulator_bulk_data structs +* +* @consumers: array of regulator_bulk_data entries to initialize +* @supply_names: array of supply name strings +* @num_supplies: number of supply names to initialize +* +* Note: the 'consumers' array must be the size of 'num_supplies'. +*/ +void regulator_bulk_set_supply_names (struct regulator_bulk_data *consumers, +const char *const *supply_names, +unsigned int num_supplies) +{ +unsigned int i; + +for (i =0 ; i < num_supplies; i++) + consumers[i].supply = supply_names[i]; +} +EXPORT_SYMBOL_GPL (regulator_bulk_set_supply_names);
include/linux/regulator/consumer.h +12 -0
@@ -281,6 +281,12 @@ void devm_regulator_unregister_notifier(struct regulator *regulator,void *regulator_get_drvdata (struct regulator *regulator);void regulator_set_drvdata (struct regulator *regulator,void *data); +/* misc helpers */ + +void regulator_bulk_set_supply_names (struct regulator_bulk_data *consumers, +const char *const *supply_names, +unsigned int num_supplies); +#else /*
@@ -580,6 +586,12 @@ static inline int regulator_list_voltage(struct regulator *regulator, unsigned sreturn -EINVAL ; } +void regulator_bulk_set_supply_names (struct regulator_bulk_data *consumers, +const char *const *supply_names, +unsigned int num_supplies) +{ +} +#endif static inline int regulator_set_voltage_triplet(struct regulator *regulator,
Signature · 1 line
2.21.0
kbuild test robot
build botRe: [PATCH 1/4] regulator: provide regulator_bulk_set_supply_names()
I love your patch! Yet something to improve:
Hi Bartosz,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc6 next-20190830]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/regulator-add-and-use-a-helper-for-setting-supply-names/20190901-140224
config: nds32-allnoconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 8.1.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.1.0 make.cross ARCH=nds32
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
nds32le-linux-ld: drivers/of/platform.o: in function `regulator_bulk_set_supply_names':
>> platform.c:(.text+0xe8): multiple definition of `regulator_bulk_set_supply_names'; drivers/usb/phy/of.o:of.c:(.text+0x0): first defined here
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH 1/4] regulator: provide regulator_bulk_set_supply_names()
In reply to Bartosz GolaszewskiI love your patch! Yet something to improve:
Hi Bartosz,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc6 next-20190830]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/regulator-add-and-use-a-helper-for-setting-supply-names/20190901-140224
config: c6x-evmc6678_defconfig (attached as .config)
compiler: c6x-elf-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=c6x
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers/of/platform.o: In function `regulator_bulk_set_supply_names':
>> platform.c:(.text+0xc80): multiple definition of `regulator_bulk_set_supply_names'
drivers/usb/phy/of.o:of.c:(.text+0xa8): first defined here
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Mark Brown
maintainerApplied "regulator: provide regulator_bulk_set_supply_names()" to the regulator tree
In reply to Bartosz GolaszewskiThe patch
regulator: provide regulator_bulk_set_supply_names()
has been applied to the regulator tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-5.4
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
From d0087e72710ca7d1b309bf427286da58418ea89e Mon Sep 17 00:00:00 2001
From: Bartosz Golaszewski <[email protected]>
Date: Fri, 30 Aug 2019 09:17:37 +0200
Subject: [PATCH] regulator: provide regulator_bulk_set_supply_names()
There are many regulator consumers who - before using the regulator bulk functions - set the supply names in regulator_bulk_data using a for loop.
Let's provide a simple helper in the consumer API that allows users to do the same with a single function call.
--- drivers/regulator/helpers.c | 21 +++++++++++++++++++++ include/linux/regulator/consumer.h | 12 ++++++++++++ 2 files changed, 33 insertions(+)
drivers/regulator/helpers.c +21 -0
@@ -860,3 +860,24 @@ int regulator_get_current_limit_regmap(struct regulator_dev *rdev)return -EINVAL ; }EXPORT_SYMBOL_GPL (regulator_get_current_limit_regmap); + +/** +* regulator_bulk_set_supply_names - initialize the 'supply' fields in an array +* of regulator_bulk_data structs +* +* @consumers: array of regulator_bulk_data entries to initialize +* @supply_names: array of supply name strings +* @num_supplies: number of supply names to initialize +* +* Note: the 'consumers' array must be the size of 'num_supplies'. +*/ +void regulator_bulk_set_supply_names (struct regulator_bulk_data *consumers, +const char *const *supply_names, +unsigned int num_supplies) +{ +unsigned int i; + +for (i =0 ; i < num_supplies; i++) + consumers[i].supply = supply_names[i]; +} +EXPORT_SYMBOL_GPL (regulator_bulk_set_supply_names);
include/linux/regulator/consumer.h +12 -0
@@ -281,6 +281,12 @@ void devm_regulator_unregister_notifier(struct regulator *regulator,void *regulator_get_drvdata (struct regulator *regulator);void regulator_set_drvdata (struct regulator *regulator,void *data); +/* misc helpers */ + +void regulator_bulk_set_supply_names (struct regulator_bulk_data *consumers, +const char *const *supply_names, +unsigned int num_supplies); +#else /*
@@ -580,6 +586,12 @@ static inline int regulator_list_voltage(struct regulator *regulator, unsigned sreturn -EINVAL ; } +void regulator_bulk_set_supply_names (struct regulator_bulk_data *consumers, +const char *const *supply_names, +unsigned int num_supplies) +{ +} +#endif static inline int regulator_set_voltage_triplet(struct regulator *regulator,
Signature · 1 line
2.20.1
PATCH 2/4 ahci: tegra: use regulator_bulk_set_supply_names()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Use the new regulator helper instead of a for loop.
--- drivers/ata/ahci_tegra.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/ata/ahci_tegra.c +3 -3
@@ -483,7 +483,6 @@ static int tegra_ahci_probe(struct platform_device *pdev)struct tegra_ahci_priv *tegra;struct resource *res;int ret; -unsigned int i; hpriv =ahci_platform_get_resources (pdev,0 );if (IS_ERR (hpriv))
@@ -543,8 +542,9 @@ static int tegra_ahci_probe(struct platform_device *pdev)if (!tegra->supplies)return -ENOMEM ; -for (i =0 ; i < tegra->soc->num_supplies; i++) - tegra->supplies[i].supply = tegra->soc->supply_names[i]; +regulator_bulk_set_supply_names (tegra->supplies, + tegra->soc->supply_names, + tegra->soc->num_supplies); ret = devm_regulator_bulk_get(&pdev->dev, tegra->soc->num_supplies,
Signature · 1 line
2.21.0
PATCH 3/4 phy: tegra: use regulator_bulk_set_supply_names()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Use the new regulator helper instead of a for loop.
--- drivers/phy/tegra/xusb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/phy/tegra/xusb.c +3 -3
@@ -862,7 +862,6 @@ static int tegra_xusb_padctl_probe(struct platform_device *pdev)struct tegra_xusb_padctl *padctl;const struct of_device_id *match;struct resource *res; -unsigned int i;int err;/* for backwards compatibility with old device trees */
@@ -907,8 +906,9 @@ static int tegra_xusb_padctl_probe(struct platform_device *pdev) goto remove; } -for (i =0 ; i < padctl->soc->num_supplies; i++) - padctl->supplies[i].supply = padctl->soc->supply_names[i]; +regulator_bulk_set_supply_names (padctl->supplies, + padctl->soc->supply_names, + padctl->soc->num_supplies); err =devm_regulator_bulk_get (&pdev->dev, padctl->soc->num_supplies, padctl->supplies);
Signature · 1 line
2.21.0
PATCH 4/4 usb: host: xhci-tegra: use regulator_bulk_set_supply_names()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Use the new regulator helper instead of a for loop.
--- drivers/usb/host/xhci-tegra.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-tegra.c +3 -2
@@ -1128,8 +1128,9 @@ static int tegra_xusb_probe(struct platform_device *pdev) goto put_powerdomains; } -for (i =0 ; i < tegra->soc->num_supplies; i++) - tegra->supplies[i].supply = tegra->soc->supply_names[i]; +regulator_bulk_set_supply_names (tegra->supplies, + tegra->soc->supply_names, + tegra->soc->num_supplies); err =devm_regulator_bulk_get (&pdev->dev, tegra->soc->num_supplies, tegra->supplies);
Signature · 1 line
2.21.0
Quoted 15 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
There are ~80 users of regulator bulk APIs that set the supply names in a for loop before using the bulk helpers.
This series proposes to add a helper function for setting supply names and uses it in a couple tegra drivers. If accepted: a coccinelle script should be easy to develop that would address this in other drivers.
Bartosz Golaszewski (4):
regulator: provideregulator_bulk_set_supply_names()
ahci: tegra: useregulator_bulk_set_supply_names()
phy: tegra: useregulator_bulk_set_supply_names()
usb: host: xhci-tegra: useregulator_bulk_set_supply_names()
Quoted 6 lines
drivers/ata/ahci_tegra.c | 6 +++--- drivers/phy/tegra/xusb.c | 6 +++--- drivers/regulator/helpers.c | 21 +++++++++++++++++++++ drivers/usb/host/xhci-tegra.c | 5 +++-- include/linux/regulator/consumer.h | 12 ++++++++++++ 5 files changed, 42 insertions(+), 8 deletions(-)
The diffstat here suggests that this isn't really helpful. Even if you subtract the regulator code that adds the new helper, you actually have a zero diffstat (and a positive one in one case).
Instead, why don't we take this one step further and roll a bit more of the boilerplate into the new helper, something along these lines:
struct regulator_bulk_data *
devm_regulator_bulk_get_from_names(struct device *dev,
const char * const *supply_names,
unsigned int num_supplies)
{
struct regulator_bulk_data *data;
unsigned int i;
int err;
data = devm_kcalloc(dev, num_supplies, sizeof(*data));
if (!data)
return ERR_PTR(-ENOMEM);
for (i = 0; i < num_supplies; i++)
data[i].supply = supply_names[i];
err = devm_regulator_bulk_get(dev, num_supplies, data);
if (err < 0)
return ERR_PTR(err);
return data;
}That seems to be still a very common pattern and gets rid of a lot more boilerplate, so your diffstat will actually start to be negative at some point.
I suppose one could add a non-managed variant for this as well, but I'm counting 6 uses of regulator_bulk_get() vs. ~140 uses of the managed variant, so I'm not sure it's worth it.
Thierry
pt., 30 sie 2019 o 10:15 Thierry Reding <[email protected]> napisał(a):
Quoted 24 lines · Bartosz Golaszewski
Quoted 15 lines
From: Bartosz Golaszewski <[email protected]>
There are ~80 users of regulator bulk APIs that set the supply names in a for loop before using the bulk helpers.
This series proposes to add a helper function for setting supply names and uses it in a couple tegra drivers. If accepted: a coccinelle script should be easy to develop that would address this in other drivers.
Bartosz Golaszewski (4):
regulator: provideregulator_bulk_set_supply_names()
ahci: tegra: useregulator_bulk_set_supply_names()
phy: tegra: useregulator_bulk_set_supply_names()
usb: host: xhci-tegra: useregulator_bulk_set_supply_names()Quoted 6 lines
drivers/ata/ahci_tegra.c | 6 +++--- drivers/phy/tegra/xusb.c | 6 +++--- drivers/regulator/helpers.c | 21 +++++++++++++++++++++ drivers/usb/host/xhci-tegra.c | 5 +++-- include/linux/regulator/consumer.h | 12 ++++++++++++ 5 files changed, 42 insertions(+), 8 deletions(-)
Quoted 4 lines
The diffstat here suggests that this isn't really helpful. Even if you subtract the regulator code that adds the new helper, you actually have a zero diffstat (and a positive one in one case).
You are right when it comes to LoC stats, but bloat-o-meter says it's quite useful when it comes to actual code size.
This is what we're adding:
$ ./scripts/bloat-o-meter drivers/regulator/helpers.o.old drivers/regulator/helpers.o add/remove: 3/0 grow/shrink: 0/0 up/down: 72/0 (72) Function old new delta regulator_bulk_set_supply_names - 32 +32 __kstrtab_regulator_bulk_set_supply_names - 32 +32 __ksymtab_regulator_bulk_set_supply_names - 8 +8 Total: Before=4438, After=4510, chg +1.62%
And this is what we're removing just from one driver:
$ ./scripts/bloat-o-meter ./drivers/ata/ahci_tegra.o.old ./drivers/ata/ahci_tegra.o add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-52 (-52) Function old new delta tegra_ahci_probe 1688 1636 -52 Total: Before=3474, After=3422, chg -1.50%
Quoted 26 lines
Instead, why don't we take this one step further and roll a bit more of the boilerplate into the new helper, something along these lines:
struct regulator_bulk_data * devm_regulator_bulk_get_from_names(struct device *dev, const char * const *supply_names, unsigned int num_supplies) { struct regulator_bulk_data *data; unsigned int i; int err; data = devm_kcalloc(dev, num_supplies, sizeof(*data)); if (!data) return ERR_PTR(-ENOMEM); for (i = 0; i < num_supplies; i++) data[i].supply = supply_names[i]; err = devm_regulator_bulk_get(dev, num_supplies, data); if (err < 0) return ERR_PTR(err); return data; }
Quoted 4 lines
That seems to be still a very common pattern and gets rid of a lot more boilerplate, so your diffstat will actually start to be negative at some point.
This looks like a good candidate for the next step, but I'd say this change is still worth applying.
Bart
Quoted 5 lines
I suppose one could add a non-managed variant for this as well, but I'm counting 6 uses of
regulator_bulk_get()vs. ~140 uses of the managed variant, so I'm not sure it's worth it.Thierry