From: Steffen Maier <maier@linux.ibm.com>
To: Damien Le Moal <damien.lemoal@opensource.wdc.com>,
linux-scsi@vger.kernel.org,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Bart Van Assche <bvanassche@acm.org>,
Benjamin Block <bblock@linux.ibm.com>
Subject: Re: [PATCH] scsi: simplify registration of scsi host sysfs attributes
Date: Mon, 15 Nov 2021 12:43:39 +0100 [thread overview]
Message-ID: <c01c238d-6fc4-83fb-2288-dbb21bdd642f@linux.ibm.com> (raw)
In-Reply-To: <20211115092922.367777-1-damien.lemoal@opensource.wdc.com>
On 11/15/21 10:29, Damien Le Moal wrote:
> Similarly to the way attribute groups are registered for a scsi device
> using the device sdev_gendev, a scsi host attribute groups can be
> registered by specifying the generic attribute groups using the groups
> field of the scsi_host_type (struct device_type) and set the array of
> host attribute groups provided by the LLDD using the groups field of the
> host shost_dev generic device. This partially reverts the changes
> introduced by commit 92c4b58b15c5 ("scsi: core: Register sysfs
> attributes earlier"), avoiding the for loop to build a size limited
> array of attribute groups from the generic attributes and LLDD provided
> attribut groups.
See also
https://lore.kernel.org/linux-scsi/2f5e5d18-7ba9-10f6-1855-84546172b473@linux.ibm.com/T/#md21644c177f45a0721d4fa3bdb84fbafb2bc8981
?
E.g. your patch does not seem to remove the now unused(?)
Scsi_Host.shost_dev_attr_groups ?
Not sure which is better: Bart using the scsi_host class or your below patch
using scsi_host device_type.
>
> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> ---
> drivers/scsi/hosts.c | 15 +++------------
> drivers/scsi/scsi_priv.h | 2 +-
> drivers/scsi/scsi_sysfs.c | 7 ++++++-
> 3 files changed, 10 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
> index 8049b00b6766..c3b6812aac5b 100644
> --- a/drivers/scsi/hosts.c
> +++ b/drivers/scsi/hosts.c
> @@ -359,6 +359,7 @@ static void scsi_host_dev_release(struct device *dev)
> static struct device_type scsi_host_type = {
> .name = "scsi_host",
> .release = scsi_host_dev_release,
> + .groups = scsi_sysfs_shost_attr_groups,
> };
>
> /**
> @@ -377,7 +378,7 @@ static struct device_type scsi_host_type = {
> struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
> {
> struct Scsi_Host *shost;
> - int index, i, j = 0;
> + int index;
>
> shost = kzalloc(sizeof(struct Scsi_Host) + privsize, GFP_KERNEL);
> if (!shost)
> @@ -483,17 +484,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
> shost->shost_dev.parent = &shost->shost_gendev;
> shost->shost_dev.class = &shost_class;
> dev_set_name(&shost->shost_dev, "host%d", shost->host_no);
> - shost->shost_dev.groups = shost->shost_dev_attr_groups;
> - shost->shost_dev_attr_groups[j++] = &scsi_shost_attr_group;
> - if (sht->shost_groups) {
> - for (i = 0; sht->shost_groups[i] &&
> - j < ARRAY_SIZE(shost->shost_dev_attr_groups);
> - i++, j++) {
> - shost->shost_dev_attr_groups[j] =
> - sht->shost_groups[i];
> - }
> - }
> - WARN_ON_ONCE(j >= ARRAY_SIZE(shost->shost_dev_attr_groups));
> + shost->shost_dev.groups = sht->shost_groups;
>
> shost->ehandler = kthread_run(scsi_error_handler, shost,
> "scsi_eh_%d", shost->host_no);
> diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
> index a278fc8948f4..f8ca22d495d9 100644
> --- a/drivers/scsi/scsi_priv.h
> +++ b/drivers/scsi/scsi_priv.h
> @@ -144,7 +144,7 @@ extern struct scsi_transport_template blank_transport_template;
> extern void __scsi_remove_device(struct scsi_device *);
>
> extern struct bus_type scsi_bus_type;
> -extern const struct attribute_group scsi_shost_attr_group;
> +extern const struct attribute_group *scsi_sysfs_shost_attr_groups[];
>
> /* scsi_netlink.c */
> #ifdef CONFIG_SCSI_NETLINK
> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index 55addd78fde4..c3b93d2de081 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -424,10 +424,15 @@ static struct attribute *scsi_sysfs_shost_attrs[] = {
> NULL
> };
>
> -const struct attribute_group scsi_shost_attr_group = {
> +static const struct attribute_group scsi_shost_attr_group = {
> .attrs = scsi_sysfs_shost_attrs,
> };
>
> +const struct attribute_group *scsi_sysfs_shost_attr_groups[] = {
> + &scsi_shost_attr_group,
> + NULL,
> +};
> +
> static void scsi_device_cls_release(struct device *class_dev)
> {
> struct scsi_device *sdev;
>
--
Mit freundlichen Gruessen / Kind regards
Steffen Maier
Linux on IBM Z and LinuxONE
https://www.ibm.com/privacy/us/en/
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
next prev parent reply other threads:[~2021-11-15 11:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-15 9:29 [PATCH] scsi: simplify registration of scsi host sysfs attributes Damien Le Moal
2021-11-15 11:43 ` Steffen Maier [this message]
2021-11-15 17:36 ` Bart Van Assche
2021-11-16 3:29 ` Damien Le Moal
2021-11-16 4:22 ` Bart Van Assche
2021-11-16 4:54 ` Damien Le Moal
2021-11-19 8:24 ` [scsi] c8f22155c6: BUG:KASAN:slab-out-of-bounds_in_show_shost_state 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=c01c238d-6fc4-83fb-2288-dbb21bdd642f@linux.ibm.com \
--to=maier@linux.ibm.com \
--cc=bblock@linux.ibm.com \
--cc=bvanassche@acm.org \
--cc=damien.lemoal@opensource.wdc.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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
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