[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190830081550.GA25502@ulmo>
Date: Fri, 30 Aug 2019 10:15:50 +0200
From: Thierry Reding <thierry.reding@...il.com>
To: Bartosz Golaszewski <brgl@...ev.pl>
Cc: Jens Axboe <axboe@...nel.dk>,
Jonathan Hunter <jonathanh@...dia.com>,
JC Kuo <jckuo@...dia.com>,
Kishon Vijay Abraham I <kishon@...com>,
Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>,
Mathias Nyman <mathias.nyman@...el.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-ide@...r.kernel.org, linux-tegra@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-usb@...r.kernel.org,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: Re: [PATCH 0/4] regulator: add and use a helper for setting supply
names
On Fri, Aug 30, 2019 at 09:17:36AM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@...libre.com>
>
> 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(-)
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
Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)
Powered by blists - more mailing lists