linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-ide@vger.kernel.org
Cc: Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH] scsi: fix scsi device attributes registration
Date: Thu, 11 Nov 2021 17:45:51 +0900	[thread overview]
Message-ID: <20211111084551.446548-1-damien.lemoal@opensource.wdc.com> (raw)

Since the sdev_gendev device of a scsi device defines its attributes
using scsi_sdev_attr_groups as the groups field value of its device
type, the execution of device_add() in scsi_sysfs_add_sdev() register
with sysfs only the attributes defined using scsi_sdev_attr_groups. As
a results, the attributes defined by an LLD using the scsi host
sdev_groups attribute groups are never registered with sysfs and not
visible to the users.

Fix this problem by removing scsi_sdev_attr_groups and manually setting
the groups field of a scsi device sdev_gendev to point to the scsi
device gendev_attr_groups. As the first entry of this array of
attribute groups is scsi_sdev_attr_group, using gendev_attr_groups as
the gendev groups result in all defined attributes to be created in
sysfs when device_add() is called.

Fixes: 92c4b58b15c5 ("scsi: core: Register sysfs attributes earlier")
cc: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
 drivers/scsi/scsi_sysfs.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index d3d362289ecc..92c92853f516 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -1301,11 +1301,6 @@ static struct attribute_group scsi_sdev_attr_group = {
 	.is_bin_visible = scsi_sdev_bin_attr_is_visible,
 };
 
-static const struct attribute_group *scsi_sdev_attr_groups[] = {
-	&scsi_sdev_attr_group,
-	NULL
-};
-
 static int scsi_target_add(struct scsi_target *starget)
 {
 	int error;
@@ -1575,7 +1570,6 @@ int scsi_sysfs_add_host(struct Scsi_Host *shost)
 static struct device_type scsi_dev_type = {
 	.name =		"scsi_device",
 	.release =	scsi_device_dev_release,
-	.groups =	scsi_sdev_attr_groups,
 };
 
 void scsi_sysfs_device_initialize(struct scsi_device *sdev)
@@ -1601,6 +1595,7 @@ void scsi_sysfs_device_initialize(struct scsi_device *sdev)
 		}
 	}
 	WARN_ON_ONCE(j >= ARRAY_SIZE(sdev->gendev_attr_groups));
+	sdev->sdev_gendev.groups = sdev->gendev_attr_groups;
 
 	device_initialize(&sdev->sdev_dev);
 	sdev->sdev_dev.parent = get_device(&sdev->sdev_gendev);
-- 
2.31.1


             reply	other threads:[~2021-11-11  8:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11  8:45 Damien Le Moal [this message]
2021-11-11  9:56 ` Christoph Hellwig
2021-11-11 10:35 ` Steffen Maier
2021-11-11 23:03   ` Damien Le Moal

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=20211111084551.446548-1-damien.lemoal@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=bvanassche@acm.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --subject='Re: [PATCH] scsi: fix scsi device attributes registration' \
    /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

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