From patchwork Tue Jun 20 14:37:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 110537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3716400vqr; Tue, 20 Jun 2023 07:44:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CozATQSOE1cW1x8WgEB5nzfkecIk7u6IygYzROW9BfSmPK7iCNC7d1h96xVN+umQiT77M X-Received: by 2002:a05:6a20:8f06:b0:122:a808:dbbe with SMTP id b6-20020a056a208f0600b00122a808dbbemr1966372pzk.29.1687272248985; Tue, 20 Jun 2023 07:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687272248; cv=none; d=google.com; s=arc-20160816; b=hD7CwhAN5jyi1xP7aul8bc0+LPRs3+jSW8+tAa6ku0cqJ/q9lpIQGfqq5dcUQZOCcv gxB8PGlIwqOEHMEVA+t1RBZrE6YClOUgsCt13/m9i2Yr49hEdRI7M+qgny5pDue5pDvf sF8h9+KyAbXM+UL5y8YGcZMiKBDx4TOBGJwEyNbKvmpgOGZOMkw9lAL/t1rDV9XC9hFz Fu0KkaIuX8f8fh7Ck0u1ZvjBJ4PKjwUDd8WmoHgolgCHWQAmgHKW5Zpyg5RGzek04ZnS q0MIZfztnhzAs6QiC5mMc1EAUoAS6gQuB4LSLiVJdy2A4xMSkIiOk1NPbkPuAf5kPv7k DQ3g== 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=CYSkr5mnGvf13VDlMz1tr4N1uKAmkmlvou8f97lm168=; b=eYKz46HzPNil/N74kcC4HPYdS/P1F7q2JUi+o1bmJOd7LDiPnti45czRK0ubI6hr2+ NZcv1cMjs8wlRzu3a0yL5NBxgW5lzJmC9KsDKNgZeH2LsdbtqkOCBpwyaxyN90QckjU7 nYHva1cm08KHYqZDTSwn0cXxVpAO8qRcj/Ub8P6NV7NLtRIYAEM+Msm4rMSxKCarzSPq bCnX2XJ/IQ1nEL0Pc4yxwSmrnKOQmHCcRg0afx3RH4Og0FVpUWS2uLiecYnjXaZeMoFO P8EuKl+BA6CilrevRjSUy1ZMA1qhekScVfLlJPASWZ94ti8HTFhNvFdvV80OP1Q8jzdv qa7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zHbhCU7a; 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 a24-20020aa794b8000000b0066881cb1b2fsi1761708pfl.346.2023.06.20.07.43.56; Tue, 20 Jun 2023 07:44:08 -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=zHbhCU7a; 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 S232941AbjFTOiM (ORCPT + 99 others); Tue, 20 Jun 2023 10:38:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbjFTOiG (ORCPT ); Tue, 20 Jun 2023 10:38:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1368C1709 for ; Tue, 20 Jun 2023 07:38:05 -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 9CD6A6127D for ; Tue, 20 Jun 2023 14:38:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AED7EC433C8; Tue, 20 Jun 2023 14:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687271884; bh=aL+zPU+4ql5HlCKxKr8ENZd/vHFVLtnUtN7tBrGgRrc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zHbhCU7a8ubHXxx2tXw676Qo8kSg0qM21ETCGWViK7U/G1YrVzaNBaAt6zkhBhwI6 VeA4gqzq5gxQO60/AoZWnYcp2/QcBpbZlim5i1/tVVYE2YlOfdcAJXpFwdNelhw7Th amGQth1g1gGTNis66+yJcveIYVfPSGpGNjDZu7tc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Ivan Orlov , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH 3/9] char: lp: make lp_class a static const structure Date: Tue, 20 Jun 2023 16:37:54 +0200 Message-ID: <20230620143751.578239-12-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=2420; i=gregkh@linuxfoundation.org; h=from:subject; bh=d1GSl0pDYIsh4omT1MKF3Zrqgoaggl/D/FsxIzUumgQ=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTd+7fYH1le9033YBEy3vNh9Kqt7kKNRakvX6vWfJuv 8qs51XVHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRxQoM88ssC1fOmvLPe8aR dP9+a1nuXC+X7QwLmlb7Z6XMmXXaioXfke3DzwUi7x1fAgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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?1769233185924631221?= X-GMAIL-MSGID: =?utf-8?q?1769233185924631221?= From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, move the lp_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/lp.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/char/lp.c b/drivers/char/lp.c index 70cfc5140c2c..2f171d14b9b5 100644 --- a/drivers/char/lp.c +++ b/drivers/char/lp.c @@ -145,7 +145,9 @@ static struct lp_struct lp_table[LP_NO]; static int port_num[LP_NO]; static unsigned int lp_count = 0; -static struct class *lp_class; +static const struct class lp_class = { + .name = "printer", +}; #ifdef CONFIG_LP_CONSOLE static struct parport *console_registered; @@ -932,7 +934,7 @@ static int lp_register(int nr, struct parport *port) if (reset) lp_reset(nr); - device_create(lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL, + device_create(&lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL, "lp%d", nr); printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name, @@ -1004,7 +1006,7 @@ static void lp_detach(struct parport *port) if (port_num[n] == port->number) { port_num[n] = -1; lp_count--; - device_destroy(lp_class, MKDEV(LP_MAJOR, n)); + device_destroy(&lp_class, MKDEV(LP_MAJOR, n)); parport_unregister_device(lp_table[n].dev); } } @@ -1049,11 +1051,9 @@ static int __init lp_init(void) return -EIO; } - lp_class = class_create("printer"); - if (IS_ERR(lp_class)) { - err = PTR_ERR(lp_class); + err = class_register(&lp_class); + if (err) goto out_reg; - } if (parport_register_driver(&lp_driver)) { printk(KERN_ERR "lp: unable to register with parport\n"); @@ -1072,7 +1072,7 @@ static int __init lp_init(void) return 0; out_class: - class_destroy(lp_class); + class_unregister(&lp_class); out_reg: unregister_chrdev(LP_MAJOR, "lp"); return err; @@ -1115,7 +1115,7 @@ static void lp_cleanup_module(void) #endif unregister_chrdev(LP_MAJOR, "lp"); - class_destroy(lp_class); + class_unregister(&lp_class); } __setup("lp=", lp_setup);