From patchwork Sun Apr 2 17:58:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 78277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1856744vqo; Sun, 2 Apr 2023 11:02:42 -0700 (PDT) X-Google-Smtp-Source: AKy350ZLdM+YanLBe3+p7Wlp//5q21noeKbIRcWsBS1m8zcwy1NZjLT7NU5amvJWcWe40EgIzxup X-Received: by 2002:a62:5246:0:b0:628:87f:6b5d with SMTP id g67-20020a625246000000b00628087f6b5dmr29920304pfb.11.1680458562364; Sun, 02 Apr 2023 11:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680458562; cv=none; d=google.com; s=arc-20160816; b=GBOcDfTndL+mNFen8d1rmB6Ov1uNzwaeQoADT+iWouhWbuGc0Ky+3re3B9gLqicXi7 jEztUaWLfwY5IV+Hcwmt86wd1oXuusgbSnvuEjimN1jO+7N3wp626PqQFZe9vAY1mfoW dAZ+j8RKAvyQEYdMy3ohplgCsPuvxCYjGh8d8Thp4dzK6zU3rv/+Bh9lkN3KMuht285S 7t/feGoQdlSbldhjkpjjcIicOhJBiXvJaEab6wPD/6wusUbVp9+crN+0blS0n2kn9QLf A1T5W3EOV/+W8bwhpbS/UsYeCJitNQ+bRVYkgYv5CwRpwfbJhGd8ikiw2X0adqwOZRf5 oYXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:lines:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xwOtnQfApSMtfWMzNhEsTRVFvlOJW6mch2NVS3t6O54=; b=DgJXenkuHA7EnrxU4nPnt9YJEWk0GXvCsKsRn3SwnUc0ae8dxCUPC2x2EIUmsVCBIb WYPO7nz9H0XkOATnMgfG51lNKAo/8PiQYEk/afy6F5nSx/Wit1e3EzzwsU+CBfJdKagF vx/UAck+v0YjbhwlTeVlq1PEcnvBZhqguIum+tayA6DZbm2QKOYSSjbKf8IQsP7JZinK oZmvEz3eRNmgqwlKlb0/RfjIG2Kym9sH+7wKhwRY7PDNsGStne+NUcnyxW4oO3LSOHj+ xOuFNWTEaQjHngSpWpCj8vqG23p+VexwbtWa9zpoNr/sIqG2oCj/8LyEo5AD1syWI0JH oV2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="R1Utxy/t"; 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 i8-20020aa796e8000000b00623e3bcfbd2si6974761pfq.11.2023.04.02.11.02.30; Sun, 02 Apr 2023 11:02:42 -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="R1Utxy/t"; 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 S231203AbjDBR7F (ORCPT + 99 others); Sun, 2 Apr 2023 13:59:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjDBR7E (ORCPT ); Sun, 2 Apr 2023 13:59:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1EF54EFD for ; Sun, 2 Apr 2023 10:59:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 78B7C612D5 for ; Sun, 2 Apr 2023 17:59:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D01AC433EF; Sun, 2 Apr 2023 17:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680458341; bh=vIGPghN8n4UlZStHEt+zl72sd282xSKb+oj0ziHP0ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R1Utxy/tIZEnQB5zUl3huvAQDaSOzhk0AJxG0zfxjNSeBNcf/6st6aWIn8yhRsdsu UepwoX3LQBxn3bL7hY7eAsDIHRKgzELc1JBvTS7qmtmuz+qBkCqWeAkH0ZeeM8UdRK x/1G9jouRybWq3fkbXKKtUMaXRj+tNsvD4Aidmgw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman Subject: [PATCH 1/5] driver core: class: mark class_release() as taking a const * Date: Sun, 2 Apr 2023 19:58:46 +0200 Message-Id: <2023040248-outrage-obsolete-5a9a@gregkh> X-Mailer: git-send-email 2.40.0 In-Reply-To: <2023040244-duffel-pushpin-f738@gregkh> References: <2023040244-duffel-pushpin-f738@gregkh> MIME-Version: 1.0 Lines: 55 X-Developer-Signature: v=1; a=openpgp-sha256; l=2057; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=vIGPghN8n4UlZStHEt+zl72sd282xSKb+oj0ziHP0ss=; b=owGbwMvMwCRo6H6F97bub03G02pJDCmahyLktco4fL7xvLjB1FUSu/TuffcEvQ0tEm9W9LN8C 6zKnFbYEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABOZu4ZhwYxHG4q3+FZ8W6n8 02L6O7P9B+Zt8GdYsHN2/qKF+5zFP+/d2PFy0ezVrNZT7wIA X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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?1762088517158675056?= X-GMAIL-MSGID: =?utf-8?q?1762088517158675056?= The struct class callback, class_release(), is only called in 2 places, the pcmcia cardservices code, and in the class driver core code. Both places it is safe to mark the structure as a const *, to allow us to in the future mark all struct class usages as constant and move into read-only memory. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman Acked-by: Rafael J. Wysocki --- drivers/base/class.c | 2 +- drivers/pcmcia/cs.c | 2 +- include/linux/device/class.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/class.c b/drivers/base/class.c index 65502bd7d5c5..53fc7052340c 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -235,7 +235,7 @@ void class_unregister(const struct class *cls) } EXPORT_SYMBOL_GPL(class_unregister); -static void class_create_release(struct class *cls) +static void class_create_release(const struct class *cls) { pr_debug("%s called for %s\n", __func__, cls->name); kfree(cls); diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index e3224e49c43f..5658745c398f 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -824,7 +824,7 @@ static int pcmcia_socket_uevent(const struct device *dev, static struct completion pcmcia_unload; -static void pcmcia_release_socket_class(struct class *data) +static void pcmcia_release_socket_class(const struct class *data) { complete(&pcmcia_unload); } diff --git a/include/linux/device/class.h b/include/linux/device/class.h index 7e4a1a6329f4..f3c418fa129a 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -58,7 +58,7 @@ struct class { int (*dev_uevent)(const struct device *dev, struct kobj_uevent_env *env); char *(*devnode)(const struct device *dev, umode_t *mode); - void (*class_release)(struct class *class); + void (*class_release)(const struct class *class); void (*dev_release)(struct device *dev); int (*shutdown_pre)(struct device *dev); From patchwork Sun Apr 2 17:58:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 78278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1856781vqo; Sun, 2 Apr 2023 11:02:46 -0700 (PDT) X-Google-Smtp-Source: AKy350YMbCgFUxLbLhI7VBCGO/kYLD/fuRTr9SlWtUyi4SthGc9KASJK7pdMLpre3ux6qt0hdMnr X-Received: by 2002:a17:902:c951:b0:1a2:3108:5cc9 with SMTP id i17-20020a170902c95100b001a231085cc9mr35719381pla.40.1680458566604; Sun, 02 Apr 2023 11:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680458566; cv=none; d=google.com; s=arc-20160816; b=BQRr4whxeXnxowjQ0wxOVTTWVJxQWOIgiF5YQGkUgg510cu7IZTrw4G2f3Xvt+8+mt Oizkx3ueaunxt1FX0dI7giSoreEO2KDZAfta+WB1rlW1/X9EmZ0pjDmollcg+DG68obJ SLN+x2sKBG/pCkxHNcj/uYFvAeyLhifNwzcqCfh4yBJ4b3UFMPxj/xV7bZcY0wf6+Go6 4/rbQ3lRJrh3kQNuwhC+pYjT7oLyX3HkTf+SYbwS8x0xv0xqMZK5S9sKX/N85gzmmfT2 xnPCVQw7nckZ8/9J4zZBDsDg3Sc+h7duPPhoqEjHyuaITDfBxuHpZ/Fszrb7XNbT1hYU RGMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:lines:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FAP/CcTAjkBCwHEd9yBEKk4bW9gLUxYFIMzfOy1gFgU=; b=vFE5Ivk/CG041m2bMKGh/L3fTCHbnA+0zEX8RHVQdIwSItFY4h4SiXRX/NOHiwzF8w 8pvGpHsC9F7DQyaeSAnTEC3WLnkVoWOdHbX1FoYe1MJx81C0JyJThPv3LX59Xhd34ECX YiUd9ovgGhB7+HNfKiYwWMQh5U84dgxA9ovbhBdC03UIz8wTBZpy7PJOWVQy/7VnDmfC LmanJN4qBtEZ61ZjbmNltvi1qPAbiUNfJAK51eQ0gb4PUVaU2A2ChBZuUb5AYSf3Jp7Z qEbFQkFasQXw5PKRJD1LQu5YkMxbG7XD8fblnUiLXt/l7ZSIzSxufbVf+j8z9r95uimR ZkYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="1X/OWQT+"; 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 q14-20020a6557ce000000b005073e3342eesi6796890pgr.143.2023.04.02.11.02.32; Sun, 02 Apr 2023 11:02:46 -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="1X/OWQT+"; 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 S231294AbjDBR7P (ORCPT + 99 others); Sun, 2 Apr 2023 13:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbjDBR7O (ORCPT ); Sun, 2 Apr 2023 13:59:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 602DEDBF3 for ; Sun, 2 Apr 2023 10:59:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D72DBB80F02 for ; Sun, 2 Apr 2023 17:59:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C32BC433D2; Sun, 2 Apr 2023 17:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680458349; bh=4x1kMrX4o0OHNQFtezpfSrEFxvp1hGakgpbo4FR7d1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1X/OWQT+qUf88EQhJxJt7QwVAJGGOlfP0aR7DqS95FxnoYIvjgyYE1uCEW6O7MlLu zZDhlVn7xtCMKPnRcHbJOzBry4BZKvmKkVcW6CtZ4ESu8ua9rJc85gQAvkzBzIRj+A gA4oWK2lsira/5wgEwqRT0fnAnBCSV4ANyqQSglI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman Subject: [PATCH 2/5] driver core: class: make class_register() take a const * Date: Sun, 2 Apr 2023 19:58:47 +0200 Message-Id: <2023040248-customary-release-4aec@gregkh> X-Mailer: git-send-email 2.40.0 In-Reply-To: <2023040244-duffel-pushpin-f738@gregkh> References: <2023040244-duffel-pushpin-f738@gregkh> MIME-Version: 1.0 Lines: 71 X-Developer-Signature: v=1; a=openpgp-sha256; l=2435; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=4x1kMrX4o0OHNQFtezpfSrEFxvp1hGakgpbo4FR7d1g=; b=owGbwMvMwCRo6H6F97bub03G02pJDCmahyI353021p6+7XlKo7pCsYxVUIFkQhTrs4yr0dG3t szM2nS4I5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACay5gDDHG7jU7Xzptq0L/h4 Odm8gs3xUZa6KcOCHWFs2p2iW6qPbiiUsf25K4ZXyFcbAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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?1762088521873765313?= X-GMAIL-MSGID: =?utf-8?q?1762088521873765313?= Now that the class code is cleaned up to not modify the class pointer registered with it, change class_register() to take a const * to allow the structure to be placed into read-only memory. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman Acked-by: Rafael J. Wysocki --- drivers/base/base.h | 2 +- drivers/base/class.c | 6 +++--- include/linux/device/class.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index e96f3343fd7c..eb4c0ace9242 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -54,7 +54,7 @@ struct subsys_private { struct device *dev_root; struct kset glue_dirs; - struct class *class; + const struct class *class; struct lock_class_key lock_key; }; diff --git a/drivers/base/class.c b/drivers/base/class.c index 53fc7052340c..05bce79d3d19 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -93,7 +93,7 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr, static void class_release(struct kobject *kobj) { struct subsys_private *cp = to_subsys_private(kobj); - struct class *class = cp->class; + const struct class *class = cp->class; pr_debug("class '%s': release.\n", class->name); @@ -110,7 +110,7 @@ static void class_release(struct kobject *kobj) static const struct kobj_ns_type_operations *class_child_ns_type(const struct kobject *kobj) { const struct subsys_private *cp = to_subsys_private(kobj); - struct class *class = cp->class; + const struct class *class = cp->class; return class->ns_type; } @@ -175,7 +175,7 @@ static void klist_class_dev_put(struct klist_node *n) put_device(dev); } -int class_register(struct class *cls) +int class_register(const struct class *cls) { struct subsys_private *cp; struct lock_class_key *key; diff --git a/include/linux/device/class.h b/include/linux/device/class.h index f3c418fa129a..4bf46f9bbb56 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -76,7 +76,7 @@ struct class_dev_iter { const struct device_type *type; }; -int __must_check class_register(struct class *class); +int __must_check class_register(const struct class *class); void class_unregister(const struct class *class); bool class_is_registered(const struct class *class); From patchwork Sun Apr 2 17:58:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 78281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1864424vqo; Sun, 2 Apr 2023 11:23:05 -0700 (PDT) X-Google-Smtp-Source: AKy350brHG3f2kpnefbqCGkN6TN3mpZIBlosYF7iV4FgcvIujD43DDskXE/dvv6GHDXVQG4ITt9h X-Received: by 2002:a17:907:6e04:b0:930:3916:df17 with SMTP id sd4-20020a1709076e0400b009303916df17mr45872584ejc.0.1680459785657; Sun, 02 Apr 2023 11:23:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680459785; cv=none; d=google.com; s=arc-20160816; b=bWrz9wL6CMSgOVIEk0TFNamemr+2GAubeb9K2/OtQNMvwwpLan33hi6mnrUDVRPsf/ JWMnbwuoSTA8pSfh4k2HVzQPuUlFEVJWpVUla0NWfqibgFmxxX1BcGFwWH8sKErFmUgq YztuV4wt9te18YbuW7GsyMRtKv1oEHOTTCecegDvkQkJ8Jxy98qRoHoRCIFaU29pL9x1 obN8AoINYVmg6XVagw8xRq8s0+7f3/4A4MvS75fxyzssokG6IgHfiz4Bc/lFHo0EIPDr jNrwoK55RtCQL+RXbIjrZYRYelItrpFB0Yvsf1018G9juOzw3vj66woYIZUT6f1XiEeO A/Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:lines:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=J4wVwvt42hkAKvM1gY6gbUABq7KbpWVCeZcrak9ZILc=; b=MDzsm3BFW/p07Wh7RTy6xmJqzFMzwBfOuwMKcX9AEDtpnFEnOJJkZ+8UeCP712I23r NXeh2CkKXPbREDNh1p+jzjL5m/fcZrpHKAzfBghzhH/3y4gDbkj3nDHUEgzTD4aIJDN0 jAp6x6PB9XNOx8H++swwT6ZCXfP8P0QCwmE5Ym7Qz4YNh+HZemyrBOArwYBd53w2vuYk 2a8WYb2pwpYvwf2YJTNS0yB4E6+HtUzEr/j44Jew/eqLc+OLv3Q+FB5i7K0E037I92J+ EIG61sxZUpjVA2kMWGJccJvdJKQIR+Rez0JshHPuSlCS3VVXTzoqWPw6yY6XgOYyWOPi deTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bbtMeHcf; 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 e3-20020a170906044300b009341587edabsi4740649eja.89.2023.04.02.11.22.42; Sun, 02 Apr 2023 11:23:05 -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=bbtMeHcf; 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 S231308AbjDBR7S (ORCPT + 99 others); Sun, 2 Apr 2023 13:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbjDBR7R (ORCPT ); Sun, 2 Apr 2023 13:59:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E51C0E049 for ; Sun, 2 Apr 2023 10:59:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 86EDFB80F2B for ; Sun, 2 Apr 2023 17:59:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9C46C433D2; Sun, 2 Apr 2023 17:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680458352; bh=pRhq4yGE+rRCid5ll0m5GDPBM3XxuF3voRhflViLux0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbtMeHcfM0Z8nMH6TfPb7pUT0IAvzwnYkc/+3f1tk1/E+o0fiP/+Ygzd8HGNXde6O VCp8KkzexSCfY8YU+GoKXyMLV++tmDaDPBV6ICoKPWOJ/v6HR31cLfoDRyHyVdrc1+ T92NcIpTi2KcHZ/M6TqwBkBd2Imo0HUG3IKJ3ucw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman Subject: [PATCH 3/5] driver core: class: mark the struct class in struct class_interface constant Date: Sun, 2 Apr 2023 19:58:48 +0200 Message-Id: <2023040249-handball-gruffly-5da7@gregkh> X-Mailer: git-send-email 2.40.0 In-Reply-To: <2023040244-duffel-pushpin-f738@gregkh> References: <2023040244-duffel-pushpin-f738@gregkh> MIME-Version: 1.0 Lines: 39 X-Developer-Signature: v=1; a=openpgp-sha256; l=1425; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=pRhq4yGE+rRCid5ll0m5GDPBM3XxuF3voRhflViLux0=; b=owGbwMvMwCRo6H6F97bub03G02pJDCmahyKVbSf+KTPUceK4smmDfp/1PlXdOalLAudEp1bJx Dz2N7HviGVhEGRikBVTZPmyjefo/opDil6Gtqdh5rAygQxh4OIUgIlEvGCYX2uWq3NAK6b3USub cNalq9Jt9fGCDPMzFgr1PWVeFSF7/PDTxVtU79cU/b0HAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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?1762089799817105440?= X-GMAIL-MSGID: =?utf-8?q?1762089799817105440?= The struct class pointer in struct class_interface is never modified, so mark it as const so that no one accidentally tries to modify it in the future. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman Acked-by: Rafael J. Wysocki --- drivers/base/class.c | 2 +- include/linux/device/class.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/base/class.c b/drivers/base/class.c index 05bce79d3d19..ad8b9f163fd2 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -498,7 +498,7 @@ EXPORT_SYMBOL_GPL(class_interface_register); void class_interface_unregister(struct class_interface *class_intf) { struct subsys_private *sp; - struct class *parent = class_intf->class; + const struct class *parent = class_intf->class; struct class_dev_iter iter; struct device *dev; diff --git a/include/linux/device/class.h b/include/linux/device/class.h index 4bf46f9bbb56..53287aa105b8 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -217,7 +217,7 @@ ssize_t show_class_attr_string(const struct class *class, const struct class_att struct class_interface { struct list_head node; - struct class *class; + const struct class *class; int (*add_dev) (struct device *, struct class_interface *); void (*remove_dev) (struct device *, struct class_interface *); From patchwork Sun Apr 2 17:58:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 78280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1864239vqo; Sun, 2 Apr 2023 11:22:27 -0700 (PDT) X-Google-Smtp-Source: AKy350aa6XCwbQN2TKeJRBjavHng/KKmwIAQzz/jHCRaFqfurMLuSSxRKxNpn23gxrlVG+8KgC6c X-Received: by 2002:a17:907:868f:b0:948:eed:b4e0 with SMTP id qa15-20020a170907868f00b009480eedb4e0mr6131904ejc.61.1680459746771; Sun, 02 Apr 2023 11:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680459746; cv=none; d=google.com; s=arc-20160816; b=nEwKMALOlsBCF0okX76ADeFHOMLHPfqnbq3WyjrJRUNwVA7CnNsEgXSGz0BJve+VLC IqoBWdYxIT9rtJsokkQI3ObvD0cmKsPcE/lDdasU+YwBt+si8zSGkWIv+cSAXdf4EIKI Euy0n874n1n4NlPBYS0MyUqVnwgM+S/vv9zW/AFTDsxodyG/9vcuHep4jpfQoDUvViSa EF4d2yZX5v+9EhPFNqOq8aufOd38s9puTZ6UK+3UjSS+sEJVGUUTpq5V9eWVJk8f5fES zCEaFRDlWI/n2ANB0kK28r3eJqUz9uoCsxoYPfG1459p7Vo80tHcJ3bYBLwT1yd1feDa es5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:lines:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V/3FwJnUGiA+YOs6eSUmj3BvrkcxudSFBoiP9T4HI60=; b=azrEEXZoLZ8j7T8C3GveSsOdJ7zOOoLNp0DJ7deIEBFJcSk/Y64zAQ4MSE7fsFSjhC TlNENXtFJQ6Adsr1z+ADzncCLZnqfzukkjbbtZ6WrWQjWur6hANhKuhM1QEXM1sTUEEa PqBIBNfHZZvljv0MvQIvYwAaGfW/KUJeWteS5LF2pkDrLW1cbljC9jNMQj/zXluIcnQ4 PrAUt4ybUoKNdvC5GP6lsRG7NEaxE1LmWvXga9c5a99a1Faz7wjCw2kl6iMiMM6eLlKY 9yP5exgRmq6+3CXuxACPwb1RBOCNB9RBHoBn4fXYmVGxkbDGOwWU67S4B7Bzq+JhzD8O hZVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=awde1rq0; 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 m22-20020a170906721600b008e6bdf85401si6249467ejk.869.2023.04.02.11.22.02; Sun, 02 Apr 2023 11:22:26 -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=awde1rq0; 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 S231318AbjDBR72 (ORCPT + 99 others); Sun, 2 Apr 2023 13:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231304AbjDBR7Y (ORCPT ); Sun, 2 Apr 2023 13:59:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61AC1EB6B for ; Sun, 2 Apr 2023 10:59:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 37B0AB80F10 for ; Sun, 2 Apr 2023 17:59:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60023C433D2; Sun, 2 Apr 2023 17:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680458354; bh=gi+gKnH113ddsxRQT0k8K/Z9hlCfY3UZcSTiuNPvzNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=awde1rq0CG2iGm1qGV0gdQkp7uOgz7QWFGNa55TUpl3IWrur2vvrCkxhcjCe9PLCO QK/HfIQlposmB/c2kpNNlZCvX01Q+uqaqMZ2aS9TAd/0hg+SLNTlYiY6ZC50U1+tvV okjXPcuW2EfZC9vzR7vzniQboSNZkrcqHbJu/Q4A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman , Jean Delvare , Guenter Roeck , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kurt Schwemmer , Logan Gunthorpe , Jon Mason , Dave Jiang , Allen Hubbe , Dominik Brodowski , Matt Porter , Alexandre Bounine , "James E.J. Bottomley" , "Martin K. Petersen" , Doug Gilbert , John Stultz , Thomas Gleixner , Stephen Boyd , Hans de Goede , Andrew Morton , Wang Weiyang , Yang Yingliang , Jakob Koschel , Cai Xinchen Subject: [PATCH 4/5] driver core: class: remove struct class_interface * from callbacks Date: Sun, 2 Apr 2023 19:58:49 +0200 Message-Id: <2023040250-pushover-platter-509c@gregkh> X-Mailer: git-send-email 2.40.0 In-Reply-To: <2023040244-duffel-pushpin-f738@gregkh> References: <2023040244-duffel-pushpin-f738@gregkh> MIME-Version: 1.0 Lines: 381 X-Developer-Signature: v=1; a=openpgp-sha256; l=14757; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=gi+gKnH113ddsxRQT0k8K/Z9hlCfY3UZcSTiuNPvzNo=; b=owGbwMvMwCRo6H6F97bub03G02pJDCmah6JmGAYoxCj+Yul14HxoUbAw+UbSt6tCZhueH1J37 P5uOIWtI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACZiWsUwk1F91d1fX5zfm3Rq 7Zkdm75C95trGsP8wmThgzsFJG2kWU6ueWSrtvXUNz09AA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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?1762089759234679205?= X-GMAIL-MSGID: =?utf-8?q?1762089759234679205?= The add_dev and remove_dev callbacks in struct class_interface currently pass in a pointer back to the class_interface structure that is calling them, but none of the callback implementations actually use this pointer as it is pointless (the structure is known, the driver passed it in in the first place if it is really needed again.) So clean this up and just remove the pointer from the callbacks and fix up all callback functions. Cc: Jean Delvare Cc: Guenter Roeck Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Kurt Schwemmer Cc: Logan Gunthorpe Cc: Jon Mason Cc: Dave Jiang Cc: Allen Hubbe Cc: Dominik Brodowski Cc: Matt Porter Cc: Alexandre Bounine Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: Doug Gilbert Cc: John Stultz Cc: Thomas Gleixner Cc: Stephen Boyd Cc: Hans de Goede Cc: Andrew Morton Cc: Wang Weiyang Cc: Yang Yingliang Cc: Jakob Koschel Cc: Cai Xinchen Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman Acked-by: Logan Gunthorpe Acked-by: Rafael J. Wysocki Acked-by: Guenter Roeck --- Note, subsystem maintainers, this should go through my driver-core tree as it's part of a larger cleanup of 'struct class' handling. I'm cc:ing you all to get reviews to verify I didn't do something foolish, but it has passed 0-day bot build testing already (which caught many foolish mistakes of mine...) drivers/base/class.c | 4 ++-- drivers/base/core.c | 10 ++++------ drivers/hwmon/drivetemp.c | 4 ++-- drivers/net/rionet.c | 3 +-- drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 6 ++---- drivers/pcmcia/ds.c | 6 ++---- drivers/pcmcia/rsrc_nonstatic.c | 6 ++---- drivers/rapidio/devices/rio_mport_cdev.c | 7 ++----- drivers/rapidio/rio_cm.c | 8 ++------ drivers/scsi/ses.c | 6 ++---- drivers/scsi/sg.c | 8 ++++---- include/linux/device/class.h | 4 ++-- kernel/time/alarmtimer.c | 3 +-- 13 files changed, 28 insertions(+), 47 deletions(-) diff --git a/drivers/base/class.c b/drivers/base/class.c index ad8b9f163fd2..ac1808d1a2e8 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -486,7 +486,7 @@ int class_interface_register(struct class_interface *class_intf) if (class_intf->add_dev) { class_dev_iter_init(&iter, parent, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) - class_intf->add_dev(dev, class_intf); + class_intf->add_dev(dev); class_dev_iter_exit(&iter); } mutex_unlock(&sp->mutex); @@ -514,7 +514,7 @@ void class_interface_unregister(struct class_interface *class_intf) if (class_intf->remove_dev) { class_dev_iter_init(&iter, parent, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) - class_intf->remove_dev(dev, class_intf); + class_intf->remove_dev(dev); class_dev_iter_exit(&iter); } mutex_unlock(&sp->mutex); diff --git a/drivers/base/core.c b/drivers/base/core.c index 64d188be4df9..7a42d1b6b721 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -541,8 +541,7 @@ static struct class devlink_class = { .dev_release = devlink_dev_release, }; -static int devlink_add_symlinks(struct device *dev, - struct class_interface *class_intf) +static int devlink_add_symlinks(struct device *dev) { int ret; size_t len; @@ -591,8 +590,7 @@ static int devlink_add_symlinks(struct device *dev, return ret; } -static void devlink_remove_symlinks(struct device *dev, - struct class_interface *class_intf) +static void devlink_remove_symlinks(struct device *dev) { struct device_link *link = to_devlink(dev); size_t len; @@ -3647,7 +3645,7 @@ int device_add(struct device *dev) /* notify any interfaces that the device is here */ list_for_each_entry(class_intf, &sp->interfaces, node) if (class_intf->add_dev) - class_intf->add_dev(dev, class_intf); + class_intf->add_dev(dev); mutex_unlock(&sp->mutex); subsys_put(sp); } @@ -3805,7 +3803,7 @@ void device_del(struct device *dev) /* notify any interfaces that the device is now gone */ list_for_each_entry(class_intf, &sp->interfaces, node) if (class_intf->remove_dev) - class_intf->remove_dev(dev, class_intf); + class_intf->remove_dev(dev); /* remove the device from the class list */ klist_del(&dev->p->knode_class); mutex_unlock(&sp->mutex); diff --git a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c index 8e5759b42390..86171031ddc5 100644 --- a/drivers/hwmon/drivetemp.c +++ b/drivers/hwmon/drivetemp.c @@ -550,7 +550,7 @@ static const struct hwmon_chip_info drivetemp_chip_info = { * The device argument points to sdev->sdev_dev. Its parent is * sdev->sdev_gendev, which we can use to get the scsi_device pointer. */ -static int drivetemp_add(struct device *dev, struct class_interface *intf) +static int drivetemp_add(struct device *dev) { struct scsi_device *sdev = to_scsi_device(dev->parent); struct drivetemp_data *st; @@ -585,7 +585,7 @@ static int drivetemp_add(struct device *dev, struct class_interface *intf) return err; } -static void drivetemp_remove(struct device *dev, struct class_interface *intf) +static void drivetemp_remove(struct device *dev) { struct drivetemp_data *st, *tmp; diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c index fbcb9d05da64..4eececc94513 100644 --- a/drivers/net/rionet.c +++ b/drivers/net/rionet.c @@ -662,8 +662,7 @@ static int rionet_shutdown(struct notifier_block *nb, unsigned long code, return NOTIFY_DONE; } -static void rionet_remove_mport(struct device *dev, - struct class_interface *class_intf) +static void rionet_remove_mport(struct device *dev) { struct rio_mport *mport = to_rio_mport(dev); struct net_device *ndev; diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c index 88ae18b0efa8..d6bbcc7b5b90 100644 --- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c +++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c @@ -1470,8 +1470,7 @@ static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev) return rc; } -static int switchtec_ntb_add(struct device *dev, - struct class_interface *class_intf) +static int switchtec_ntb_add(struct device *dev) { struct switchtec_dev *stdev = to_stdev(dev); struct switchtec_ntb *sndev; @@ -1541,8 +1540,7 @@ static int switchtec_ntb_add(struct device *dev, return rc; } -static void switchtec_ntb_remove(struct device *dev, - struct class_interface *class_intf) +static void switchtec_ntb_remove(struct device *dev) { struct switchtec_dev *stdev = to_stdev(dev); struct switchtec_ntb *sndev = stdev->sndev; diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index c8087efa5e4a..d500e5dbbc3f 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1335,8 +1335,7 @@ static struct pcmcia_callback pcmcia_bus_callback = { .resume = pcmcia_bus_resume, }; -static int pcmcia_bus_add_socket(struct device *dev, - struct class_interface *class_intf) +static int pcmcia_bus_add_socket(struct device *dev) { struct pcmcia_socket *socket = dev_get_drvdata(dev); int ret; @@ -1369,8 +1368,7 @@ static int pcmcia_bus_add_socket(struct device *dev, return 0; } -static void pcmcia_bus_remove_socket(struct device *dev, - struct class_interface *class_intf) +static void pcmcia_bus_remove_socket(struct device *dev) { struct pcmcia_socket *socket = dev_get_drvdata(dev); diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index ad1141fddb4c..471e0c5815f3 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -1200,8 +1200,7 @@ static const struct attribute_group rsrc_attributes = { .attrs = pccard_rsrc_attributes, }; -static int pccard_sysfs_add_rsrc(struct device *dev, - struct class_interface *class_intf) +static int pccard_sysfs_add_rsrc(struct device *dev) { struct pcmcia_socket *s = dev_get_drvdata(dev); @@ -1210,8 +1209,7 @@ static int pccard_sysfs_add_rsrc(struct device *dev, return sysfs_create_group(&dev->kobj, &rsrc_attributes); } -static void pccard_sysfs_remove_rsrc(struct device *dev, - struct class_interface *class_intf) +static void pccard_sysfs_remove_rsrc(struct device *dev) { struct pcmcia_socket *s = dev_get_drvdata(dev); diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c index deb96c3160a7..a115730ebf14 100644 --- a/drivers/rapidio/devices/rio_mport_cdev.c +++ b/drivers/rapidio/devices/rio_mport_cdev.c @@ -2536,10 +2536,8 @@ static void mport_cdev_remove(struct mport_dev *md) /* * mport_add_mport() - Add rio_mport from LDM device struct * @dev: Linux device model struct - * @class_intf: Linux class_interface */ -static int mport_add_mport(struct device *dev, - struct class_interface *class_intf) +static int mport_add_mport(struct device *dev) { struct rio_mport *mport = NULL; struct mport_dev *chdev = NULL; @@ -2559,8 +2557,7 @@ static int mport_add_mport(struct device *dev, * mport_remove_mport() - Remove rio_mport from global list * TODO remove device from global mport_dev list */ -static void mport_remove_mport(struct device *dev, - struct class_interface *class_intf) +static void mport_remove_mport(struct device *dev) { struct rio_mport *mport = NULL; struct mport_dev *chdev; diff --git a/drivers/rapidio/rio_cm.c b/drivers/rapidio/rio_cm.c index acaf9cda014c..49f8d111e546 100644 --- a/drivers/rapidio/rio_cm.c +++ b/drivers/rapidio/rio_cm.c @@ -2087,13 +2087,11 @@ static int riocm_cdev_add(dev_t devno) /* * riocm_add_mport - add new local mport device into channel management core * @dev: device object associated with mport - * @class_intf: class interface * * When a new mport device is added, CM immediately reserves inbound and * outbound RapidIO mailboxes that will be used. */ -static int riocm_add_mport(struct device *dev, - struct class_interface *class_intf) +static int riocm_add_mport(struct device *dev) { int rc; int i; @@ -2166,14 +2164,12 @@ static int riocm_add_mport(struct device *dev, /* * riocm_remove_mport - remove local mport device from channel management core * @dev: device object associated with mport - * @class_intf: class interface * * Removes a local mport device from the list of registered devices that provide * channel management services. Returns an error if the specified mport is not * registered with the CM core. */ -static void riocm_remove_mport(struct device *dev, - struct class_interface *class_intf) +static void riocm_remove_mport(struct device *dev) { struct rio_mport *mport = to_rio_mport(dev); struct cm_dev *cm; diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c index b11a9162e73a..57feb0cae896 100644 --- a/drivers/scsi/ses.c +++ b/drivers/scsi/ses.c @@ -663,8 +663,7 @@ static void ses_match_to_enclosure(struct enclosure_device *edev, } } -static int ses_intf_add(struct device *cdev, - struct class_interface *intf) +static int ses_intf_add(struct device *cdev) { struct scsi_device *sdev = to_scsi_device(cdev->parent); struct scsi_device *tmp_sdev; @@ -869,8 +868,7 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev) enclosure_unregister(edev); } -static void ses_intf_remove(struct device *cdev, - struct class_interface *intf) +static void ses_intf_remove(struct device *cdev) { struct scsi_device *sdev = to_scsi_device(cdev->parent); diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 4997f880d4a4..037f8c98a6d3 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -96,8 +96,8 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ; #define SG_SECTOR_SZ 512 -static int sg_add_device(struct device *, struct class_interface *); -static void sg_remove_device(struct device *, struct class_interface *); +static int sg_add_device(struct device *); +static void sg_remove_device(struct device *); static DEFINE_IDR(sg_index_idr); static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock @@ -1488,7 +1488,7 @@ sg_alloc(struct scsi_device *scsidp) } static int -sg_add_device(struct device *cl_dev, struct class_interface *cl_intf) +sg_add_device(struct device *cl_dev) { struct scsi_device *scsidp = to_scsi_device(cl_dev->parent); Sg_device *sdp = NULL; @@ -1578,7 +1578,7 @@ sg_device_destroy(struct kref *kref) } static void -sg_remove_device(struct device *cl_dev, struct class_interface *cl_intf) +sg_remove_device(struct device *cl_dev) { struct scsi_device *scsidp = to_scsi_device(cl_dev->parent); Sg_device *sdp = dev_get_drvdata(cl_dev); diff --git a/include/linux/device/class.h b/include/linux/device/class.h index 53287aa105b8..9deeaeb457bb 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -219,8 +219,8 @@ struct class_interface { struct list_head node; const struct class *class; - int (*add_dev) (struct device *, struct class_interface *); - void (*remove_dev) (struct device *, struct class_interface *); + int (*add_dev) (struct device *dev); + void (*remove_dev) (struct device *dev); }; int __must_check class_interface_register(struct class_interface *); diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 7e5dff602585..82b28ab0f328 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -81,8 +81,7 @@ struct rtc_device *alarmtimer_get_rtcdev(void) } EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev); -static int alarmtimer_rtc_add_device(struct device *dev, - struct class_interface *class_intf) +static int alarmtimer_rtc_add_device(struct device *dev) { unsigned long flags; struct rtc_device *rtc = to_rtc_device(dev); From patchwork Sun Apr 2 17:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 78279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1857333vqo; Sun, 2 Apr 2023 11:03:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aCN1Q7+76B+43VQUQNGD4Glq81pEDjR2cyOXIYf13qS9s3cdqO+xAB2eRaJFU1wBvZEjBv X-Received: by 2002:a17:903:410c:b0:1a1:f0ce:bb8f with SMTP id r12-20020a170903410c00b001a1f0cebb8fmr26879999pld.65.1680458630745; Sun, 02 Apr 2023 11:03:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680458630; cv=none; d=google.com; s=arc-20160816; b=a+MkRrh+m6PxLVJm1Q0JlAVL2BVs3QhHhgZAeZV57ba28+5k/U9H1zQMs7S6t5lMTh SAXpR2x/aSTFMPpHnbAgppNs1frEoaAPXckvxWc4D45fmGPsZ/niy5Z+AVGPYlrFtFle aTVtAbvDYN3P+yc6HcOCHoFaNpwCxJnTIN9xto5C1v/gAU2QCbYR4t5xWrh+VteJWHSx JMDdwqqUvnVF271YimdiHgZQbM0ZWorqNC6N7u6gOFUg/twVUu9W2Uqp56MQ9lz/8gh/ lXI35i4/L6WonzQ9zW0h6cKVL+SrE4vuh1Gd6bGFH68T8/rXgD+D6pOfqbqSy+5dl8OR SACA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:lines:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yvwuLf3N6zVM6IrYjQ8DJ3FQt61/GTv1/7b1OKkzkxA=; b=ArLFMtual5bxqesI+zLHVhUs/0AD9ZgUCrag0XOL++Qpvmp4qgRT1IytliN4Q2NRqS lDKB4Lr9X3DMMwlq51dkedRdRC5a+qNvHHMiGlsZ8mNjXSQMGepCOivIRl/viwBqQLOR TwCBltGmOzuYbk+nO2nDI92SnDy2wMy69VNgbd0AtrOe6Xfp1BfaO0+giK4JN+TDnEQm gVIT27XzNmwjxHgtFpO7mMTLJ9PROCytj5eI9VBwd9L/uUq974dlfXtofFwWJcpdtINr AyRAC3aJxNTnzyJXZ+eHc95G4ItwDLZXnhhKlzCSgtTNFtin2MOwXpr6ZbmsARRus47k M/Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rcGT+fPD; 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 s195-20020a632ccc000000b00513233eb86asi6492870pgs.593.2023.04.02.11.03.38; Sun, 02 Apr 2023 11:03:50 -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=rcGT+fPD; 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 S231328AbjDBR7a (ORCPT + 99 others); Sun, 2 Apr 2023 13:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbjDBR7Z (ORCPT ); Sun, 2 Apr 2023 13:59:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F111012845 for ; Sun, 2 Apr 2023 10:59:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 33C01612D6 for ; Sun, 2 Apr 2023 17:59:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44B43C433D2; Sun, 2 Apr 2023 17:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680458357; bh=leWIQAXQz3QXHiAX/iTqJSpy4ZNlpuecBAdl9KGTU0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rcGT+fPDhJJRkEUFgUkTykT3Go2qmi2Tpjn+UO/WIpsa7NhIcSNZ2WUx1b15ToNJG +cepNiUJwjgf5v7sNQyh5GHSIiqZM7GA1MfEwxeHCit4u2b0YrodSpEr99nrbtLPdD Vwi+wYAxeVk2GyhoZiaZjjbvxIUjSM26OM9/4ltM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman , Jiri Slaby , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 5/5] tty: make tty_class a static const structure Date: Sun, 2 Apr 2023 19:58:50 +0200 Message-Id: <2023040250-landowner-unfitted-11f4@gregkh> X-Mailer: git-send-email 2.40.0 In-Reply-To: <2023040244-duffel-pushpin-f738@gregkh> References: <2023040244-duffel-pushpin-f738@gregkh> MIME-Version: 1.0 Lines: 138 X-Developer-Signature: v=1; a=openpgp-sha256; l=5137; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=leWIQAXQz3QXHiAX/iTqJSpy4ZNlpuecBAdl9KGTU0A=; b=owGbwMvMwCRo6H6F97bub03G02pJDCmah6IqND1XreO+xpnhz5ejk/vBRl0uk70zS7Nrr5xJ7 P3MFa0dsSwMgkwMsmKKLF+28RzdX3FI0cvQ9jTMHFYmkCEMXJwCMJF7ZxgWzG9ce+y4pZpbwDSj /dN/Ptf78UE+iGE2605l854j4Vv9Fy8t3Pb5qbV4mtYKAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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?1762088589607702114?= X-GMAIL-MSGID: =?utf-8?q?1762088589607702114?= Now that the driver core allows for struct class to be in read-only memory, move the tty_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: Jiri Slaby Cc: "Ilpo Järvinen" Signed-off-by: Greg Kroah-Hartman Reviewed-by: Jiri Slaby --- Jiri and Ilpo, this is part of the larger driver-core changes to make it possible to move struct class into read-only memory and is used as proof that this all works properly. I'll take it throught the driver-core tree as it shoudn't conflict with any tty.git changes. drivers/tty/pty.c | 2 +- drivers/tty/tty_io.c | 24 +++++++++++------------- drivers/tty/vt/vt.c | 2 +- include/linux/tty.h | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 07394fdaf522..2b1c8ab99dba 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -931,7 +931,7 @@ static void __init unix98_pty_init(void) if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0) panic("Couldn't register /dev/ptmx driver"); - device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx"); + device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx"); } #else diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 1382d9050ce8..44e0d53aa0b8 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3070,7 +3070,7 @@ static struct device *tty_get_device(struct tty_struct *tty) { dev_t devt = tty_devnum(tty); - return class_find_device_by_devt(tty_class, devt); + return class_find_device_by_devt(&tty_class, devt); } @@ -3143,8 +3143,6 @@ int tty_put_char(struct tty_struct *tty, unsigned char ch) } EXPORT_SYMBOL_GPL(tty_put_char); -struct class *tty_class; - static int tty_cdev_add(struct tty_driver *driver, dev_t dev, unsigned int index, unsigned int count) { @@ -3239,7 +3237,7 @@ struct device *tty_register_device_attr(struct tty_driver *driver, return ERR_PTR(-ENOMEM); dev->devt = devt; - dev->class = tty_class; + dev->class = &tty_class; dev->parent = device; dev->release = tty_device_create_release; dev_set_name(dev, "%s", name); @@ -3294,8 +3292,7 @@ EXPORT_SYMBOL_GPL(tty_register_device_attr); */ void tty_unregister_device(struct tty_driver *driver, unsigned index) { - device_destroy(tty_class, - MKDEV(driver->major, driver->minor_start) + index); + device_destroy(&tty_class, MKDEV(driver->major, driver->minor_start) + index); if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) { cdev_del(driver->cdevs[index]); driver->cdevs[index] = NULL; @@ -3510,13 +3507,14 @@ static char *tty_devnode(const struct device *dev, umode_t *mode) return NULL; } +const struct class tty_class = { + .name = "tty", + .devnode = tty_devnode, +}; + static int __init tty_class_init(void) { - tty_class = class_create("tty"); - if (IS_ERR(tty_class)) - return PTR_ERR(tty_class); - tty_class->devnode = tty_devnode; - return 0; + return class_register(&tty_class); } postcore_initcall(tty_class_init); @@ -3643,13 +3641,13 @@ int __init tty_init(void) if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) panic("Couldn't register /dev/tty driver\n"); - device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); + device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); cdev_init(&console_cdev, &console_fops); if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) panic("Couldn't register /dev/console driver\n"); - consdev = device_create_with_groups(tty_class, NULL, + consdev = device_create_with_groups(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL, cons_dev_groups, "console"); if (IS_ERR(consdev)) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 5496bf4b76ec..02f4b6be8584 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3539,7 +3539,7 @@ int __init vty_init(const struct file_operations *console_fops) if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) panic("Couldn't register /dev/tty0 driver\n"); - tty0dev = device_create_with_groups(tty_class, NULL, + tty0dev = device_create_with_groups(&tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, vt_dev_groups, "tty0"); if (IS_ERR(tty0dev)) diff --git a/include/linux/tty.h b/include/linux/tty.h index 093935e97f42..121eb4b0d325 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -387,7 +387,7 @@ extern struct ktermios tty_std_termios; int vcs_init(void); -extern struct class *tty_class; +extern const struct class tty_class; /** * tty_kref_get - get a tty reference