lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 11 Nov 2022 22:27:19 +0800
From:   "Longpeng(Mike)" <longpeng2@...wei.com>
To:     <bhelgaas@...gle.com>
CC:     <linux-pci@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <jianjay.zhou@...wei.com>, <zhuangshengen@...wei.com>,
        <arei.gonglei@...wei.com>, <yechuan@...wei.com>,
        <huangzhichao@...wei.com>, <xiehong@...wei.com>,
        Longpeng <longpeng2@...wei.com>
Subject: [RFC 1/4] pci/sriov: extract sriov_numvfs common helper

From: Longpeng <longpeng2@...wei.com>

Extract a common helper to set sriov nums.

Signed-off-by: Longpeng <longpeng2@...wei.com>
---
 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);
 }
 
-/*
- * num_vfs > 0; number of VFs to enable
- * num_vfs = 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 = to_pci_dev(dev);
 	int ret = 0;
-	u16 num_vfs;
-
-	if (kstrtou16(buf, 0, &num_vfs) < 0)
-		return -EINVAL;
 
 	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);
 
+	return ret;
+}
+
+/*
+ * num_vfs > 0; number of VFs to enable
+ * num_vfs = 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 = to_pci_dev(dev);
+	int ret;
+	u16 num_vfs;
+
+	if (kstrtou16(buf, 0, &num_vfs) < 0)
+		return -EINVAL;
+
+	ret = sriov_numvfs_common(pdev, num_vfs);
 	if (ret < 0)
 		return ret;
 
-- 
2.23.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ