From patchwork Wed Feb 8 11:13:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 54401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3394162wrn; Wed, 8 Feb 2023 03:17:32 -0800 (PST) X-Google-Smtp-Source: AK7set+YvnqXptaz3nusORp5BVUmBH+1uhseYVnhfIBZOg9rGH6hHcXs0gKHC/yi0bzRxxmptLx5 X-Received: by 2002:a17:906:73dd:b0:894:4341:77d6 with SMTP id n29-20020a17090673dd00b00894434177d6mr6424654ejl.1.1675855052105; Wed, 08 Feb 2023 03:17:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675855052; cv=none; d=google.com; s=arc-20160816; b=WoYIGJhY1A7pHd3QdbjqXcn1/lPyX07bTgDfENeNw/zKVKc/iKm36V5bTu4AQ/xfgF PVmqXLk7M3YikJncxs64D2iPPvuMjnm/alWML/PajJXUKnaEOJqTwIrLvOUNxNNfVtfO jVsUEbAuqOY6rmqltmZw0Eo3Yk806mNQqA6m71+6YOauEvO7Que3nXhc5zGmjYLWUpjZ +Yb+/ToBSjU2ppcIOurrB1Z3Pmpj+QBV4YJoRXiBGWAKqAJOteP9Mkxnb0zU1OIMAiC7 Oi6W4Sq+HLk02ZByqdMU0g2aATcT01gVXQiSa1ys+wmaOrbsNUZ6RNI/9UWxmmmRKeQ3 P14Q== 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=n94y7gpYBQuo1aCzNN5ARO2NCnkNUwCYmpJgErO7SXU=; b=YopEaMlEgQu3bS3Sy2OtCnTL4PIqmAxDmgCxW30CxnKCAlwCgIHzKP16YsRjXS3DJz gk5MjPmMIxF8fM6t/gpofJQTia+DNjKKPvXeuA1YHGwnE3ZjVjF18Tlp/UPUVZiGahmd zqBkle64JMt/oRn2qbmhJFGP37qcRKvhVkaZBgYgma/HwDVTdPkhsZLyaszPfaKOUr0u fuTxx1FICQ8p0ijJhguJndoNftHTUWWZpjYtHJH+u1oLorHNs/SZbLX9ITMrM4ztskkd TvEMDyM7WKgky3lrZOc3Fy/gbOLJOhgOGbRhN6ARD0y/Gd7Gid63x8UBh4M2Hi0XIaoV KpQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zxvfNV5W; 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 fw38-20020a170907502600b0088e6b7aff2csi1247012ejc.159.2023.02.08.03.17.05; Wed, 08 Feb 2023 03:17:32 -0800 (PST) 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=zxvfNV5W; 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 S230196AbjBHLPO (ORCPT + 99 others); Wed, 8 Feb 2023 06:15:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbjBHLOa (ORCPT ); Wed, 8 Feb 2023 06:14:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E018E241C2 for ; Wed, 8 Feb 2023 03:14:29 -0800 (PST) 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 99662B81BA8 for ; Wed, 8 Feb 2023 11:14:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF0DEC433EF; Wed, 8 Feb 2023 11:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854867; bh=p5TTPOpWMWq5eEE+GU3lcGME3666+d2rAuul7YL7CAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zxvfNV5WPLQBgbzqn565uqsBJEha3bjIJ5kSEq+28IuUCP0JrWAIhot3mKdaAKJSP KJpOp1EwcJtemoqN5NAvNfdXal4jThM+crHRrpOt7CM8DNrs+RzR2NGCxPxP9we473 8tMTGcCS38FhWcKV7n8dW+AU1VDXJYtscfR2XvYE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 04/21] driver core: bus: convert bus_create/remove_file to be constant Date: Wed, 8 Feb 2023 12:13:13 +0100 Message-Id: <20230208111330.439504-5-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208111330.439504-1-gregkh@linuxfoundation.org> References: <20230208111330.439504-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2643; i=gregkh@linuxfoundation.org; h=from:subject; bh=p5TTPOpWMWq5eEE+GU3lcGME3666+d2rAuul7YL7CAE=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm681v7OQLHOfuedP5eplAjdjXf+pxnafPv7tgaDCIuNS /ntmHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjARD0WGBY2J+16cZuhnmqX1l2068+ 7k8/+cdzEs2Je5X9BvT8nnq+tCU4oTfbi5t/TsAQA= 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 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?1757261387240514674?= X-GMAIL-MSGID: =?utf-8?q?1757261387240514674?= bus_create_file() and bus_remove_file() can be made to take a constant bus pointer, as it should not be modifying anything in the bus structure. Make this change and move the functions to use the internal subsys_get/put() logic as well, to prevent the use of the back-pointer in struct bus_type. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 28 +++++++++++++++++----------- include/linux/device/bus.h | 5 ++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 7949302663f9..8debbe00b4ca 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -175,24 +175,30 @@ static const struct sysfs_ops bus_sysfs_ops = { .store = bus_attr_store, }; -int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) +int bus_create_file(const struct bus_type *bus, struct bus_attribute *attr) { + struct subsys_private *sp = bus_to_subsys(bus); int error; - if (bus_get(bus)) { - error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); - bus_put(bus); - } else - error = -EINVAL; + + if (!sp) + return -EINVAL; + + error = sysfs_create_file(&sp->subsys.kobj, &attr->attr); + + subsys_put(sp); return error; } EXPORT_SYMBOL_GPL(bus_create_file); -void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) +void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr) { - if (bus_get(bus)) { - sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); - bus_put(bus); - } + struct subsys_private *sp = bus_to_subsys(bus); + + if (!sp) + return; + + sysfs_remove_file(&sp->subsys.kobj, &attr->attr); + subsys_put(sp); } EXPORT_SYMBOL_GPL(bus_remove_file); diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index f0c8bf91b07a..f6537f5fc535 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -135,9 +135,8 @@ struct bus_attribute { #define BUS_ATTR_WO(_name) \ struct bus_attribute bus_attr_##_name = __ATTR_WO(_name) -extern int __must_check bus_create_file(struct bus_type *, - struct bus_attribute *); -extern void bus_remove_file(struct bus_type *, struct bus_attribute *); +int __must_check bus_create_file(const struct bus_type *bus, struct bus_attribute *attr); +void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr); /* Generic device matching functions that all busses can use to match with */ int device_match_name(struct device *dev, const void *name);