Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp244528pxf; Wed, 10 Mar 2021 05:32:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWU5R9yRaBzqZJVNRMrDyphwj/6yizOB3CLD0mXx4mx3OsmXF9idiPjZgQ9OqcpbYIbz/z X-Received: by 2002:a05:6402:3049:: with SMTP id bu9mr3366141edb.104.1615383145796; Wed, 10 Mar 2021 05:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615383145; cv=none; d=google.com; s=arc-20160816; b=kOIg7ifG0FwM9wQRYpDFaGIjGv2I+O+f12/EDY8X+5J29t+BhHzxfwHnCtGpXUDoaP +o5ki5D7lbFn9p9Fm97e2wA1//8OhgUl+VZjbV02J7HOGFaZu/CDjBD8gCuYd9Y8TnTS e6w0Dtq9eeSJw0HkTb6UP3pjvgWyCgoC7ZzyzGj0tSrk4nuUreDzx6/aj9YtYmbn8NEq ngw16QYLlwdhE2Mn/7wiYjBop4XkXL7oO7esOb449KUNTcdZ5cG9akf4mEysVS2zJS/m 5Gcy6mCsxzUrY/lrYEG48fG7SXWLNrnBZevS3Bucrfj8ShADJjxRlkRqBL1shw/I9nrz vbXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bh+QrlHYzgCl5sFKXHzWL+gJYhL3mOvSaOYw5AYDZx0=; b=r+s3Ygz7LbSxOW9yHg/oRPepF6A2ekf2YOQYTpdAL1FUwH90Np7uZ6L6xCRSnM0daW 9I9QmOntSV9nRAIoWD3nbhqC6S6tiug0GBSBHYR5SYYXaJ6QGosuUMpeRO4lsSX9VFFB 5a/gnzqTyHkYxVArEMQFBpJd+KwX8GPzei8hmONrakmqkKaeSXpfvxD1QVA8Xd7gh4Nj 7PLP79y9mWca0sYWvSFlOvmUkSCf6QxnRobXmMTmx8n1n25okpus6ZXfC6LViQpW719z FUKo2BjW5zUve45WNorwd2hCdDfC9jmyxvYjpVRBZVFigwkpnOobQVoDezusq7l+L5oa TemA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SLt08xFG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v15si12975657edl.21.2021.03.10.05.32.01; Wed, 10 Mar 2021 05:32:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SLt08xFG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233097AbhCJN3B (ORCPT + 99 others); Wed, 10 Mar 2021 08:29:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:47144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbhCJNZR (ORCPT ); Wed, 10 Mar 2021 08:25:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9E3E464FD7; Wed, 10 Mar 2021 13:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615382717; bh=Mv+hLXHkjrDzBrzMtasAFMxtG84yYgmUgwvTbvG0mBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SLt08xFGczD83OExF9TXONqLNVXEHLZR3ZZgsKL7cuzKqf8Qq9+lIZilvpIjfcCbX zrQvSmUE/92pd9PwAY6PSEKhbvOuRGk0SZbaDhg81b9YEzDULEew/zLX9B3G1mp1Qv mAoe3ExDNGUA18bp7Q3YLnpRQuhZn6XdRtTqIIFY= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hannes Reinecke , Minchan Kim , Nitin Gupta , Christoph Hellwig , Bart Van Assche , Jens Axboe , Jeffle Xu Subject: [PATCH 4.19 14/39] zram: register default groups with device_add_disk() Date: Wed, 10 Mar 2021 14:24:22 +0100 Message-Id: <20210310132320.177065779@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210310132319.708237392@linuxfoundation.org> References: <20210310132319.708237392@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Hannes Reinecke commit 98af4d4df889dcea3bc0ce6b8a04759658ba8826 upstream. Register default sysfs groups during device_add_disk() to avoid a race condition with udev during startup. Signed-off-by: Hannes Reinecke Cc: Minchan Kim Cc: Nitin Gupta Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche Signed-off-by: Jens Axboe Signed-off-by: Jeffle Xu Signed-off-by: Greg Kroah-Hartman --- drivers/block/zram/zram_drv.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1644,6 +1644,11 @@ static const struct attribute_group zram .attrs = zram_disk_attrs, }; +static const struct attribute_group *zram_disk_attr_groups[] = { + &zram_disk_attr_group, + NULL, +}; + /* * Allocate and initialize new zram device. the function returns * '>= 0' device_id upon success, and negative value otherwise. @@ -1724,24 +1729,14 @@ static int zram_add(void) zram->disk->queue->backing_dev_info->capabilities |= (BDI_CAP_STABLE_WRITES | BDI_CAP_SYNCHRONOUS_IO); - add_disk(zram->disk); + device_add_disk(NULL, zram->disk, zram_disk_attr_groups); - 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); - goto out_free_disk; - } strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor)); zram_debugfs_register(zram); pr_info("Added device: %s\n", zram->disk->disk_name); return device_id; -out_free_disk: - del_gendisk(zram->disk); - put_disk(zram->disk); out_free_queue: blk_cleanup_queue(queue); out_free_idr: @@ -1770,15 +1765,6 @@ static int zram_remove(struct zram *zram mutex_unlock(&bdev->bd_mutex); zram_debugfs_unregister(zram); - /* - * Remove sysfs first, so no one will perform a disksize - * store while we destroy the devices. This also helps during - * hot_remove -- zram_reset_device() is the last holder of - * ->init_lock, no later/concurrent disksize_store() or any - * other sysfs handlers are possible. - */ - sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, - &zram_disk_attr_group); /* Make sure all the pending I/O are finished */ fsync_bdev(bdev);