From patchwork Tue Jun 20 14:37:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 110546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3723265vqr; Tue, 20 Jun 2023 07:54:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Jyfz1rG+aoZNOVDrDpQklo1IBjOXGOIc0ns/pny6UQdkBUajw0iqMN9Vjf78bg0Prx3DZ X-Received: by 2002:a05:6358:9d8b:b0:130:df9d:3477 with SMTP id d11-20020a0563589d8b00b00130df9d3477mr3458496rwo.13.1687272881694; Tue, 20 Jun 2023 07:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687272881; cv=none; d=google.com; s=arc-20160816; b=ZCSybMsbj8kKPJZx80mvuhhZ4jM6KfdaQQyY4WJp9JPFaKPEHiv2Ztyg549Krr0Mas XV2dY8KipzujIs4BKnzmQDXX0IvxBW64rqjMKmCiYwNa0813sGtxjiSrwg8C4+iKZNHW IZTfiZ4d4o+DcC16V1oWZVYN4o+QLnc5BYrTiveeBwX+ROU2cWkpyfGeqe8QZ2ZiTuHx oJfYjJWhmeOG9nC9QFvngw3SQXvzXUz6Mi7eTr1sWL15ZGTXplYIdTNjU0eE4QYOdmBi h7gtm04O/jGK+lMzSetm8N3ekQtt3npIA4Jw6G4rwqhcvUN7Jx8ovE8R9LahvL6zyxjP O2QA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t69-20020a638148000000b00553b512d1f0si1822450pgd.433.2023.06.20.07.54.28; Tue, 20 Jun 2023 07:54:41 -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 S233395AbjFTOi3 (ORCPT + 99 others); Tue, 20 Jun 2023 10:38:29 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769233848732580858?= X-GMAIL-MSGID: =?utf-8?q?1769233848732580858?= 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);