Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp281388lqc; Thu, 7 Mar 2024 18:18:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUn8XwBAzRyx1VSiwAkyola5/1oNDA/jlle7MfSh81MzUVeXF3hNu/AykxvN6IOolXxkqne1OIfkjBkjK1Dui1vurkyx9XD0llsRqdxDA== X-Google-Smtp-Source: AGHT+IHRwZr0FSALsyNhqmsYm4DHcAVZWryksadrhN1ZLOC78x5IuUWtG1cgO/PIL9RtAUYfqI/R X-Received: by 2002:a17:902:c951:b0:1dc:673:1932 with SMTP id i17-20020a170902c95100b001dc06731932mr12585032pla.38.1709864338148; Thu, 07 Mar 2024 18:18:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709864338; cv=pass; d=google.com; s=arc-20160816; b=pZCsj0GCsH1iXLdeTNCRAktUQZTObmqfWcb0VCSpuud+fAmWT530p3cYkt5Pw5c41B TYoEu5fM62BvEkewC0yKdYeLEu5V4rYW3Hj79T1CNQwLIyCBszEK8+UPW2fJhIb1YmK5 0RDnFguw9FOeEUsbjVBUQOO9b0LMboNxeke0tUnRITM8YHZYP9dszzTDNEhIlQNpwYiU bx1c1nwwxHvNVj8ZKRB1xaV/FWi937cajGTzBjCpe2cmOC1EaVUPc094LN7wzM9PsmXF tuKnAOtWxrnQ21PB6H4Z5OArEblvgDiTqwEPNGfMtZpg5he/Uh+oJLjFqHt33uN7ur8w pN+A== 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=tLxjIs8f/lnLvJoE5R+baInSbYa4ox3iynZ8gnuCrEc=; fh=apthUW3NzSVwQ+UZUiEGwcSzoS/LWb6iQjw8CySdCi0=; b=rtvfkxNPn+yBpoVGAxdFP+TDOY66oZSHRgECFESYEcmWDGDmbXmv2t3RehyGLuY2Yk JBqcD8Dy0Zh694IwvLfRpBa3kHacRRSbeS/CTpr89eIsYLP7Q8Nr87iVsyv/0AKhyeYA v/c9sUnBdWWTTGBDM5bQA8iLWUguwvNQDJ5y0Tcv3+R8xVLL5kDcvO/vTfiUJHj/Lqki p3Wn5kncKhzOiZ5CoF4B9iy/45+AdUrH4sqRxr8vLUoL7m2J+6YZ8UGl4C9umyh+5iXo hrl8PIPh1RUnbZ2SngD+8bribZmwI9dyFADhIAw1aRPiUGNLKAfJV4yJUHSxvv2IZAsO UVVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xwaUisIj; 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-96445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o8-20020a170902778800b001d893990719si14829431pll.359.2024.03.07.18.18.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 18:18:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xwaUisIj; 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-96445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96445-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BA16128362E for ; Fri, 8 Mar 2024 02:18:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E842241E4; Fri, 8 Mar 2024 02:18:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xwaUisIj" Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (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 3D54C1D546 for ; Fri, 8 Mar 2024 02:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709864326; cv=none; b=YyEHAMW8yDm9ekVuQstIOdVgC4zpE4vCGQfGEVusdGOeB9fw4oy/AEqi1EFuIf/jGwltuuciCqcz2OCWfEAIuT73tyxdvrqDy40qDHN9hfCHiElhf8cZiVKXunMH81bAeLJ4NeVRVuIZpmkmOTuZeOn4yKLKSy/B75ED9JLHeoI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709864326; c=relaxed/simple; bh=nEwH4yfP4vqXQbZOO7lJhENGHFgNWar4jxiwuKlg7Us=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IN3j0SFGA5wOfuQ08+2Xc7Y8Ei8avbXW2rCFuxK+fZPPDFyOHTq1jcTezld+GoeimEfYPelxkZ9VHUcPUVUIlcvQp3lPgslEWnlpjlrz2uT3FoTTI6TujwVf00IgJMLozwYtkLgr034k3tpS0TYxmHKsFfDCqfYiGHXRSnjDzFA= 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=xwaUisIj; arc=none smtp.client-ip=95.215.58.174 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, 7 Mar 2024 21:18:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1709864322; 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=tLxjIs8f/lnLvJoE5R+baInSbYa4ox3iynZ8gnuCrEc=; b=xwaUisIjy/cj/mNY5MLxtwBhEG+kOE1pjEA/ITKL9zJkd1mSJn+xQYI5JqbQOfa4gbNHgn 1ksclDjfKdRKb4o4L2cZk0h7fCDoXvtJYCe2Q6N4X5LJLmeqpMHYaoiJ405iBpFwbD4lfD 9N8Kgm9ey0EY6ip0U8RY72DRjLzPCAw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: "Ricardo B. Marliere" Cc: Hongbo Li , Brian Foster , linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH] bcachefs: chardev: make bch_chardev_class constant Message-ID: <5odqpww3sjv6ffj3hpmhx25q4fdacstfr5qn7seb3mwrclynpi@drhj7xa2cfyj> References: <20240305-bcachefs-v1-1-436196e25729@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: X-Migadu-Flow: FLOW_OUT On Wed, Mar 06, 2024 at 08:50:04AM -0300, Ricardo B. Marliere wrote: > On 6 Mar 09:23, Hongbo Li wrote: > > On 2024/3/6 4:21, 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. > > > > > > Cc: Greg Kroah-Hartman > > > Suggested-by: Greg Kroah-Hartman > > > Signed-off-by: Ricardo B. Marliere > > > --- > > > fs/bcachefs/chardev.c | 23 ++++++++++++----------- > > > 1 file changed, 12 insertions(+), 11 deletions(-) > > > > > > diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c > > > index 226b39c17667..af587453fd3d 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,26 +970,25 @@ 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) > > Here, I think you should call class_unregister to relase resource which > > allocated before. And the same thing shoud be done in other exception exit. > > Hi Hongbo, > > Thank you for the feedback. Did you mean that bch_chardev_major should > be unregistered if the class_register() call fails? Because if it does, > there is no need to call class_unregister(). Hongbo is correct, if bch2_chardev_init() fails it needs to clean up anything it did. > > > > + return ret; > > > > > > - 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)) > > like here.. > > Can you please elaborate? > > Best regards, > - Ricardo. > > > > > > > > --- > > > base-commit: 90d35da658da8cff0d4ecbb5113f5fac9d00eb72 > > > change-id: 20240305-bcachefs-27a4bb8b9f4f > > > > > > Best regards,