Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1975724pxm; Sun, 27 Feb 2022 07:58:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyc6VZHesUGuZGGJB56kIHqsRn/+AP+cdoBoHiHdgE7vZ8ZO0Ag2R1OA/sO/mVQc3i7yN+y X-Received: by 2002:a63:5f42:0:b0:373:d440:496e with SMTP id t63-20020a635f42000000b00373d440496emr14084795pgb.529.1645977528394; Sun, 27 Feb 2022 07:58:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645977528; cv=none; d=google.com; s=arc-20160816; b=GGLH01Qkq0F4dJ4+vRfJzXFbRw8B+BEeXy4S4Q1ePif+NSNJRTAIRkcgOGuJZW7fLC q8/CNBCrpMAwb8+9F2PSdD12ypKDXjTJ80+BR6ktPeJLOwZNsjAn0RNao/woXEIauiRy AGDZ9kacG4EKM8n7h2ZNIsE0UsHq0oHa5Aujx3YPU1tRf8xhVZPrU4pQ1xjQxhZxKWLv EtqAnDNNhM3ENukAl7bGNOXuuRnvXwh5ekjjq4iL9xPykcYg45mVB3Oo+wcbcoEuf4oj MCzjgndt1n/YyHT6LbOR1hIkC7/8tKvWrwy7dgd1AsyIQIUkZ1i7ro08w1FzGsZOtAca H8dw== 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=ovOgd1VJlKyRzMY+TlP34IMSMGHGw8uakjQlL885+iI=; b=gfiXWOOQDqeOrVTci72KW6ftvqHsjJhhf8u5REwfqHTXfNqZHo9IPqLAXk9FQ0UUbP 1l3b/NxvUf5LzRlM6lQj3vYIrdvDBdra3o2YG9qTbHVZN4DuDDyLNK1N0d7KyzHfKYwC I6TSZlSx1yjz9jQbxhTYGBq1Yg7fc8Y+EbDR33zfQYlPdl+NVBPQiWL3p0jZEKn4QAo5 7cdeohT5r1oDRUwO2TnAUaoT8NgcKUeSuMAvrHv/FRajd2aBmsxIWcU8vSoYPOTW1zWB QUYthCerUCNoepXdgMBBCzDWL8QM2AHDR0kYGl2CJ1XD7HrYjE64XIgTa7E4oKYapk5n r17w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=mLrt+Mrl; 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=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170902968600b0014ff5ffaf93si7006531plp.523.2022.02.27.07.58.32; Sun, 27 Feb 2022 07:58:48 -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=@canonical.com header.s=20210705 header.b=mLrt+Mrl; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbiB0Nxd (ORCPT + 99 others); Sun, 27 Feb 2022 08:53:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbiB0Nx3 (ORCPT ); Sun, 27 Feb 2022 08:53:29 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04183E086 for ; Sun, 27 Feb 2022 05:52:49 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 0238040304 for ; Sun, 27 Feb 2022 13:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645969960; bh=ovOgd1VJlKyRzMY+TlP34IMSMGHGw8uakjQlL885+iI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mLrt+MrlGPeM7hEUM0D8DQEf2yXP7SeWz4tokcBNATpGtcWl8G/xNDsEstT/UFfsQ t4Fkxhy3MmQ6W8st+BwoMkxBZZOaCJTvZ6Brjsjmro8e5qCtGEA57hOhdy4AvhaD9J ePMXfbXlfj5cAEmz9uizyxqRxllfTSYyg5CMPxuZ6DWSp+r5CIWZTdGroDf2eCncpU U2sdztvkmGcVoFGbem7cA+iJQrMN9pYrOgSHKDF9wVC3a5FL7sAnRgdpo2/BD3BJr5 2PqvzKkRFo/nNWCF9hAnhL4DIFYKMYu1AuW4/RDg1Wejkf1XP7w5rTc0o4Skq58/tW O+3a0yysDQCtw== Received: by mail-ed1-f69.google.com with SMTP id h17-20020a05640250d100b004133863d836so4271216edb.0 for ; Sun, 27 Feb 2022 05:52:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ovOgd1VJlKyRzMY+TlP34IMSMGHGw8uakjQlL885+iI=; b=BfJRZbqF/lcB+R8XAioY0RHZyKT0zCf93vf2UbRaa9qpdr1wDpLS8p9AInzxBE22yr Fpg6RIa/0Mq7QvBu+4Ohsa1K/PYUd0K4vhLQZ9/spbiIGunFpnzmEXjlNzvuz+9rbeg6 tKtzMn6pE/BUJkhfglj7Y83qqTp+GtoTf4shlXoxT/0g53zC505+ZQQnQVsh4u3rCfGJ ZLN/WIPO1QF5TaBnap5RPFXypu1lUNxPhSNJPnZT2gI/gweFYUP+HyVhCWIIWYoC92oa xPcq8YdNx94X2zmEDJuuXV9okU8m7gtklTdidbVYI6P/YWU/ZsUaEVo3m6lD6/L+qSpm dZlg== X-Gm-Message-State: AOAM533PFHlncg3rXGK3LyAqCkZnVTcueYjtrnabPEzxUND9fI9wLK2I 1DoauZtOt/F4hwa75xp2A9FwkWA2fGLxnm7J6sx/mL4WvTtKFi/fcA/6HNMgRJho/aUmcqncECt XOTzzYAKJAXFarlOOBU14OIkdE/WCCR0EnFnUN9BtdA== X-Received: by 2002:a17:906:82cf:b0:6d0:3d6:8f27 with SMTP id a15-20020a17090682cf00b006d003d68f27mr11873366ejy.236.1645969959551; Sun, 27 Feb 2022 05:52:39 -0800 (PST) X-Received: by 2002:a17:906:82cf:b0:6d0:3d6:8f27 with SMTP id a15-20020a17090682cf00b006d003d68f27mr11873353ejy.236.1645969959366; Sun, 27 Feb 2022 05:52:39 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-181-108.adslplus.ch. [188.155.181.108]) by smtp.gmail.com with ESMTPSA id r22-20020a17090638d600b006d584aaa9c9sm3393333ejd.133.2022.02.27.05.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 05:52:38 -0800 (PST) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Stuart Yoder , Laurentiu Tudor , Abel Vesa , Shawn Guo , Sascha Hauer , Fabio Estevam , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Bjorn Helgaas , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Andy Gross , Srinivas Kandagatla , Mark Brown , "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, virtualization@lists.linux-foundation.org, Linus Torvalds Cc: Rasmus Villemoes , Krzysztof Kozlowski Subject: [PATCH v3 05/11] PCI: Use driver_set_override() instead of open-coding Date: Sun, 27 Feb 2022 14:52:08 +0100 Message-Id: <20220227135214.145599-6-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> References: <20220227135214.145599-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 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 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 Use a helper for seting driver_override to reduce amount of duplicated code. Make the driver_override field const char, because it is not modified by the core and it matches other subsystems. Signed-off-by: Krzysztof Kozlowski --- drivers/pci/pci-sysfs.c | 28 ++++------------------------ include/linux/pci.h | 7 ++++++- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 602f0fb0b007..5c42965c32c2 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -567,31 +567,11 @@ static ssize_t driver_override_store(struct device *dev, const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - char *driver_override, *old, *cp; - - /* We need to keep extra room for a newline */ - if (count >= (PAGE_SIZE - 1)) - return -EINVAL; - - driver_override = kstrndup(buf, count, GFP_KERNEL); - if (!driver_override) - return -ENOMEM; - - cp = strchr(driver_override, '\n'); - if (cp) - *cp = '\0'; - - device_lock(dev); - old = pdev->driver_override; - if (strlen(driver_override)) { - pdev->driver_override = driver_override; - } else { - kfree(driver_override); - pdev->driver_override = NULL; - } - device_unlock(dev); + int ret; - kfree(old); + ret = driver_set_override(dev, &pdev->driver_override, buf, count); + if (ret) + return ret; return count; } diff --git a/include/linux/pci.h b/include/linux/pci.h index 8253a5413d7c..5c00a8aebdf9 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -516,7 +516,12 @@ struct pci_dev { u16 acs_cap; /* ACS Capability offset */ phys_addr_t rom; /* Physical address if not from BAR */ size_t romlen; /* Length if not from BAR */ - char *driver_override; /* Driver name to force a match */ + /* + * Driver name to force a match. + * Do not set directly, because core frees it. + * Use driver_set_override() to set or clear it. + */ + const char *driver_override; unsigned long priv_flags; /* Private flags for the PCI driver */ -- 2.32.0