From patchwork Wed Aug 17 07:15:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9285281 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 7BCF960459 for ; Wed, 17 Aug 2016 07:24:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6953B287BC for ; Wed, 17 Aug 2016 07:24:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A4E62884A; Wed, 17 Aug 2016 07:24:58 +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 F3533287BC for ; Wed, 17 Aug 2016 07:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754016AbcHQHYc (ORCPT ); Wed, 17 Aug 2016 03:24:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50562 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753764AbcHQHYa (ORCPT ); Wed, 17 Aug 2016 03:24:30 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BA0F71096; Wed, 17 Aug 2016 07:16:15 +0000 (UTC) Received: from lemon.nay.redhat.com (dhcp-15-153.nay.redhat.com [10.66.15.153]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7H7FGWF008426; Wed, 17 Aug 2016 03:16:10 -0400 From: Fam Zheng To: linux-kernel@vger.kernel.org Cc: linux-nvme@lists.infradead.org, Keith Busch , Michael Ellerman , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, "Michael S. Tsirkin" , linux-block@vger.kernel.org, Brian Norris , Paul Mackerras , linux-mtd@lists.infradead.org, "Ed L. Cashin" , Jens Axboe , Minchan Kim , virtualization@lists.linux-foundation.org, Sergey Senozhatsky , Nitin Gupta , David Woodhouse Subject: [PATCH 11/15] zram: Pass attribute group to device_add_disk Date: Wed, 17 Aug 2016 15:15:11 +0800 Message-Id: <1471418115-3654-12-git-send-email-famz@redhat.com> In-Reply-To: <1471418115-3654-1-git-send-email-famz@redhat.com> References: <1471418115-3654-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 17 Aug 2016 07:16:15 +0000 (UTC) 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 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 --- drivers/block/zram/zram_drv.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 20920a2..2331788 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1298,13 +1298,10 @@ static int zram_add(void) zram->disk->queue->limits.discard_zeroes_data = 0; queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, zram->disk->queue); - device_add_disk(NULL, zram->disk, NULL); + ret = device_add_disk(NULL, zram->disk, &zram_disk_attr_group); - ret = sysfs_create_group(&disk_to_dev(zram->disk)->kobj, - &zram_disk_attr_group); if (ret < 0) { - pr_err("Error creating sysfs group for device %d\n", - device_id); + pr_err("Error creating disk %d\n", device_id); goto out_free_disk; } strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));