Linux-ide Archive on lore.kernel.org
 help / color / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	Jonathan Hunter <jonathanh@nvidia.com>, JC Kuo <jckuo@nvidia.com>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-ide@vger.kernel.org, linux-tegra@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-usb@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [PATCH 0/4] regulator: add and use a helper for setting supply names
Date: Fri, 30 Aug 2019 13:06:00 +0200
Message-ID: <CAMRc=Mdy-MX6+hsrvErioUg=38s9Hspp7+2mT7nDYbjL9uQ9uQ@mail.gmail.com> (raw)
In-Reply-To: <20190830081550.GA25502@ulmo>

pt., 30 sie 2019 o 10:15 Thierry Reding <thierry.reding@gmail.com> napisał(a):
>
> On Fri, Aug 30, 2019 at 09:17:36AM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.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).
>

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%

> 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.
>

This looks like a good candidate for the next step, but I'd say this
change is still worth applying.

Bart

> 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

      reply index

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-30  7:17 Bartosz Golaszewski
2019-08-30  7:17 ` [PATCH 1/4] regulator: provide regulator_bulk_set_supply_names() Bartosz Golaszewski
2019-09-02  5:39   ` kbuild test robot
2019-09-02  7:46   ` kbuild test robot
2019-09-02 12:23   ` Applied "regulator: provide regulator_bulk_set_supply_names()" to the regulator tree Mark Brown
2019-08-30  7:17 ` [PATCH 2/4] ahci: tegra: use regulator_bulk_set_supply_names() Bartosz Golaszewski
2019-08-30  7:17 ` [PATCH 3/4] phy: " Bartosz Golaszewski
2019-08-30  7:17 ` [PATCH 4/4] usb: host: xhci-tegra: " Bartosz Golaszewski
2019-08-30  8:15 ` [PATCH 0/4] regulator: add and use a helper for setting supply names Thierry Reding
2019-08-30 11:06   ` Bartosz Golaszewski [this message]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMRc=Mdy-MX6+hsrvErioUg=38s9Hspp7+2mT7nDYbjL9uQ9uQ@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=axboe@kernel.dk \
    --cc=bgolaszewski@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jckuo@nvidia.com \
    --cc=jonathanh@nvidia.com \
    --cc=kishon@ti.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-ide Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-ide/0 linux-ide/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-ide linux-ide/ https://lore.kernel.org/linux-ide \
		linux-ide@vger.kernel.org linux-ide@archiver.kernel.org
	public-inbox-index linux-ide

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-ide


AGPL code for this site: git clone https://public-inbox.org/ public-inbox