Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp505217lqc; Fri, 8 Mar 2024 04:16:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVGqOfuf9A7zxPjI7dlPDHjtOBCXY8sXLL1Ai3AHDDQO56FpFsyBUip3Zzz1JJPwrR80rmPArSqSnb6fs+ktKIjxD5ieQ3ywepahcEz6Q== X-Google-Smtp-Source: AGHT+IFDfIPyEgfkHquGMO1K1bL+IDNNnOWR3XXydbHBpz5BvWcYq9eMptJUDpicC00HnFofFNCL X-Received: by 2002:a17:90a:d313:b0:29b:be4a:cb7 with SMTP id p19-20020a17090ad31300b0029bbe4a0cb7mr93043pju.14.1709900202590; Fri, 08 Mar 2024 04:16:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709900202; cv=pass; d=google.com; s=arc-20160816; b=nGbYqQeQ+i3F42ZrTKZtHWEYgAVsHPViHjcgclGKIp/Fftgo+B5hyUqbHklchejg8M 49rWONCIP5hJq6HVHfxiIlDce6mkX3QQxyZaLSBeKjnWiCVrCGmKhtxwT7IxVAIVknpP NEYKfs8cwB+cv1ylEkCNAObYWjt3Kn6My2eClf+r7hs0Ejg+jAq4pOsxav3XuOkzxU6l 2RrhIePKDka5W5rKe7aIA8kJ9MBG5hCt+utMk6m6Ldf9t2TfTtch9D60NYe6k9ErK+lz TKsUKOCQkNk3Cu+Y7PulTGCQktDIb+Oe7jn+Y40WFWl4BaskFLBWu+lSYVHHKKW+iBwE 5ZXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :dkim-signature:from; bh=6o7+NY2dQ7MkSysTTxlBFTXs4hpEZRChFXdmrSC3bNU=; fh=fBI8jB25gnkrJ20bnJo9FgsKRGiRw14l1LXQiR2J5b0=; b=WLAs/y03TisGioeb4f3LyK5e2kTFNTItEKI9PNDuiIFQCAG+fEIb9R0Tluq0L37GNj JxbeBhZCqaPTH6GnuUrKEhuwY48VqVPgIx44gzCdu6IRul3/uPTkXsbehbj1VA9uip6P 3hDp2ZSlOcc7PraBsxLdafDSEDBDPvy43gpie6K4iP2B65xyM87WSZuzub+5fLGAE0Of M12gBjbq9uK0hiOYL6X6rgf5x9G5oU2RuocH7sIYWHY2rxu1ZAmV1bYlnBaqJU3iQ+DZ ZH8jKTX18Nk7gXYhPTq7027W8s9oMpUh1+dHLRqaLr3KfXIdMq34pA336PcVpOyT5wzP LkKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@marliere.net header.s=2024 header.b=J64+HuIP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=marliere.net dmarc=pass fromdomain=marliere.net); spf=pass (google.com: domain of linux-kernel+bounces-96985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=marliere.net Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x8-20020a17090a46c800b0029ba20feef7si2271048pjg.188.2024.03.08.04.16.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 04:16:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@marliere.net header.s=2024 header.b=J64+HuIP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=marliere.net dmarc=pass fromdomain=marliere.net); spf=pass (google.com: domain of linux-kernel+bounces-96985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=marliere.net 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9795FB224F9 for ; Fri, 8 Mar 2024 12:13:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6121A56768; Fri, 8 Mar 2024 12:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marliere.net header.i=@marliere.net header.b="J64+HuIP" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 474C055E57; Fri, 8 Mar 2024 12:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709899978; cv=none; b=PsXoYMOthFQhtml6VBnuCdKu3ZMYEbsJg/9VZuo8kdZwqHn+CL43aZViejFdtOk3V3JFLqwSFlyiuy5r2wAWzbWxokyABIFOw1tIkeqBp4NkVOzNAOMtmCEYnBiYKoU5zzwEJ7minqv9kIA+zQF/n/kJl0XICqAfGyGGARmNufw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709899978; c=relaxed/simple; bh=K2sCIAlU6dXk5ratr4Vv5OEgr6af+7vpwMRF89XMaYU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=PF3a6vdqR9P1G20Pp/1D+SMR4s4rd7rPsUY4nOOeVjo3+nXOaCQL0gSn9WBqXBU4w6BNrSSlcPCImSc7tUd6w72p8K2QVs4WQ38zgZXP6OcrpQn+4ONaww3kKjGd223fKO/uMxXyin3rDYQnPSghlBHyskQC6wnZe0r5LOHKktE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=marliere.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=marliere.net header.i=@marliere.net header.b=J64+HuIP; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=marliere.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e655a12c81so1621944b3a.1; Fri, 08 Mar 2024 04:12:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709899975; x=1710504775; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:dkim-signature:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6o7+NY2dQ7MkSysTTxlBFTXs4hpEZRChFXdmrSC3bNU=; b=XGTDS6gKtqutu9iV5T3Ql5VzlrWjb7Arrk1nHLRidcxEgtcCtG5EL2mrYSHbLzu8on Chcl6a02N0mUtFD02kqfFUVho9d7h5k6IQD0/thzLrpNdPiT+SLm1+GlskJBPXLqFzA1 l5fasZoOidp0wviv1WKjR+lr5t68ycnYSSYOEO30u76/Nd8buncXQowZyibMVWADZSgX hymryPowxhi9kiqnJEE2Yxg/1Th9dmyMVlV19NjC/j43KrpxR/OYGIKa4KxtyMtYV4N7 OYelkwyNfrz7cJ0lC6a22PKA32jfUL+YV4JFQDpLwAaj1nXLtQEBiRklxJnwKcx9VB8I LAEg== X-Forwarded-Encrypted: i=1; AJvYcCVGUbSjmDvrZJ3ju6HwkzD4pFWqzuKKlh20FgJX7S1uJYrz5Cqe+4deUR47fbO06Wig3XuEkzL2MaPmq/mp0FHUF6JKPn7/ZQ6ZoudL X-Gm-Message-State: AOJu0YxnbVfXT62XAI3BhJ/vSysDeXjuQN4SkUuzilYPmzUBgjRmNiAZ P/Wr94CUooIKR7KfSjg2SdoZld09CwXTRhFcnff4nvvQazpmAd1I X-Received: by 2002:a17:902:e5c9:b0:1dc:c8b3:9376 with SMTP id u9-20020a170902e5c900b001dcc8b39376mr76845plf.7.1709899975314; Fri, 08 Mar 2024 04:12:55 -0800 (PST) Received: from mail.marliere.net ([24.199.118.162]) by smtp.gmail.com with ESMTPSA id y7-20020a17090322c700b001d9d4375149sm16094710plg.215.2024.03.08.04.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 04:12:54 -0800 (PST) From: "Ricardo B. Marliere" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marliere.net; s=2024; t=1709899973; 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: content-transfer-encoding:content-transfer-encoding; bh=6o7+NY2dQ7MkSysTTxlBFTXs4hpEZRChFXdmrSC3bNU=; b=J64+HuIPw1LXPn6yF1yJq5QwpYBGqgFFLdjInSVhKkoyn1Qe43pyQ+AVT/G3MBhSKjW5LK HOKpjaC8t4Hg/PBgS8EM0EGYDtzbYkVfjazuRBQizEI55Z1+w7q3ZCt3RGz5eLHoL8EJuX ZfVCcxHnMDbx/d/MBdHf9kqe++cMWMiFSdhRhkKQjqwKsEOxdse5qBjTqpg/1AWBWsPO+D KMuWJl9wXeT4N8k4LaGYidXFMhN8mW34c4Vzy5xIj3JR0+kbn0YIzY2hb5wAgy3eNu9yg7 Ush6EFdY/QlXc99/XD8weFvMHTZESYsH+m5cxsa62q6TkNEUuKckD7bM1WNZdA== Authentication-Results: ORIGINATING; auth=pass smtp.auth=ricardo@marliere.net smtp.mailfrom=ricardo@marliere.net Date: Fri, 08 Mar 2024 09:12:47 -0300 Subject: [PATCH v2] bcachefs: chardev: make bch_chardev_class constant 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240308-bcachefs-v2-1-3e84c845055e@marliere.net> X-B4-Tracking: v=1; b=H4sIAL4A62UC/23MQQ7CIBCF4as0sxYDlLbiynuYLgAHmUSpgYZoG u4udu3yf3n5NsiYCDOcuw0SFsq0xBby0IELJt6R0a01SC4V7/nArDMuoM9MTkZZe7LaKw/t/kr o6b1T17l1oLwu6bPLRfzWP0gRTDDVj0KPKIdJ6svTpAdhwmPEFeZa6xf0xh6jowAAAA== To: Kent Overstreet , Brian Foster Cc: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org, Hongbo Li , Greg Kroah-Hartman , "Ricardo B. Marliere" X-Developer-Signature: v=1; a=openpgp-sha256; l=3348; i=ricardo@marliere.net; h=from:subject:message-id; bh=K2sCIAlU6dXk5ratr4Vv5OEgr6af+7vpwMRF89XMaYU=; b=owEBbQKS/ZANAwAKAckLinxjhlimAcsmYgBl6wDBHcpFMUWrsbq8OZSINLnfyVLs1ZsmFSIOt X0eqOY8jkyJAjMEAAEKAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCZesAwQAKCRDJC4p8Y4ZY poZcEACrCm1DrTpffhSMz45nWyULhbZuxUB44yhj+rBzxvuC1bdxtZTZJZJs+PvI0oPDgX9Gqee 1AiHIlbk2zjKT4gZAUT+qNGBEOe8kpI/z1IZ7fgdXjMnU1bQnQZfkczQxkw+BMcLsEnd6e9b+1x o6EG02mGj+tjMcKTw40lUdzC7PPs5JH3Ai4nMRsXAZ+Mshbz4Ao4flVqEstTC4+OaRjN8P4LXOC 11Em7aSmlmKn05SktoRXdePNktwV3tzzFveOLBalpSF/mmzuCy7twRCBMVXZUKD7CAHNfkZQEyL iX1yKITREn3GeCdm8s9qK4diTskAFq0OCJJFughPaRn+wlYNb7BTMJFrE9X1m4GdM3PxtqH/15X G3biqC3KUINOtG4oE76Xuear3hlZyLyUt+30Z764J6X0ziJQFTb+2cnjDGFv8Ti7OwpkcaHzWcc PONZGw68NH/APdE+f7+abOJckuYCuoHFCmETs7ud4qxx2VAoub6yu0Gl+otbGUi9w8Td01mRKXp HPL201nmB7J5b9O96EhUJwr6qP0IltpLBUpqqH6VjF8t3WnCZltADX01mRu6Ye3gfD1iLNkk7Ne jeksoBsn2+RsvF+pf0pzXsKitEtMYrG/n+BBZtFirXw54Pwgi/7XZIfNUjd5n4bA7yzVQ+xLPgI NVX5XIxEP/Ri8VQ== X-Developer-Key: i=ricardo@marliere.net; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 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, -- Ricardo B. Marliere