Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp183220lqn; Thu, 11 Apr 2024 19:31:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXiD8izy93Q1nNU1ZkJWbrRtEN2mQTosWT7ulsD1WV/Iluj5NUIdEw9WKHUKSSKWDa2qvLeTPpnnrXmV+6AZmoM+y+M9qaVRWfywrzFzw== X-Google-Smtp-Source: AGHT+IHVtZz7RVqcFWbWYzNtyUsXSnOjMxMDn9bAwETA54fxz5PclT0fd/yWWHzTgKZv0zUJAkBD X-Received: by 2002:a05:6870:b52a:b0:22e:9806:f97a with SMTP id v42-20020a056870b52a00b0022e9806f97amr1334568oap.2.1712889088356; Thu, 11 Apr 2024 19:31:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712889088; cv=pass; d=google.com; s=arc-20160816; b=oFRqkZxRJEZso8Xcpq5ifA1+WvrMy0J+PIAsGxg81zHdlCWfb+bEuiyT9sqkb+LHkS u7a+bKJkFQF3PeP6OrJLNaimPw4gJ8PPdoxPy2AQC0f37wjikPFzXG8Fk1E3OJw3HD8v wOLJvbOoPVaalCOsUuamqZHA27pZT1UQd3juZyx37f+3q+u12izFh+H6NvAghhEL9uUa LIN8pd+AklV9Pez6qPmtVl5lSga63qti6p5KSRvzFh+tmO/Pplus9gPGOOSZLyf4RVWo krLbeInuZkxKB7scnwfEi8uEcU1ICYSbBqvBgYDC8xnZ+CCS1Bx/xYc12WM0ykeJZLtm 2DiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=w/Nt6uRcKV4S1UFxqTX+yFbM6WHLLy/Ozcnv8kzTK4I=; fh=sqnfbAYcYy9BDg93Nd0WgM2+dXW9FHlsd/facGZqYGU=; b=P96bI3afjtuuQ55vZkXfuE+foZjj1HRNWY83gZqOikU7+DwR2TLM1w3SrR/ejpefV9 iK6SWu1qu7ADz+LA2eLWm8FA5U9S7OOfCHNWYJfPKwkermFr1FGJqkdK6gSbjmx7ACND Brb+bGo0STNICsMlbkVSUf9XU8TGkeIeR/N3BE+s6KvDyi0UJA1lbexhkYsZUn7squdz f12M06GxhBLrDFcU2P4nV/Ivkws2eX5PuS7jeEljubn5caElus6LE/wqE01pc6eZpqiA uDwk22DfkhHkvtrRj/dlftXstCFC9xb8SYUZLC8vfnufCdqkzgjAtGLke6oV7iQ9rP6i I/2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-141812-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bv130-20020a632e88000000b005dc76f56a18si2207521pgb.559.2024.04.11.19.31.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 19:31:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141812-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-141812-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0B895284131 for ; Fri, 12 Apr 2024 02:31:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBA9310957; Fri, 12 Apr 2024 02:31:22 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E92E205E34; Fri, 12 Apr 2024 02:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712889082; cv=none; b=QpOMhPHyJQBFaXSTO7LHaSAgcoqGGlDa/LFWYAoBvNGcFFhcJQupdQdZ2wIkWk6s8V3FUCW7B6QG+C3W0ZS7w6ajSlPW6MQxOUyZKy0e7Z4fvMlQby9jYqCnQQWGn1F8xhgWPrtBEIuSnkNkn2lNxcNgoKNg4OQOU+xCyuflagI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712889082; c=relaxed/simple; bh=GYv3jLCzBzSLGkmeYDpAlmFWCL32zZ6LZ0+zXlJPS18=; h=Message-ID:Date:MIME-Version:Subject:From:To:CC:References: In-Reply-To:Content-Type; b=pB7NKRkGnQPjtARWQu9X6DOKMrSYz6rCjKPre7GtEjw5BJ+RXXPxETgC5WY1eG5mz0/T4+EC9DUmoe8ivs+ZjZro1Ru/mgd+kBW4Z7YSWEZjtn/R06FJQ3w7vipI/yPT+Eol0PTHyBSkYeNJ1rbrJBt/UyhbeCUnO8OV311SLlA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4VG0qD4MWyz2CcD9; Fri, 12 Apr 2024 10:28:24 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id F36701A0172; Fri, 12 Apr 2024 10:31:17 +0800 (CST) Received: from [10.67.111.104] (10.67.111.104) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 12 Apr 2024 10:31:17 +0800 Message-ID: Date: Fri, 12 Apr 2024 10:31:17 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] bcachefs: chardev: make bch_chardev_class constant Content-Language: en-US From: Hongbo Li To: "Ricardo B. Marliere" , Kent Overstreet , Brian Foster CC: , , Greg Kroah-Hartman References: <20240308-bcachefs-v2-1-3e84c845055e@marliere.net> <4ddd2362-2383-434a-b4b0-2075072572d6@huawei.com> In-Reply-To: <4ddd2362-2383-434a-b4b0-2075072572d6@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500022.china.huawei.com (7.185.36.66) On 2024/3/11 9:41, Hongbo Li wrote: > It's fine for me. > > On 2024/3/8 20:12, Ricardo B. Marliere wrote: >> Since commit 43a7206b0963 ("driver core: class: make class_register() >> take >> a const *"), the driver core allows for struct class to be in read-only >> memory, so move the bch_chardev_class structure to be declared at build >> time placing it into read-only memory, instead of having to be >> dynamically >> allocated at boot time. Also, correctly clean up after failing paths in >> bch2_chardev_init(). >> >> Cc: Hongbo Li >> Cc: Greg Kroah-Hartman >> Suggested-by: Greg Kroah-Hartman >> Signed-off-by: Ricardo B. Marliere >> --- >> Changes in v2: >> - Used "free the last thing" pattern in bch2_chardev_init(). >> - Link to v1: >> https://lore.kernel.org/r/20240305-bcachefs-v1-1-436196e25729@marliere.net >> --- >>   fs/bcachefs/chardev.c | 35 ++++++++++++++++++++++------------- >>   1 file changed, 22 insertions(+), 13 deletions(-) >> >> diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c >> index 226b39c17667..dc09f547dae6 100644 >> --- a/fs/bcachefs/chardev.c >> +++ b/fs/bcachefs/chardev.c >> @@ -940,7 +940,9 @@ static const struct file_operations >> bch_chardev_fops = { >>   }; >>   static int bch_chardev_major; >> -static struct class *bch_chardev_class; >> +static const struct class bch_chardev_class = { >> +    .name = "bcachefs", >> +}; >>   static struct device *bch_chardev; >>   void bch2_fs_chardev_exit(struct bch_fs *c) >> @@ -957,7 +959,7 @@ int bch2_fs_chardev_init(struct bch_fs *c) >>       if (c->minor < 0) >>           return c->minor; >> -    c->chardev = device_create(bch_chardev_class, NULL, >> +    c->chardev = device_create(&bch_chardev_class, NULL, >>                      MKDEV(bch_chardev_major, c->minor), c, >>                      "bcachefs%u-ctl", c->minor); >>       if (IS_ERR(c->chardev)) >> @@ -968,32 +970,39 @@ int bch2_fs_chardev_init(struct bch_fs *c) >>   void bch2_chardev_exit(void) >>   { >> -    if (!IS_ERR_OR_NULL(bch_chardev_class)) >> -        device_destroy(bch_chardev_class, >> -                   MKDEV(bch_chardev_major, U8_MAX)); >> -    if (!IS_ERR_OR_NULL(bch_chardev_class)) >> -        class_destroy(bch_chardev_class); >> +    device_destroy(&bch_chardev_class, MKDEV(bch_chardev_major, >> U8_MAX)); >> +    class_unregister(&bch_chardev_class); >>       if (bch_chardev_major > 0) >>           unregister_chrdev(bch_chardev_major, "bcachefs"); >>   } >>   int __init bch2_chardev_init(void) >>   { >> +    int ret; >> + >>       bch_chardev_major = register_chrdev(0, "bcachefs-ctl", >> &bch_chardev_fops); >>       if (bch_chardev_major < 0) >>           return bch_chardev_major; >> -    bch_chardev_class = class_create("bcachefs"); >> -    if (IS_ERR(bch_chardev_class)) >> -        return PTR_ERR(bch_chardev_class); >> +    ret = class_register(&bch_chardev_class); >> +    if (ret) >> +        goto major_out; >> -    bch_chardev = device_create(bch_chardev_class, NULL, >> +    bch_chardev = device_create(&bch_chardev_class, NULL, >>                       MKDEV(bch_chardev_major, U8_MAX), >>                       NULL, "bcachefs-ctl"); >> -    if (IS_ERR(bch_chardev)) >> -        return PTR_ERR(bch_chardev); >> +    if (IS_ERR(bch_chardev)) { >> +        ret = PTR_ERR(bch_chardev); >> +        goto class_out; >> +    } >>       return 0; >> + >> +class_out: >> +    class_unregister(&bch_chardev_class); >> +major_out: >> +    unregister_chrdev(bch_chardev_major, "bcachefs-ctl"); >> +    return ret; >>   } >>   #endif /* NO_BCACHEFS_CHARDEV */ >> >> --- >> base-commit: 90d35da658da8cff0d4ecbb5113f5fac9d00eb72 >> change-id: 20240305-bcachefs-27a4bb8b9f4f >> >> Best regards, > This is a useful patch, and also works on latest code. Maybe we almost forgot it. Reviewed-by: Hongbo Li