linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: simplify registration of scsi host sysfs attributes
@ 2021-11-15  9:29 Damien Le Moal
  2021-11-15 11:43 ` Steffen Maier
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Damien Le Moal @ 2021-11-15  9:29 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen

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.

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;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-11-19  8:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15  9:29 [PATCH] scsi: simplify registration of scsi host sysfs attributes Damien Le Moal
2021-11-15 11:43 ` Steffen Maier
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).