Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp187199lqn; Thu, 11 Apr 2024 19:44:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2uQ53UbcAici07AeG4MqJWKOb4Uys6fMdW8Ms9vwsPxp9iHc89hdyBHrq7iQfVI0hIzcfnJMyJdFeFDNB5B2b4tVvJ9Xek6ebPtu/nw== X-Google-Smtp-Source: AGHT+IETYVewHvfneFG6iP9V8gn/dSaGMufVS1okWhEdOmTpk81kvoqn3loSplCJSlOORtwbIfXb X-Received: by 2002:a05:622a:164e:b0:434:767f:2999 with SMTP id y14-20020a05622a164e00b00434767f2999mr1564722qtj.33.1712889895746; Thu, 11 Apr 2024 19:44:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712889895; cv=pass; d=google.com; s=arc-20160816; b=sZ7pWFIdXsoP+ZQYqAbbsm+m1nSENOaVwfLlut/IsIvdXmauDDlxhC4+OL7M726jMs wLi0/Fdoy4pHD6vfQ/nl1fP7VFE6ELxAkhFbdV69Ijpt7QHWQe6rebhtg9SNBrkL0vdP 6esuC7ur5AeR6Z5jTzfPkanfVHCJnK1tbh7Hy4UtV252KkIQhNw2wjg3sLSw2VpBTDzO juJhvbhUEudESaNSmr5RWtu/CV4OYAbEtXWnWEiwEh7khs4Ls3VVzB/Z7YlPTTlMh6e7 O69TX/Y7ngIsDOI8oEFAMS0PxnpAxGPqKWQIdUqF1NqEQYfXhMF5Lm3SeUskQVCXEJ7A hHtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=I79hH/MqceyrY7sxro/GgYJP7b4PlTecMBGnWtJf/kE=; fh=02/uCX/ehv07EpL1MkMUSXNqI6A7hcoIMQv9/G/UqUk=; b=lxfdb4AzfOoX+im3fir4s0Je4mwUItbIgDcyM234H9ksnVI/UJSYHU+SD9o3cDdh+E VkUpbailp5zbb5n5SHsEWQg7XfQyIBqnbDoPpTLXdxrsMkL2+hZxwWCyMGfBcCuBWXn+ y53Kgic+PQ6MHXNsKk9Hj2+/FHUzPJc/HA7H9AMPqZfu6UTTDHLbnprE8ixLJQna8aUz BNfcvDMh1gyU/n3+6tFnr1cCidjnsOfB9z5orYqiMVktBgLzI2S3UsJugrtErq4FQ0r+ M9XyFn3D1r8sCngYTf6cXa/Yz8+dXd515kKMZDfVDYd6JGvYhTkiGxkPhK0g+45pNFFg Ffvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QOwbCjmt; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-141819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141819-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a21-20020a05622a02d500b004343f236d85si2833813qtx.702.2024.04.11.19.44.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 19:44:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QOwbCjmt; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-141819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141819-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 795C81C220B6 for ; Fri, 12 Apr 2024 02:44:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C6EC11185; Fri, 12 Apr 2024 02:44:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QOwbCjmt" Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 39E7917F5 for ; Fri, 12 Apr 2024 02:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712889888; cv=none; b=F/aCzDYVG1xXFYygJ8e/KU8xD7O84lQS+TI1nwvJbDtZSQQgwhA2smNRu1RIWlLrRf4McNQvjTRMXoPHROylmHbO7s8wNj2oekHSWIbjPJ7VWeVSJGMRAOERwvXgs9uDRaAieHPxKm5XR8Y3WEHHbOqhSGoqXhX09FceCEKOhJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712889888; c=relaxed/simple; bh=d8TMlfpqfj0EJkk4co1gVGQPXhL+ttMpGKUpO6Ej/tw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oNbL81efktZXVdkN2BrrgY0DsmNuD3EeSXV4ZGxaHMBtEPN/C58du1JxqBv3TOk4MQffZR+yu9T6DF5Gp7WEkXIuiDmNI3gZyLBA2wokjhDuv3P/512eOhHLv97ZdaMy1VRB/+lXLT1WzR3MTzdoaSutjMz3XvqfKtAkduc4Jd4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QOwbCjmt; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Thu, 11 Apr 2024 22:44:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1712889884; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I79hH/MqceyrY7sxro/GgYJP7b4PlTecMBGnWtJf/kE=; b=QOwbCjmtAEE42sRxAb7b4AOsULuYL9eaT/ENTW68O2WWOHkwIByai13wmNjulZDpk5VlT1 0lj9Lx96lHfqscUXt+BmOsp7OqM5uuz9N670Zr5su0INS0k36HpSg3jSSaGzx32sJAidS8 cZ9xhmBRsbwCenfTJ97RuZqjlEbytwQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: "Ricardo B. Marliere" Cc: Brian Foster , linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org, Hongbo Li , Greg Kroah-Hartman Subject: Re: [PATCH v2] bcachefs: chardev: make bch_chardev_class constant Message-ID: References: <20240308-bcachefs-v2-1-3e84c845055e@marliere.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240308-bcachefs-v2-1-3e84c845055e@marliere.net> X-Migadu-Flow: FLOW_OUT On Fri, Mar 08, 2024 at 09:12:47AM -0300, 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 Thanks, applied > --- > 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, > -- > Ricardo B. Marliere >