Re: [PATCH 1/2] scsi: Register SCSI host sysfs attributes earlier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/25/21 2:02 AM, Greg Kroah-Hartman wrote:
On Fri, Sep 24, 2021 at 04:26:34PM -0700, Bart Van Assche wrote:
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 3f6f14f0cafb..f424aca6dc6e 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -480,7 +480,15 @@ 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 = scsi_sysfs_shost_attr_groups;
+	shost->shost_dev.groups = shost->shost_dev_attr_groups;
+	shost->shost_dev_attr_groups[0] = &scsi_host_attr_group;
+	if (shost->hostt->shost_attrs) {
+		shost->shost_dev_attr_groups[1] =
+			&shost->shost_driver_attr_group;
+		shost->shost_driver_attr_group = (struct attribute_group){
+			.attrs = shost->hostt->shost_attrs,
+		};

Did you just allocate this off the stack?  What happens when the
function returns and the stack data is returned?

The SCSI host data structure is allocated as follows:

	shost = kzalloc(sizeof(struct Scsi_Host) + privsize, GFP_KERNEL);

So the shost->shost_dev_attr_groups array exists in SLAB memory.

--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -476,7 +476,7 @@ struct scsi_host_template {
  	/*
  	 * Pointer to the sysfs class properties for this host, NULL terminated.
  	 */
-	struct device_attribute **shost_attrs;
+	struct attribute **shost_attrs;

Why isn't this "struct attribute_group **groups"?

I will make this change.

@@ -695,6 +695,8 @@ struct Scsi_Host {
/* ldm bits */
  	struct device		shost_gendev, shost_dev;
+	struct attribute_group  shost_driver_attr_group;
+	const struct attribute_group *shost_dev_attr_groups[3];

Why just 3?

I'm trying to avoid yet another dynamic memory allocation. One array entry
is for the SCSI core attribute group, the second array entry is for the
group with device driver attributes and the third entry is the NULL sentinel.

Thanks,

Bart.



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux