diff mbox

[08/15] nvme: Pass attribute group to device_add_disk

Message ID 1471418115-3654-9-git-send-email-famz@redhat.com
State New, archived
Headers show

Commit Message

Fam Zheng Aug. 17, 2016, 7:15 a.m. UTC
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.

Signed-off-by: Fam Zheng <famz@redhat.com>
 drivers/nvme/host/core.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)


kernel test robot Aug. 17, 2016, 8:13 a.m. UTC | #1
Hi Fam,

[auto build test WARNING on linus/master]
[also build test WARNING on v4.8-rc2 next-20160817]
[cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Fam-Zheng/Fix-issue-with-KOBJ_ADD-uevent-versus-disk-attributes/20160817-152900
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All warnings (new ones prefixed by >>):

   drivers/nvme/host/core.c: In function 'nvme_alloc_ns':
>> drivers/nvme/host/core.c:1689:42: warning: passing argument 3 of 'device_add_disk' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     device_add_disk(ctrl->device, ns->disk, &nvme_ns_attr_group);
   In file included from include/linux/blkdev.h:9:0,
                    from drivers/nvme/host/core.c:15:
   include/linux/genhd.h:416:12: note: expected 'struct attribute_group *' but argument is of type 'const struct attribute_group *'
    extern int device_add_disk(struct device *parent, struct gendisk *disk,

vim +1689 drivers/nvme/host/core.c

  1673		disk->private_data = ns;
  1674		disk->queue = ns->queue;
  1675		disk->flags = GENHD_FL_EXT_DEVT;
  1676		sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, ns->instance);
  1678		if (nvme_revalidate_disk(ns->disk))
  1679			goto out_free_disk;
  1681		mutex_lock(&ctrl->namespaces_mutex);
  1682		list_add_tail(&ns->list, &ctrl->namespaces);
  1683		mutex_unlock(&ctrl->namespaces_mutex);
  1685		kref_get(&ctrl->kref);
  1686		if (ns->type == NVME_NS_LIGHTNVM)
  1687			return;
> 1689		device_add_disk(ctrl->device, ns->disk, &nvme_ns_attr_group);
  1690		return;
  1691	 out_free_disk:
  1692		kfree(disk);
  1693	 out_free_queue:
  1694		blk_cleanup_queue(ns->queue);
  1695	 out_release_instance:
  1696		ida_simple_remove(&ctrl->ns_ida, ns->instance);
  1697	 out_free_ns:

0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox


diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 23a795f..1921cb2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1686,11 +1686,7 @@  static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	if (ns->type == NVME_NS_LIGHTNVM)
-	device_add_disk(ctrl->device, ns->disk, NULL);
-	if (sysfs_create_group(&disk_to_dev(ns->disk)->kobj,
-					&nvme_ns_attr_group))
-		pr_warn("%s: failed to create sysfs group for identification\n",
-			ns->disk->disk_name);
+	device_add_disk(ctrl->device, ns->disk, &nvme_ns_attr_group);