From nobody Mon Apr 13 13:15:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B12FC4332F for ; Fri, 11 Nov 2022 14:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234505AbiKKO1i (ORCPT ); Fri, 11 Nov 2022 09:27:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbiKKO1a (ORCPT ); Fri, 11 Nov 2022 09:27:30 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257E11AD; Fri, 11 Nov 2022 06:27:29 -0800 (PST) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N81Hg1GfHzmVpr; Fri, 11 Nov 2022 22:27:11 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi100025.china.huawei.com (7.221.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 22:27:26 +0800 From: "Longpeng(Mike)" To: CC: , , , , , , , , Longpeng Subject: [RFC 1/4] pci/sriov: extract sriov_numvfs common helper Date: Fri, 11 Nov 2022 22:27:19 +0800 Message-ID: <20221111142722.1172-2-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20221111142722.1172-1-longpeng2@huawei.com> References: <20221111142722.1172-1-longpeng2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi100025.china.huawei.com (7.221.188.158) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Longpeng Extract a common helper to set sriov nums. Signed-off-by: Longpeng --- drivers/pci/iov.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 952217572113..3b441cd92960 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -406,23 +406,9 @@ static ssize_t sriov_numvfs_show(struct device *dev, return sysfs_emit(buf, "%u\n", num_vfs); } =20 -/* - * num_vfs > 0; number of VFs to enable - * num_vfs =3D 0; disable all VFs - * - * Note: SRIOV spec does not allow partial VF - * disable, so it's all or none. - */ -static ssize_t sriov_numvfs_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int sriov_numvfs_common(struct pci_dev *pdev, u16 num_vfs) { - struct pci_dev *pdev =3D to_pci_dev(dev); int ret =3D 0; - u16 num_vfs; - - if (kstrtou16(buf, 0, &num_vfs) < 0) - return -EINVAL; =20 if (num_vfs > pci_sriov_get_totalvfs(pdev)) return -ERANGE; @@ -471,6 +457,28 @@ static ssize_t sriov_numvfs_store(struct device *dev, exit: device_unlock(&pdev->dev); =20 + return ret; +} + +/* + * num_vfs > 0; number of VFs to enable + * num_vfs =3D 0; disable all VFs + * + * Note: SRIOV spec does not allow partial VF + * disable, so it's all or none. + */ +static ssize_t sriov_numvfs_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev =3D to_pci_dev(dev); + int ret; + u16 num_vfs; + + if (kstrtou16(buf, 0, &num_vfs) < 0) + return -EINVAL; + + ret =3D sriov_numvfs_common(pdev, num_vfs); if (ret < 0) return ret; =20 --=20 2.23.0