From patchwork Mon Mar 13 18:18:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 69007 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1339161wrd; Mon, 13 Mar 2023 11:27:46 -0700 (PDT) X-Google-Smtp-Source: AK7set9AsB4K2WVzkU13BGkjbkrYnzEhsnycCnTfeiINoh4LmOtFfjbDTWahvexjmYPd8EVI8v6e X-Received: by 2002:a17:902:e741:b0:1a0:41ea:b9bb with SMTP id p1-20020a170902e74100b001a041eab9bbmr4995341plf.27.1678732065786; Mon, 13 Mar 2023 11:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678732065; cv=none; d=google.com; s=arc-20160816; b=g+PiDxh1nHEUPcS0JnsqxCxU5Bf2NVV/TGtjIu31zRErlhrR8Gg5eTlr7uZmxTFpyZ bqv7VIm02IyhdAWnwyC0D+ZyaQXCBEmhfh5NPUkuRz/USwH4PP/h1UGfi95f1PbYI+y3 lEvb2EmQo1Hl3rNi7DDzOsGKRzO2XMNx+M66bBWqehEbB5UqLLTiYpWZsuRhC5ci7iys Ys/wawcXgU0MzgoHxLIgpPH6/8JKLIhvFLfHI93Czv0UHYPsdILlriwb4QcmwRQg7Wi2 D4/dkf04GZuTZIjEwqRpHSOc5UqLG50eUCCBKqIAWPF5VTAq3vCzZ/C3LYFTIUa7cgR3 dHTg== 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=lxgZGj8ef2gp/gKdkMi9YPd3tIGYza7fBNj7t1vqPAQ=; b=CfhZ7vT+clm2MC4sJ9xqPqUU+KRC0RlRU8sahzvzghuWzTLF5vh8rt03gf3c6qQyBh PH1gSDnr0rM2u1l4gld6yHGayjv2LPPuf4yRomEYPgyhhy8gZk7wwgyHzCk4CF73ljQt rIs9z6qet0y2Q3BikwMwT19wI1/FfnEzJm/974RIT6wa1IQZcGDMDejYUokf+XhtwFKR OoEbbX8B3YCqxWY4efnVHDKWq2lgEhdnaCdY+mixzx3HQam6WO23qDa03jW28m0ezNLb o4QYSR/RfVcEtlbl1bIpTdZC+UIJxvMhrh55mJziHdRQ6L0nR3ZFuJkyl/Ll8o2V2RcY mFlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Mbv0P7nw; 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 jj21-20020a170903049500b0019a88f51635si304273plb.534.2023.03.13.11.27.30; Mon, 13 Mar 2023 11:27:45 -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=Mbv0P7nw; 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 S229961AbjCMSTM (ORCPT + 99 others); Mon, 13 Mar 2023 14:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjCMSTD (ORCPT ); Mon, 13 Mar 2023 14:19:03 -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 98CFE4DBFD for ; Mon, 13 Mar 2023 11:19:01 -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 3400E6144F for ; Mon, 13 Mar 2023 18:19:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45544C4339B; Mon, 13 Mar 2023 18:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678731540; bh=Ao8E7I6q4IqhdrrchnK3hfPSFJkT9ZPSxEvWAhBtTUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mbv0P7nwVw7bKDKzaPcuGuQV4E5mgJq77e469LDVKQELNfp48353TI+KPMdGJdfeK YLhcZIBXdwGkTNcEYc5ON8Gk7AgXBR448Z/nyTcmWU6VHNATvZ6s95y81ANyko3lY1 xmDo0JGBCdMFbQd1umUUjNp81+3svDSjW067g5is= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman Subject: [PATCH 11/12] driver core: device: mark struct class in struct device as constant Date: Mon, 13 Mar 2023 19:18:42 +0100 Message-Id: <20230313181843.1207845-11-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230313181843.1207845-1-gregkh@linuxfoundation.org> References: <20230313181843.1207845-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2552; i=gregkh@linuxfoundation.org; h=from:subject; bh=Ao8E7I6q4IqhdrrchnK3hfPSFJkT9ZPSxEvWAhBtTUY=; b=owGbwMvMwCRo6H6F97bub03G02pJDCn8mcy3r21bfEqx5LLMlZ93XQ+ds7l1Pt3ma4nMNt9Fx kyL1u7f2BHLwiDIxCArpsjyZRvP0f0VhxS9DG1Pw8xhZQIZwsDFKQATmajCMFf2/+2gZotdk9f9 P67Ht1N8ms1X03MM83SXNrMclr/IGtjhw/x8rrhXkEVcDgA= 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 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?1760278154098844717?= X-GMAIL-MSGID: =?utf-8?q?1760278154098844717?= The pointer to a struct class in a struct device should never be used to change anything in that class. So mark it as constant to enforce this requirement. This requires a few minor changes to some internal driver core functions to enforce the const * being used here now. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 10 +++++----- include/linux/device.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index f3b7040ef9b6..0970db630839 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2820,7 +2820,7 @@ EXPORT_SYMBOL_GPL(devm_device_add_groups); static int device_add_attrs(struct device *dev) { - struct class *class = dev->class; + const struct class *class = dev->class; const struct device_type *type = dev->type; int error; @@ -2887,7 +2887,7 @@ static int device_add_attrs(struct device *dev) static void device_remove_attrs(struct device *dev) { - struct class *class = dev->class; + const struct class *class = dev->class; const struct device_type *type = dev->type; if (dev->physical_location) { @@ -3120,7 +3120,7 @@ struct kobject *virtual_device_parent(struct device *dev) struct class_dir { struct kobject kobj; - struct class *class; + const struct class *class; }; #define to_class_dir(obj) container_of(obj, struct class_dir, kobj) @@ -3145,7 +3145,7 @@ static const struct kobj_type class_dir_ktype = { }; static struct kobject * -class_dir_create_and_add(struct class *class, struct kobject *parent_kobj) +class_dir_create_and_add(const struct class *class, struct kobject *parent_kobj) { struct class_dir *dir; int retval; @@ -4580,7 +4580,7 @@ static int device_attrs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid) { struct kobject *kobj = &dev->kobj; - struct class *class = dev->class; + const struct class *class = dev->class; const struct device_type *type = dev->type; int error; diff --git a/include/linux/device.h b/include/linux/device.h index c0c02a00fe87..f97a793c6683 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -629,7 +629,7 @@ struct device { spinlock_t devres_lock; struct list_head devres_head; - struct class *class; + const struct class *class; const struct attribute_group **groups; /* optional groups */ void (*release)(struct device *dev);