From patchwork Wed Mar 16 15:05:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12782837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 722DEC433FE for ; Wed, 16 Mar 2022 15:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QbpvxWpSrxRjYl9kN7E94C3auatMaOT7CkCusG5K9Es=; b=bC+c1hCFk2fCVh O0fhs2I9yeVglsJN4TZABn8IhyQeRqQUNV0O52esPLRwP3p4lbHJo6nGzgoB5stspUw3gIwcG/v0M uqqD2dtADr9ytgfD5gwUXdurkB+lAbExdouDMspIPHtx7pzTa60HeHD/Ou2S4620/S0mb6cnzy6+I cf8H2qKqwLnXJv7TXwqZc2RysyAWEGJQ1jrOGII2YsPxBdB7GnOh2yEM4saEvVc6NWkXn3zzAR4Cg rxoSzUygQ1NboEHlQkz6UcN73RD9yotOQfXbJbfa+93kCTZdgSDMrRqgNhBV3GPCuueJyy8tccQ4h AFAHNkVOkJ47uRNf8HdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVG0-00DPjZ-2A; Wed, 16 Mar 2022 15:08:12 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUVEj-00DPBv-1K for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 15:06:54 +0000 Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) (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 C502B3F4CC for ; Wed, 16 Mar 2022 15:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1647443211; bh=JNKVE+3JexqhZeL95jpZ7AxMh5V3BiZd1u/ZcabQDj4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZDYVsdhzekWMwPPkB5MTx7wYc7GzLqdZuCTeR1xXWl2OuCDYjmCaUj4t1d4EZU0pK gMt6+G6dpyh8C1c1T1sBtXPLkDfIwZYUoG4pEYyCWebSWoRQQA0S3grju3YcFkFfA8 Oy/1fyEz4b3NNXQn7nDpQUaiUtOvIoeGtq4dhMOXMQu8G/lbUsIglk4FJqd8/XMEZe af6lK/wZZGErlZcup0PYKcyEFk/NJR2TqDq7RLSgjmsJartr3FuA3LMDqEiSjHghXD ff5PbKDM7ACD4OubQx6rP3X/rffNQYzq0va4kIJWxUkizp7FTIiLqHY1pHZjunqrlS RIcchHiAsL71A== Received: by mail-lj1-f197.google.com with SMTP id f21-20020a2e9515000000b00247e2f244easo1013193ljh.19 for ; Wed, 16 Mar 2022 08:06:51 -0700 (PDT) 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=JNKVE+3JexqhZeL95jpZ7AxMh5V3BiZd1u/ZcabQDj4=; b=nGFCWIyeqs5JY4Fe29nl6Nq7l9cPD/K13C1YUVv0MsqWNJklFj+Os9ct1Eqs9aL7Us U+3iKE/srUjMW1radqJGbiVtOTUfT+ksPdD/hyRt7a87W3FQ3cV2iUMR4ORBRgrHXKCz gFHHoKjsv0Cgfpj+GjU6DHE1z9B+jDw55JRHU6MVbalBNme7rotV8/iACacvNmVm3FUR jK+wkxoF/0V+6Tr2Rk88mb9KJUYR8PrD+GGoxloBaXyqhYqGySM2cq3T4uCDYmPuceaZ mghZkaPkjVuD045t/AmlLqHzKoANHqg5iPyBHTH4BD2gLrorrLScGY8ha2KxPECjdtVg O+xg== X-Gm-Message-State: AOAM531WhxYeQKaLgUWyGrIIz8MbqXjjUv+FECDAzERGBhZmoNTlWg/2 7pHHRuo09uq2UZR05UwoX0YuorCZsfIws6wL1A40fY9MN0aZ3z9xxyEyFKoPHiZ8RR07nDfIY4F l/sYItbbSE37M9JlaN+24SDLCo1ypJX5unrxIf3dvM93IwKHjPRWm X-Received: by 2002:adf:e6c7:0:b0:1ed:9f7c:c99e with SMTP id y7-20020adfe6c7000000b001ed9f7cc99emr338962wrm.0.1647443200062; Wed, 16 Mar 2022 08:06:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCUhxAKawe3MPuphaitMx3nXTnkxh9V6g1RJgrcVXBEtRF7kgts/Kf4MtPXL4nFMNuuGjZig== X-Received: by 2002:adf:e6c7:0:b0:1ed:9f7c:c99e with SMTP id y7-20020adfe6c7000000b001ed9f7cc99emr338940wrm.0.1647443199883; Wed, 16 Mar 2022 08:06:39 -0700 (PDT) Received: from localhost.localdomain (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id p14-20020a5d59ae000000b00203dcc87d39sm3130155wrr.54.2022.03.16.08.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:06:38 -0700 (PDT) From: Krzysztof Kozlowski To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Stuart Yoder , "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 , 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 , Rasmus Villemoes , Andy Shevchenko , Krzysztof Kozlowski Subject: [PATCH v5 05/11] PCI: Use driver_set_override() instead of open-coding Date: Wed, 16 Mar 2022 16:05:27 +0100 Message-Id: <20220316150533.421349-6-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> References: <20220316150533.421349-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_080653_275880_A3EA500B X-CRM114-Status: GOOD ( 19.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use a helper to set driver_override to the 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 Acked-by: Bjorn Helgaas Reviewed-by: Andy Shevchenko --- drivers/pci/pci-sysfs.c | 28 ++++------------------------ include/linux/pci.h | 6 +++++- 2 files changed, 9 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 b957eeb89c7a..5ecbb845aa21 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -516,7 +516,11 @@ 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 */