mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Allen Webb <allenwebb@google.com>,
	"linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Subject: Re: [PATCH v6 2/5] drivers: Add bus_for_each for iterating over the subsystems
Date: Sat, 3 Dec 2022 18:07:53 +0000	[thread overview]
Message-ID: <8831b90c-4968-a618-a6ba-4bfcc97f74eb@csgroup.eu> (raw)
In-Reply-To: <20221202224744.1447448-2-allenwebb@google.com>



Le 02/12/2022 à 23:47, Allen Webb a écrit :
> In order to print the match-id-based modaliases it must be possible to
> reach the match id tables of each driver. With this function it becomes
> possible to iterate over each subsystem which can be paired with
> iterating over each driver.
> 
> Signed-off-by: Allen Webb <allenwebb@google.com>
> ---
>   drivers/base/bus.c         | 42 ++++++++++++++++++++++++++++++++++++++
>   include/linux/device/bus.h |  1 +
>   2 files changed, 43 insertions(+)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index 7ca47e5b3c1f4..4e0c5925545e5 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -178,6 +178,48 @@ static const struct kset_uevent_ops bus_uevent_ops = {
>   
>   static struct kset *bus_kset;
>   
> +/**
> + * bus_for_each - bus iterator.
> + * @start: bus to start iterating from.
> + * @data: data for the callback.
> + * @fn: function to be called for each device.
> + *
> + * Iterate over list of buses, and call @fn for each,
> + * passing it @data. If @start is not NULL, we use that bus to
> + * begin iterating from.
> + *
> + * We check the return of @fn each time. If it returns anything
> + * other than 0, we break out and return that value.
> + *
> + * NOTE: The bus that returns a non-zero value is not retained
> + * in any way, nor is its refcount incremented. If the caller needs
> + * to retain this data, it should do so, and increment the reference
> + * count in the supplied callback.
> + */
> +int bus_for_each(void *data, int (*fn)(struct bus_type *, void *))
> +{
> +	int error = 0;
> +	struct bus_type *bus;
> +	struct subsys_private *bus_prv;
> +	struct kset *subsys;
> +	struct kobject *k;

Those vars are not used outside of the list_for_each_entry() block, they 
should be declared inside the block.

> +
> +	spin_lock(&bus_kset->list_lock);
> +
> +	list_for_each_entry(k, &bus_kset->list, entry) {
> +		subsys = container_of(k, struct kset, kobj);
> +		bus_prv = container_of(subsys, struct subsys_private, subsys);
> +		bus = bus_prv->bus;
> +		error = fn(bus, data);
> +		if (error)
> +			break;
> +	}
> +
> +	spin_unlock(&bus_kset->list_lock);
> +	return error;
> +}
> +EXPORT_SYMBOL_GPL(bus_for_each);
> +
>   /* Manually detach a device from its associated driver. */
>   static ssize_t unbind_store(struct device_driver *drv, const char *buf,
>   			    size_t count)
> diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
> index d8b29ccd07e56..82a5583437099 100644
> --- a/include/linux/device/bus.h
> +++ b/include/linux/device/bus.h
> @@ -161,6 +161,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
>   struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
>   void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>   
> +int bus_for_each(void *data, int (*fn)(struct bus_type *, void *));
>   int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>   		     int (*fn)(struct device *dev, void *data));
>   struct device *bus_find_device(struct bus_type *bus, struct device *start,

  reply	other threads:[~2022-12-03 18:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAJzde07w6U83U_63eaF0-6zaq0cOkaymuLb3CBZ++JQi+Y9JdA@mail.gmail.com>
2022-12-01 21:16 ` [PATCH v5 0/1] Fix CONFIG_USB=y && CONFIG_MODULES not set Allen Webb
2022-12-02 12:45   ` Greg Kroah-Hartman
2022-12-02 12:46   ` Greg Kroah-Hartman
2022-12-01 21:16 ` [PATCH v5 1/1] modules: add modalias file to sysfs for modules Allen Webb
2022-12-02 12:49   ` Greg Kroah-Hartman
2022-12-02 22:45     ` [PATCH v6 0/5] Add sysfs match-id modalias attribute for USB modules Allen Webb
2022-12-02 22:47       ` [PATCH v6 1/5] module: Add empty modalias sysfs attribute Allen Webb
2022-12-02 22:47         ` [PATCH v6 2/5] drivers: Add bus_for_each for iterating over the subsystems Allen Webb
2022-12-03 18:07           ` Christophe Leroy [this message]
2022-12-05 15:45           ` Greg Kroah-Hartman
2022-12-02 22:47         ` [PATCH v6 3/5] Implement modalias sysfs attribute for modules Allen Webb
2022-12-03 18:12           ` Christophe Leroy
2022-12-05 15:51           ` Greg Kroah-Hartman
2022-12-02 22:47         ` [PATCH v6 4/5] docs: Add entry for /sys/module/*/modalias Allen Webb
2022-12-02 22:47         ` [PATCH v6 5/5] drivers: Implement module modaliases for USB Allen Webb
2022-12-03 18:25           ` Christophe Leroy
2022-12-04  8:27             ` Greg Kroah-Hartman
2022-12-05 15:53           ` Greg Kroah-Hartman
2022-12-03 18:05         ` [PATCH v6 1/5] module: Add empty modalias sysfs attribute Christophe Leroy
2022-12-05 15:42         ` Greg Kroah-Hartman
2022-12-11 10:44   ` [PATCH v5 1/1] modules: add modalias file to sysfs for modules kernel test robot

Reply instructions:

You may reply publicly 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=8831b90c-4968-a618-a6ba-4bfcc97f74eb@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=allenwebb@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=rafael@kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®