linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-nvme@lists.infradead.org,
	Keith Busch <keith.busch@intel.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	linuxppc-dev@lists.ozlabs.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	linux-block@vger.kernel.org,
	Brian Norris <computersforpeace@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	linux-mtd@lists.infradead.org, "Ed L. Cashin" <ed.cashin@acm.org>,
	Jens Axboe <axboe@kernel.dk>, Minchan Kim <minchan@kernel.org>,
	virtualization@lists.linux-foundation.org,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Nitin Gupta <ngupta@vflare.org>,
	David Woodhouse <dwmw2@infradead.org>
Subject: [PATCH 12/15] mtip: Pass attribute group to device_add_disk
Date: Wed, 17 Aug 2016 15:15:12 +0800	[thread overview]
Message-ID: <1471418115-3654-13-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1471418115-3654-1-git-send-email-famz@redhat.com>

Previously after device_add_disk returns, the KOBJ_ADD uevent is already
emitted. Adding attributes after that is a poor usage of kobject, and
in practice may result in race conditions with userspace, for
example udev checks availability of certain attributes and initializes
/dev entries conditionally.

device_add_disk can handle adding attribute group better, so use it.
Meanwhile, update the error check code and message.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 drivers/block/mtip32xx/mtip32xx.c | 38 ++++++++------------------------------
 1 file changed, 8 insertions(+), 30 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 4048a70..504c549 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -2702,26 +2702,14 @@ static const struct file_operations mtip_flags_fops = {
 	.llseek = no_llseek,
 };
 
-/*
- * Create the sysfs related attributes.
- *
- * @dd   Pointer to the driver data structure.
- * @kobj Pointer to the kobj for the block device.
- *
- * return value
- *	0	Operation completed successfully.
- *	-EINVAL Invalid parameter.
- */
-static int mtip_hw_sysfs_init(struct driver_data *dd, struct kobject *kobj)
-{
-	if (!kobj || !dd)
-		return -EINVAL;
+static struct attribute *mtip_dev_attrs[] = {
+	&dev_attr_status.attr,
+	NULL
+};
 
-	if (sysfs_create_file(kobj, &dev_attr_status.attr))
-		dev_warn(&dd->pdev->dev,
-			"Error creating 'status' sysfs entry\n");
-	return 0;
-}
+static struct attribute_group mtip_attr_group = {
+	.attrs = mtip_dev_attrs,
+};
 
 /*
  * Remove the sysfs related attributes.
@@ -3918,7 +3906,6 @@ static int mtip_block_initialize(struct driver_data *dd)
 	int rv = 0, wait_for_rebuild = 0;
 	sector_t capacity;
 	unsigned int index = 0;
-	struct kobject *kobj;
 
 	if (dd->disk)
 		goto skip_create_disk; /* hw init done, before rebuild */
@@ -4041,18 +4028,9 @@ skip_create_disk:
 	set_capacity(dd->disk, capacity);
 
 	/* Enable the block device and add it to /dev */
-	device_add_disk(&dd->pdev->dev, dd->disk, NULL);
+	device_add_disk(&dd->pdev->dev, dd->disk, &mtip_attr_group);
 
 	dd->bdev = bdget_disk(dd->disk, 0);
-	/*
-	 * Now that the disk is active, initialize any sysfs attributes
-	 * managed by the protocol layer.
-	 */
-	kobj = kobject_get(&disk_to_dev(dd->disk)->kobj);
-	if (kobj) {
-		mtip_hw_sysfs_init(dd, kobj);
-		kobject_put(kobj);
-	}
 
 	if (dd->mtip_svc_handler) {
 		set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
-- 
2.7.4

  parent reply	other threads:[~2016-08-17  7:16 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17  7:15 [PATCH 00/15] Fix issue with KOBJ_ADD uevent versus disk attributes Fam Zheng
2016-08-17  7:15 ` [PATCH 01/15] disk: Drop add_disk in favor of device_add_disk Fam Zheng
2016-08-17  7:15 ` [PATCH 02/15] genhd: Return error from register_disk() Fam Zheng
2016-08-17  7:15 ` [PATCH 03/15] genhd: Return error from blk_register_region Fam Zheng
2016-08-17  7:15 ` [PATCH 04/15] block: Return error from blk_integrity_add Fam Zheng
2016-08-17  7:15 ` [PATCH 05/15] genhd: Return error from disk_{add,alloc}_events Fam Zheng
2016-08-17  7:15 ` [PATCH 06/15] genhd: Add return code to device_add_disk Fam Zheng
2016-08-17  8:49   ` Cornelia Huck
2016-08-17  8:48     ` Fam Zheng
2016-08-17  9:06       ` Cornelia Huck
2016-08-17  9:14         ` Fam Zheng
2016-08-18  1:09           ` Ed Cashin
2016-08-17  7:15 ` [PATCH 07/15] genhd: Add attribute group parameter " Fam Zheng
2016-08-17  7:15 ` [PATCH 08/15] nvme: Pass attribute group " Fam Zheng
2016-08-17  8:13   ` kbuild test robot
2016-08-17  7:15 ` [PATCH 09/15] virtio-blk: " Fam Zheng
2016-09-04  4:18   ` Michael S. Tsirkin
2016-08-17  7:15 ` [PATCH 10/15] mtd: " Fam Zheng
2016-08-17  7:15 ` [PATCH 11/15] zram: " Fam Zheng
2016-08-18  1:59   ` Sergey Senozhatsky
2016-08-18  2:06     ` Sergey Senozhatsky
2016-08-17  7:15 ` Fam Zheng [this message]
2016-08-17  7:15 ` [PATCH 13/15] aoeblk: " Fam Zheng
2016-08-17  7:15 ` [PATCH 14/15] axonram: " Fam Zheng
2016-08-17  7:15 ` [PATCH 15/15] block: Add FIXME comment to handle device_add_disk error Fam Zheng
2016-08-18  2:36   ` Sergey Senozhatsky

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=1471418115-3654-13-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=benh@kernel.crashing.org \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=ed.cashin@acm.org \
    --cc=keith.busch@intel.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=minchan@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=mst@redhat.com \
    --cc=ngupta@vflare.org \
    --cc=paulus@samba.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=virtualization@lists.linux-foundation.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;
as well as URLs for NNTP newsgroup(s).