Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7917178rwd; Tue, 20 Jun 2023 07:54:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7EmHFb80MfGr0u1h9v4P/Ll+e5T7uPJuT4fuSch7LC1sXksE19JDcmQRRW54xDRXIQJyMM X-Received: by 2002:a92:dc03:0:b0:341:e2aa:354d with SMTP id t3-20020a92dc03000000b00341e2aa354dmr8635673iln.12.1687272861000; Tue, 20 Jun 2023 07:54:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687272860; cv=none; d=google.com; s=arc-20160816; b=Lr0zh7UI8JJ/uuGCliyEMO8gY7l/ZiUKV41zlhHAwrXMQHqa8QYcqwTmQBhOhI85/q BE2/LmyTz7fKEyUpzJXHWrr7Yy+3Ppyw2Q4Chvdtd3KQvPOtomBICpBekdyhC75S3xvF LWv6AGc20huf0+bWL8mAollrFB5m6ycNviIIkR6JOMgLtm3sjslNnsZJp6qVRgpnHI5k FbR9/pt7qIxAsyA6rbk9EVUxYP2GzQBrX4nJOSTOmzBR59gqTDP33amTckC72jMobygA OOTznCz+3892e4cgvyhxt9DVmXVuxMcS9Ly0VqlcehzW2Npsul1MxM33CAraQuwb2AYe u0YQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kvE3ob7XmcUp5Pyl2ZWg1NQtfTwMV0y7VDyyLGGhAe0=; b=rEnHIgGaO9sRf9peofiV9op7sHD58HTySMi5JBbVdUOC71382QCLQTMcRnkPrIUc1w ZTfFKhJoK2F0S3lVDnyXJ5XkLP5AnSGocMvAwDneJcFFWY4vZzJQ9hXh968LuRRJc5lM K6IFPc0keCre20rYkybYvNctHcuWJcDyPGAbaaOIyFicbBnUZU8SU1GjKVFUBFPrvxfI cH7iYKBo51C30eI2Vlcc1ZSnXwBsagpUI23VAShLJro+G5sYGPKARVqOjKlSPqaMCgzK JtMRtVjt2k1rGDXxdu87YmZaNRfhJVB5GN/VOkvh4Upog67dwBVK9lnlZfvdfRH3+aBb iHCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Tst5jiLN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id az9-20020a056a02004900b00540102a876csi1981250pgb.73.2023.06.20.07.54.06; Tue, 20 Jun 2023 07:54:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Tst5jiLN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233362AbjFTOi2 (ORCPT + 99 others); Tue, 20 Jun 2023 10:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233341AbjFTOiO (ORCPT ); Tue, 20 Jun 2023 10:38:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7865173D for ; Tue, 20 Jun 2023 07:38:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4008F612B3 for ; Tue, 20 Jun 2023 14:38:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E2A2C433C8; Tue, 20 Jun 2023 14:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687271889; bh=FaRHF/PB6BaxjUrk6iOOUUMOLqCwhxs44CVBkR4qXXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tst5jiLN6vj8fr8QPDWxGEklptuv3PDZpGxPZWiZxTJV69xLVRRxXjAdaTyXjwrfF Fuky1vpBLLPI1Qgp2BkXaSX1BMjyaJnFFA30S5vIVDHTGpjz5BxHZaFJ5CXgpjbXos bcrhRndB8TbQjBTY80OBbnfn4H/7ESf/wjxrM+TI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Ivan Orlov , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH 5/9] char: misc: make misc_class a static const structure Date: Tue, 20 Jun 2023 16:37:56 +0200 Message-ID: <20230620143751.578239-14-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620143751.578239-10-gregkh@linuxfoundation.org> References: <20230620143751.578239-10-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2970; i=gregkh@linuxfoundation.org; h=from:subject; bh=Wq5JfVJAtqzIAMM6fxfToBhPJeNVfiJOSPUBrqoxF3Q=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTdx5448erO6+BjTVJwSjiq+1Ghr6Npd6bddPZRJ9Nu zWZdadtRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEwkWJNhfggbr8rlwOPqE1dU tLfuuSO4bc255QwLpn5bX+G+w2L+4WyvW/GJMVv1PJnsAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, move the misc_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at load time. Cc: Arnd Bergmann Suggested-by: Greg Kroah-Hartman Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- drivers/char/misc.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 1c44c29a666e..541edc26ec89 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -168,7 +168,21 @@ static int misc_open(struct inode *inode, struct file *file) return err; } -static struct class *misc_class; +static char *misc_devnode(const struct device *dev, umode_t *mode) +{ + const struct miscdevice *c = dev_get_drvdata(dev); + + if (mode && c->mode) + *mode = c->mode; + if (c->nodename) + return kstrdup(c->nodename, GFP_KERNEL); + return NULL; +} + +static const struct class misc_class = { + .name = "misc", + .devnode = misc_devnode, +}; static const struct file_operations misc_fops = { .owner = THIS_MODULE, @@ -226,7 +240,7 @@ int misc_register(struct miscdevice *misc) dev = MKDEV(MISC_MAJOR, misc->minor); misc->this_device = - device_create_with_groups(misc_class, misc->parent, dev, + device_create_with_groups(&misc_class, misc->parent, dev, misc, misc->groups, "%s", misc->name); if (IS_ERR(misc->this_device)) { if (is_dynamic) { @@ -263,43 +277,30 @@ void misc_deregister(struct miscdevice *misc) mutex_lock(&misc_mtx); list_del(&misc->list); - device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); + device_destroy(&misc_class, MKDEV(MISC_MAJOR, misc->minor)); misc_minor_free(misc->minor); mutex_unlock(&misc_mtx); } EXPORT_SYMBOL(misc_deregister); -static char *misc_devnode(const struct device *dev, umode_t *mode) -{ - const struct miscdevice *c = dev_get_drvdata(dev); - - if (mode && c->mode) - *mode = c->mode; - if (c->nodename) - return kstrdup(c->nodename, GFP_KERNEL); - return NULL; -} - static int __init misc_init(void) { int err; struct proc_dir_entry *ret; ret = proc_create_seq("misc", 0, NULL, &misc_seq_ops); - misc_class = class_create("misc"); - err = PTR_ERR(misc_class); - if (IS_ERR(misc_class)) + err = class_register(&misc_class); + if (err) goto fail_remove; err = -EIO; if (register_chrdev(MISC_MAJOR, "misc", &misc_fops)) goto fail_printk; - misc_class->devnode = misc_devnode; return 0; fail_printk: pr_err("unable to get major %d for misc devices\n", MISC_MAJOR); - class_destroy(misc_class); + class_unregister(&misc_class); fail_remove: if (ret) remove_proc_entry("misc", NULL); -- 2.41.0