From patchwork Wed Sep 15 23:01:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12497713 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77106C433F5 for ; Wed, 15 Sep 2021 23:01:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53BD660234 for ; Wed, 15 Sep 2021 23:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232740AbhIOXCu (ORCPT ); Wed, 15 Sep 2021 19:02:50 -0400 Received: from mail-lf1-f53.google.com ([209.85.167.53]:35416 "EHLO mail-lf1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbhIOXCu (ORCPT ); Wed, 15 Sep 2021 19:02:50 -0400 Received: by mail-lf1-f53.google.com with SMTP id m3so8870059lfu.2 for ; Wed, 15 Sep 2021 16:01:30 -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:mime-version :content-transfer-encoding; bh=CEaTlQvNZpRF49/gdrsx+pw4YoE0fPAtiHHb2K0ZQps=; b=t/OvYzvEWgUlyOylROv1OlNj/KTKwKQS1pIe6Oo1gGDM5xWRSzz2iIBvB5qj3rkjB2 SrDnd64jmDZYdti4rb0PM6TqQTieYP1fhdZ+DXUm/df2rfCaEXLi70APQ9cXRCj7gSa6 H3L4/+uCqCRtG2942mHIQzkZaW6BsJhNNfgZQIEXjKUXTJwqCuCjsrhKS+SSSlYdTXZG kwojXqOagBJANrGdDWmABo5Yy6zF9sW8OiarirS80dTs8CNvUPSoAsBYQMarlMAY2MKN kDZm/FOFzFkTgC3c1Q8mltQUACEUY01Khlj49M2agvdsT93MMoZ2GZSAfhZaCw5Gn5Jy PCdQ== X-Gm-Message-State: AOAM5300HoOkZLmQlr2Mb3vbe4xDwoNREo6TivDiI6naay0nGK//Bh/s wLzfVZ5eYi029sxMAHmQSrVhOcbtoC4= X-Google-Smtp-Source: ABdhPJxlmpXlzlgfoQcXm+pgGKTknCtXHe8w8UaMsiACFebo1gaTl3sOgmSpaozdz89RjLJvIernwg== X-Received: by 2002:a05:651c:510:: with SMTP id o16mr2158708ljp.257.1631746889685; Wed, 15 Sep 2021 16:01:29 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id d15sm107386lfn.220.2021.09.15.16.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 16:01:29 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Lorenzo Pieralisi , Kishon Vijay Abraham I , linux-pci@vger.kernel.org Subject: [PATCH v3 1/3] PCI/sysfs: Check CAP_SYS_ADMIN before parsing user input Date: Wed, 15 Sep 2021 23:01:25 +0000 Message-Id: <20210915230127.2495723-1-kw@linux.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Check if the "CAP_SYS_ADMIN" capability flag is set before parsing user input as it makes more sense to first check whether the current user actually has the right permissions before accepting any input from such user. This will also make order in which enable_store() and msi_bus_store() perform the "CAP_SYS_ADMIN" capability check consistent with other PCI-related sysfs objects that first verify whether user has this capability set. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 7fb5cd17cc98..6832e161be1c 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -273,15 +273,16 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr, { struct pci_dev *pdev = to_pci_dev(dev); unsigned long val; - ssize_t result = kstrtoul(buf, 0, &val); - - if (result < 0) - return result; + ssize_t result; /* this can crash the machine when done on the "wrong" device */ if (!capable(CAP_SYS_ADMIN)) return -EPERM; + result = kstrtoul(buf, 0, &val); + if (result < 0) + return result; + device_lock(dev); if (dev->driver) result = -EBUSY; @@ -378,12 +379,12 @@ static ssize_t msi_bus_store(struct device *dev, struct device_attribute *attr, struct pci_bus *subordinate = pdev->subordinate; unsigned long val; - if (kstrtoul(buf, 0, &val) < 0) - return -EINVAL; - if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (kstrtoul(buf, 0, &val) < 0) + return -EINVAL; + /* * "no_msi" and "bus_flags" only affect what happens when a driver * requests MSI or MSI-X. They don't affect any drivers that have From patchwork Wed Sep 15 23:01:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12497717 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BE34C433FE for ; Wed, 15 Sep 2021 23:01:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 217896058D for ; Wed, 15 Sep 2021 23:01:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232774AbhIOXCw (ORCPT ); Wed, 15 Sep 2021 19:02:52 -0400 Received: from mail-lf1-f46.google.com ([209.85.167.46]:37742 "EHLO mail-lf1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232749AbhIOXCv (ORCPT ); Wed, 15 Sep 2021 19:02:51 -0400 Received: by mail-lf1-f46.google.com with SMTP id i4so10716019lfv.4 for ; Wed, 15 Sep 2021 16:01:32 -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=o1wd9u9NtMuNJTtZ+hxyzrxw9BDui1QkYVbkYr2sajc=; b=Zk6bKRZzPJmZeWR5I0rw1UPPNHkLA/66fgiimoj64+yh8i+Ga9WjNVV1rc/UAxbKNj w7SyEvX3x3TCUESyCLr5jAwIZVSAotbd0NTEJN1kYUTxJRNBQIwEOaTzXq2ke//GxX9S n5kChGsBAf/spG2GwANxbL2J26NyzSKF3nZCXEmKwFvFfKhvz3en9wjqh6yZ1hssSXLX ULRFXqjTPgSG2cKw+97VThtebKI8j67Txy0Iy9qzxXR4cSiaCcFNZqPHl45e+v8sFUwn DFRfSIjQJl5jifcZzXVF6sHIpOCb58eH2NvPhZjbji3/u01Odxafk1telewH4eeZ/oi/ iRWw== X-Gm-Message-State: AOAM531g+FZNNwjQ/NpX6FuUDxfmmmRZADqu/ja9S2ZICSHo57fmqqBE BJ3iBHGJF7rmvmeP4ILD6a2k7RBft/8= X-Google-Smtp-Source: ABdhPJzRw10gVH+ce31L58lNXqCQ8tYveVMgak9tjzjHWh1SO5NYFZNM2HQGY9jvb1MTLm7u8hInAg== X-Received: by 2002:a2e:9bc7:: with SMTP id w7mr2148673ljj.379.1631746891089; Wed, 15 Sep 2021 16:01:31 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id d15sm107386lfn.220.2021.09.15.16.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 16:01:30 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Lorenzo Pieralisi , Kishon Vijay Abraham I , linux-pci@vger.kernel.org Subject: [PATCH v3 2/3] PCI/sysfs: Return -EINVAL consistently from "store" functions Date: Wed, 15 Sep 2021 23:01:26 +0000 Message-Id: <20210915230127.2495723-2-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210915230127.2495723-1-kw@linux.com> References: <20210915230127.2495723-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org At the moment, most of the "store" functions that handle input from the userspace via the sysfs objects commonly returns the -EINVAL error code should the value provided fail validation and/or type conversion. This error code is a clear message to the userspace that the provided value is not a valid input. However, some of the "show" functions return the error code as-is as returned from the helper functions used to parse the input value, and in which case the error code can be either -EINVAL or -ERANGE. The former would often be a return from the kstrtobool() function and the latter will most likely be originating from other kstr*() functions family such as e.g., kstrtou8(), kstrtou32(), kstrtoint(), etc. The -EINVAL is commonly returned as the error code to indicate that the value provided is invalid, and the -ERANGE code is not very useful in the userspace, thus normalize the return error code to be -EINVAL for when the validation and/or type conversion fails. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/endpoint/functions/pci-epf-ntb.c | 18 ++++------ drivers/pci/endpoint/pci-ep-cfs.c | 35 +++++++------------- drivers/pci/iov.c | 14 ++++---- drivers/pci/pci-sysfs.c | 20 +++++------ 4 files changed, 33 insertions(+), 54 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/endpoint/functions/pci-epf-ntb.c index 8b4756159f15..e67489144349 100644 --- a/drivers/pci/endpoint/functions/pci-epf-ntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-ntb.c @@ -1947,11 +1947,9 @@ static ssize_t epf_ntb_##_name##_store(struct config_item *item, \ struct config_group *group = to_config_group(item); \ struct epf_ntb *ntb = to_epf_ntb(group); \ u32 val; \ - int ret; \ \ - ret = kstrtou32(page, 0, &val); \ - if (ret) \ - return ret; \ + if (kstrtou32(page, 0, &val) < 0) \ + return -EINVAL; \ \ ntb->_name = val; \ \ @@ -1980,11 +1978,9 @@ static ssize_t epf_ntb_##_name##_store(struct config_item *item, \ struct device *dev = &ntb->epf->dev; \ int win_no; \ u64 val; \ - int ret; \ \ - ret = kstrtou64(page, 0, &val); \ - if (ret) \ - return ret; \ + if (kstrtou64(page, 0, &val) < 0) \ + return -EINVAL; \ \ if (sscanf(#_name, "mw%d", &win_no) != 1) \ return -EINVAL; \ @@ -2005,11 +2001,9 @@ static ssize_t epf_ntb_num_mws_store(struct config_item *item, struct config_group *group = to_config_group(item); struct epf_ntb *ntb = to_epf_ntb(group); u32 val; - int ret; - ret = kstrtou32(page, 0, &val); - if (ret) - return ret; + if (kstrtou32(page, 0, &val) < 0) + return -EINVAL; if (val > MAX_MW) return -EINVAL; diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index 999911801877..19bc0e828c0c 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -175,9 +175,8 @@ static ssize_t pci_epc_start_store(struct config_item *item, const char *page, epc = epc_group->epc; - ret = kstrtobool(page, &start); - if (ret) - return ret; + if (kstrtobool(page, &start) < 0) + return -EINVAL; if (!start) { pci_epc_stop(epc); @@ -329,13 +328,11 @@ static ssize_t pci_epf_##_name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ u32 val; \ - int ret; \ struct pci_epf *epf = to_pci_epf_group(item)->epf; \ if (WARN_ON_ONCE(!epf->header)) \ return -EINVAL; \ - ret = kstrtou32(page, 0, &val); \ - if (ret) \ - return ret; \ + if (kstrtou32(page, 0, &val) < 0) \ + return -EINVAL; \ epf->header->_name = val; \ return len; \ } @@ -345,13 +342,11 @@ static ssize_t pci_epf_##_name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ u16 val; \ - int ret; \ struct pci_epf *epf = to_pci_epf_group(item)->epf; \ if (WARN_ON_ONCE(!epf->header)) \ return -EINVAL; \ - ret = kstrtou16(page, 0, &val); \ - if (ret) \ - return ret; \ + if (kstrtou16(page, 0, &val) < 0) \ + return -EINVAL; \ epf->header->_name = val; \ return len; \ } @@ -361,13 +356,11 @@ static ssize_t pci_epf_##_name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ u8 val; \ - int ret; \ struct pci_epf *epf = to_pci_epf_group(item)->epf; \ if (WARN_ON_ONCE(!epf->header)) \ return -EINVAL; \ - ret = kstrtou8(page, 0, &val); \ - if (ret) \ - return ret; \ + if (kstrtou8(page, 0, &val) < 0) \ + return -EINVAL; \ epf->header->_name = val; \ return len; \ } @@ -376,11 +369,9 @@ static ssize_t pci_epf_msi_interrupts_store(struct config_item *item, const char *page, size_t len) { u8 val; - int ret; - ret = kstrtou8(page, 0, &val); - if (ret) - return ret; + if (kstrtou8(page, 0, &val) < 0) + return -EINVAL; to_pci_epf_group(item)->epf->msi_interrupts = val; @@ -398,11 +389,9 @@ static ssize_t pci_epf_msix_interrupts_store(struct config_item *item, const char *page, size_t len) { u16 val; - int ret; - ret = kstrtou16(page, 0, &val); - if (ret) - return ret; + if (kstrtou16(page, 0, &val) < 0) + return -EINVAL; to_pci_epf_group(item)->epf->msix_interrupts = val; diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index dafdc652fcd0..0267977c9f17 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -183,11 +183,10 @@ static ssize_t sriov_vf_msix_count_store(struct device *dev, { struct pci_dev *vf_dev = to_pci_dev(dev); struct pci_dev *pdev = pci_physfn(vf_dev); - int val, ret; + int val, ret = 0; - ret = kstrtoint(buf, 0, &val); - if (ret) - return ret; + if (kstrtoint(buf, 0, &val) < 0) + return -EINVAL; if (val < 0) return -EINVAL; @@ -376,12 +375,11 @@ static ssize_t sriov_numvfs_store(struct device *dev, const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - int ret; + int ret = 0; u16 num_vfs; - ret = kstrtou16(buf, 0, &num_vfs); - if (ret < 0) - return ret; + if (kstrtou16(buf, 0, &num_vfs) < 0) + return -EINVAL; if (num_vfs > pci_sriov_get_totalvfs(pdev)) return -ERANGE; diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 6832e161be1c..a092fc0c665d 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -273,15 +273,14 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr, { struct pci_dev *pdev = to_pci_dev(dev); unsigned long val; - ssize_t result; + ssize_t result = 0; /* this can crash the machine when done on the "wrong" device */ if (!capable(CAP_SYS_ADMIN)) return -EPERM; - result = kstrtoul(buf, 0, &val); - if (result < 0) - return result; + if (kstrtoul(buf, 0, &val) < 0) + return -EINVAL; device_lock(dev); if (dev->driver) @@ -313,14 +312,13 @@ static ssize_t numa_node_store(struct device *dev, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - int node, ret; + int node; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - ret = kstrtoint(buf, 0, &node); - if (ret) - return ret; + if (kstrtoint(buf, 0, &node) < 0) + return -EINVAL; if ((node < 0 && node != NUMA_NO_NODE) || node >= MAX_NUMNODES) return -EINVAL; @@ -1340,10 +1338,10 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr, { struct pci_dev *pdev = to_pci_dev(dev); unsigned long val; - ssize_t result = kstrtoul(buf, 0, &val); + ssize_t result; - if (result < 0) - return result; + if (kstrtoul(buf, 0, &val) < 0) + return -EINVAL; if (val != 1) return -EINVAL; From patchwork Wed Sep 15 23:01:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12497715 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41A7BC4332F for ; Wed, 15 Sep 2021 23:01:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D7A260234 for ; Wed, 15 Sep 2021 23:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232733AbhIOXCx (ORCPT ); Wed, 15 Sep 2021 19:02:53 -0400 Received: from mail-lf1-f52.google.com ([209.85.167.52]:35425 "EHLO mail-lf1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbhIOXCw (ORCPT ); Wed, 15 Sep 2021 19:02:52 -0400 Received: by mail-lf1-f52.google.com with SMTP id m3so8870412lfu.2 for ; Wed, 15 Sep 2021 16:01:32 -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=26ouncjbdif/NlFpToD8aoYp3QL4ipoKM+I1PaYnEss=; b=WtP9bVNmV/tRZXm/mEBJv71JzCCyZsvZq+T4vhzBZ8kcRJQhJlcsJlOz3c2x3A7BFr 4iflNNT8H+P/ODUGMshmSULojQPSJDvet5dcy0u2bj+PpdoQxrla5Kzn+sOgfqFGcKjA Wd64jh4KMspilYYqoXc2lxihQbqISV3Ylw4qQOTvnnfpvekLF0OorRfqwWDgoafEMzCv qVaxTjGNXUqxOaPOLtmeKt5eWzl9GD/qLS4DlVx7vcL23HkbPHo4ehCSt/xVvmykx7fO rSd8twCj5wKijneJO9geRSaNOIoknqN19T8KkgMsYoQVn7N6SuLK+TxSPWwLML6O9Typ vOlA== X-Gm-Message-State: AOAM532h9V/M4SIlNjlHzepZJz/S2QcbnQx1wKsxr5GgbO95WO7CBPsu vZwDbpAM6gzGF/1yEeaxfAg= X-Google-Smtp-Source: ABdhPJwD2a49I/M0+MHGoSSxmz/EYyLS66FMKWZNMYEG9A1uuBJDucRNcJf4SKqdZbFTSTAcHqClYA== X-Received: by 2002:a05:6512:a82:: with SMTP id m2mr1845599lfu.66.1631746892193; Wed, 15 Sep 2021 16:01:32 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id d15sm107386lfn.220.2021.09.15.16.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 16:01:31 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Lorenzo Pieralisi , Kishon Vijay Abraham I , linux-pci@vger.kernel.org Subject: [PATCH v3 3/3] PCI: Don't use the strtobool() wrapper for kstrtobool() Date: Wed, 15 Sep 2021 23:01:27 +0000 Message-Id: <20210915230127.2495723-3-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210915230127.2495723-1-kw@linux.com> References: <20210915230127.2495723-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The strtobool() function is a wrapper over the kstrtobool() function that has been added for backward compatibility. There is no reason to use the old API, thus rather than using the wrapper use the kstrtobool() directly. Related: commit ef951599074b ("lib: move strtobool() to kstrtobool()") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/p2pdma.c | 6 +++--- drivers/pci/pcie/aspm.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 50cdde3e9a8b..4fccdcf9186f 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -943,7 +943,7 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_unmap_sg_attrs); * * Parses an attribute value to decide whether to enable p2pdma. * The value can select a PCI device (using its full BDF device - * name) or a boolean (in any format strtobool() accepts). A false + * name) or a boolean (in any format kstrtobool() accepts). A false * value disables p2pdma, a true value expects the caller * to automatically find a compatible device and specifying a PCI device * expects the caller to use the specific provider. @@ -975,11 +975,11 @@ int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev, } else if ((page[0] == '0' || page[0] == '1') && !iscntrl(page[1])) { /* * If the user enters a PCI device that doesn't exist - * like "0000:01:00.1", we don't want strtobool to think + * like "0000:01:00.1", we don't want kstrtobool to think * it's a '0' when it's clearly not what the user wanted. * So we require 0's and 1's to be exactly one character. */ - } else if (!strtobool(page, use_p2pdma)) { + } else if (!kstrtobool(page, use_p2pdma)) { return 0; } diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 013a47f587ce..52c74682601a 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1219,7 +1219,7 @@ static ssize_t aspm_attr_store_common(struct device *dev, struct pcie_link_state *link = pcie_aspm_get_link(pdev); bool state_enable; - if (strtobool(buf, &state_enable) < 0) + if (kstrtobool(buf, &state_enable) < 0) return -EINVAL; down_read(&pci_bus_sem); @@ -1276,7 +1276,7 @@ static ssize_t clkpm_store(struct device *dev, struct pcie_link_state *link = pcie_aspm_get_link(pdev); bool state_enable; - if (strtobool(buf, &state_enable) < 0) + if (kstrtobool(buf, &state_enable) < 0) return -EINVAL; down_read(&pci_bus_sem);