From patchwork Tue Jun 20 14:37:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 110545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3723049vqr; Tue, 20 Jun 2023 07:54:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OI5nCBgtZ3JfptSgZqD0ijooo4sbG3n9AxmhLOWVp5QosdfkHewGcCvZal9fzlHUq4uXe X-Received: by 2002:a17:902:f68a:b0:1b3:bd50:97dd with SMTP id l10-20020a170902f68a00b001b3bd5097ddmr3362105plg.18.1687272860638; Tue, 20 Jun 2023 07:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687272860; cv=none; d=google.com; s=arc-20160816; b=zdKRM4YTGQlga/gtCcngXRC+IgycXXVTtZTLhb+hGIiBZaIbWw3O/gp7DDKBMMmnTq 0/TjnpPYA5TkXvck1WX9LZWdGtYFXnsh0+NSHQoR2V0TsY7jlmM+8pIbGC7g8qtm3faA 64NjHaQKttIFAvBES7aUQJ9G8AVMXy/91ndBt+/gVUBZ2RPq5OhiW91BVTI1shjMYbCV HW9b3N3/WVsbwXDq25TzhwIdf0oaGp6teodpFxDfuWgGdfoOgPkCY7XmOHxZtwP053Rb CXdQF30JVV+hsyFRtZGWIM8s15ohhNEdteqtYPtr7oEjRn45RJMrophJtqa6QFhXsLJ/ eYdg== 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=CYWT2xojrZc2r8MX8/kJmr9WIxQd5Q0QJ9miCVRqLAM=; b=XOsWhduR4SbTPKFMCNAfncy/vwaekO/D0oI4szBrJuZ/rhvh4tN48bKAaAUrv3Y24U phi0Mc33REktkCqDdpFoQvs2zZxjRb4C3ISnV3H4i7+azpHhqSlKgbc9+irjhlL2PrXn wSM6oPmxOX3mWKl8AoIIEln9bfSielxikD9yp/U+LtrkdWN5do/D9ziZzuqM2NWbBcXD HJwCxzvXhcEyRUfX8p3L8KVWmijWPgHau+fNXWrvOfsORjDzpIQA92QluhuZAXHxP8kI ROCUTHvYimDFnb7Hc5Ou1doiyDHgkvsZAt9EW3jL/sp820Y0A6eG9IZsGaQXA5xgMJb5 at0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZZ41ux87; 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 m11-20020a170902f20b00b001ab2a0e3163si1944488plc.598.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=ZZ41ux87; 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 S233360AbjFTOiQ (ORCPT + 99 others); Tue, 20 Jun 2023 10:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233344AbjFTOiN (ORCPT ); Tue, 20 Jun 2023 10:38:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6576170F for ; Tue, 20 Jun 2023 07:38:07 -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 6637A6124C for ; Tue, 20 Jun 2023 14:38:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78BE0C433C0; Tue, 20 Jun 2023 14:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687271886; bh=NNeBnpMh0VKltZp3X6U483e9x1db0PB3xLQaZRMH63g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZZ41ux87hcYbKBEoQJRWGlh09O0QJ9Tv7sYNj/GDVwttzaawLeyUFHk3MpHDVLzwi AkazbBqxfDcb4h/Qel30sUKnpfroQk/wknIyjH+lH9yyFJ1O4Tt6aBvmkDF71H2mqv ch65RmdQLcI6SqqxVRgHLRqifdWTmaISOJGx9+Fs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Ivan Orlov , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH 4/9] /dev/mem: make mem_class a static const structure Date: Tue, 20 Jun 2023 16:37:55 +0200 Message-ID: <20230620143751.578239-13-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=1765; i=gregkh@linuxfoundation.org; h=from:subject; bh=m32deV9O3pdxzflG4VVrQWKJ6v1wRrZW/H2pWLSYWM4=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTd+5/cGnfjBVPg9PezJxQW2L9JDywsy32zR+vBoG/w SfV7VkXd8SyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEtqUzLFjp8/2bc5/xP8UL egrz0i/P0VfcKsowT7fsqwlTact081mskY8sOaUYNvAKAwA= 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?1769233826828421371?= X-GMAIL-MSGID: =?utf-8?q?1769233826828421371?= From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, move the mem_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/mem.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/char/mem.c b/drivers/char/mem.c index f494d31f2b98..2f944522f18f 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -753,20 +753,23 @@ static char *mem_devnode(const struct device *dev, umode_t *mode) return NULL; } -static struct class *mem_class; +static const struct class mem_class = { + .name = "mem", + .devnode = mem_devnode, +}; static int __init chr_dev_init(void) { + int retval; int minor; if (register_chrdev(MEM_MAJOR, "mem", &memory_fops)) printk("unable to get major %d for memory devs\n", MEM_MAJOR); - mem_class = class_create("mem"); - if (IS_ERR(mem_class)) - return PTR_ERR(mem_class); + retval = class_register(&mem_class); + if (retval) + return retval; - mem_class->devnode = mem_devnode; for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) { if (!devlist[minor].name) continue; @@ -777,7 +780,7 @@ static int __init chr_dev_init(void) if ((minor == DEVPORT_MINOR) && !arch_has_dev_port()) continue; - device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor), + device_create(&mem_class, NULL, MKDEV(MEM_MAJOR, minor), NULL, devlist[minor].name); }