Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3500233pxb; Mon, 4 Apr 2022 18:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSCMNVyqBGQRUDiGabXGcjFDm9738plTWwcVvs4RECvjEP+C2MXmkgFawsIVFTzo9QdYyY X-Received: by 2002:a63:86c1:0:b0:397:ffaa:1eaa with SMTP id x184-20020a6386c1000000b00397ffaa1eaamr875046pgd.382.1649123981482; Mon, 04 Apr 2022 18:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649123981; cv=none; d=google.com; s=arc-20160816; b=Tt3bOP0pFyiawxQAdqBOHiEOkxtHmIiUZlT/Z3kV6UT4GUGqq03SyGc/BM8rLzqmS1 hCNSOIzfzkCblBPztbaayxowGKLEAB9ktgdPKqm9dLp84qa/VqCEfo6IzmQ0monKzWM4 6ihqDGKzLdBvI+FV1+O5DIAUBD4Z2OofxSoIncK/TvUenejY6fjKtC0v6hvOtFSy82He TP3MVdl7JsxJ9TOg9PZScYdvW1sEcXBAEMdezjMDWP0+bEADrhGvxwb5owbx/uPTOJLx gPsM6fM4UGNlID9cpTm0YTw4pt7d+3AzlsyOhrpiz8DlQw74/9koVwMx8tDHPM5uQCnD i4lw== 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=mHITSW/sgmw/Csyhuirx5ijnYnrGvi4Rk0KXIhii9OU=; b=ziHyon2e7SvXdXdrdlmFIjJ7sFaqLi36jH2mwcx73Zq8z5OWG35j5bzlulyXvBvcS8 JWQhXsbgCBnQJWBFJyt03cw6QikubtINZJU2xKC0jvseqAc6DD3XgQ3lhCIrAxgiPHsZ d3Nls09roHPqLWQ4OoA+FCV1RmL1R9vM8AvKBynKuqNkDtroCinFQWn9tf4h9aZgV/QS F5YAPgijXYW57VyPJ+s6ZKTcHZ/yeI06UBottrHSQvQ7R7XlNjWI71HhO7SOhupyX5He PUbxulSlJMydgdsmHdALxGzdJjUklDia6Ep/ptTZGFynYgC/4IfSipJZ9QHKMATFojP8 YfsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wXR8rp03; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h38-20020a631226000000b003816043eea5si11191831pgl.154.2022.04.04.18.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 18:59:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wXR8rp03; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3793813924C; Mon, 4 Apr 2022 18:05:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359868AbiDCSkg (ORCPT + 99 others); Sun, 3 Apr 2022 14:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356512AbiDCSkY (ORCPT ); Sun, 3 Apr 2022 14:40:24 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A30E39B8A for ; Sun, 3 Apr 2022 11:38:23 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id c7so11517235wrd.0 for ; Sun, 03 Apr 2022 11:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mHITSW/sgmw/Csyhuirx5ijnYnrGvi4Rk0KXIhii9OU=; b=wXR8rp03DHc5wiUfBVAB5Nuh3XfnaYvUKqmtsWXgN+spI327pZeGN4sfFkdlAQO76M 2Cq4PgoxUbVzR/c9uRlXxz3+QdKUn/21Wzs/zg2COGsRcw1TRvCt0E5f9P+PkVHqjkIF 5Z76p+imRzuTlBLLDQ4l3jK+NlPnSdBryKK85hZDKBO3WnYbq5zwPHKx5DfZjuhQ9frO S3PY5QFr5UDBVY0KyfpgE5rFn2xr2i2goIgkSwFjKbQy5Q6+DDtCUKaI752vs/DB6ull LkXlxwq1hvPpFZCtBRdrxC90gtIPXgjfEPN4yaWbYrGQdjQBBZpMFI1q0uaCqYVzm0pN yxng== 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=mHITSW/sgmw/Csyhuirx5ijnYnrGvi4Rk0KXIhii9OU=; b=4bdCc5epBSR/aN6DJ/PVVBA5iZr1LG7HhyC4+e6beBBHuapolicz/dXlaCqfRkYA4r fqU+UKlpCJr62J24mppqQ5YMinNrKVGh5EVzCkTBvYD4boCOsc3tCUY7b5aZ49tjVmVd XrraqKPEpSi03JBLxqEKhM7t6cITx5VAboSOOWNcU4pN70rgPFmFUOUfO58Aw2r2KH+C uUvU88G+vNr4ZIf79r0DJylLtK/8zg6IZS9gTlJU/d5AC6tA+mpbTKpYC2KivNBbsHy3 meFbz/pfHl63GhEhsbTmwGcJxJSA/5W7MdCJJOsA/lUYJ/LVcJrMoj0vHwLV6j66vFYK XRSA== X-Gm-Message-State: AOAM530lrb+/IxDXIL/eG+nA1gGLLsPi4YpVb6ot9wd1LRZEnKoJvyUs mI4ne4JWjcfuSdUN/MTQqm4xFA== X-Received: by 2002:adf:90cf:0:b0:205:fdb4:92d1 with SMTP id i73-20020adf90cf000000b00205fdb492d1mr8369733wri.468.1649011102158; Sun, 03 Apr 2022 11:38:22 -0700 (PDT) Received: from localhost.localdomain (xdsl-188-155-201-27.adslplus.ch. [188.155.201.27]) by smtp.gmail.com with ESMTPSA id l28-20020a05600c1d1c00b0038e72a95ec4sm593851wms.13.2022.04.03.11.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Apr 2022 11:38:21 -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 v6 05/12] PCI: Use driver_set_override() instead of open-coding Date: Sun, 3 Apr 2022 20:37:51 +0200 Message-Id: <20220403183758.192236-6-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> References: <20220403183758.192236-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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 c263ffc5884a..fc804e08e3cb 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 60adf42460ab..844d38f589cf 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 */ -- 2.32.0