From patchwork Thu Sep 28 19:36:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 9976693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 435CD603F2 for ; Thu, 28 Sep 2017 19:37:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34D23296D9 for ; Thu, 28 Sep 2017 19:37:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2964F29702; Thu, 28 Sep 2017 19:37:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC0AE296D9 for ; Thu, 28 Sep 2017 19:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751138AbdI1ThY (ORCPT ); Thu, 28 Sep 2017 15:37:24 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:38425 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750943AbdI1ThX (ORCPT ); Thu, 28 Sep 2017 15:37:23 -0400 Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Thu, 28 Sep 2017 21:37:22 +0200 Received: from apollon.suse.de.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Thu, 28 Sep 2017 20:37:02 +0100 From: Martin Wilck To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Hannes Reinecke , linux-nvme@lists.infradead.org, Martin Wilck Subject: [PATCH 2/2] nvme: use device_add_disk_with_groups() Date: Thu, 28 Sep 2017 21:36:37 +0200 Message-Id: <20170928193637.24707-2-mwilck@suse.com> X-Mailer: git-send-email 2.14.0 In-Reply-To: <20170928193637.24707-1-mwilck@suse.com> References: <20170928193637.24707-1-mwilck@suse.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By using device_add_disk_with_groups(), we can avoid the race condition with udev rule processing, because no udev event will be triggered before all attributes are available. Signed-off-by: Martin Wilck Tested-by: Steve Schremmer Reviewed-by: Keith Busch --- drivers/nvme/host/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 5a14cc7f28ee..e7289a727715 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2156,6 +2156,11 @@ static const struct attribute_group nvme_ns_attr_group = { .is_visible = nvme_ns_attrs_are_visible, }; +static const struct attribute_group *nvme_ns_attr_groups[] = { + &nvme_ns_attr_group, + NULL, +}; + #define nvme_show_str_function(field) \ static ssize_t field##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ @@ -2405,11 +2410,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) kfree(id); - device_add_disk(ctrl->device, ns->disk); - 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_with_groups(ctrl->device, ns->disk, + nvme_ns_attr_groups); if (ns->ndev && nvme_nvm_register_sysfs(ns)) pr_warn("%s: failed to register lightnvm sysfs group for identification\n", ns->disk->disk_name);