]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/pci/pci-sysfs.c
atomisp: eliminate intel_mid_pm.h
[karo-tx-linux.git] / drivers / pci / pci-sysfs.c
index 066628776e1be62ec4fdfb2692bd15dbee7ab761..25d010d449a31408fe3058783eec32f0be92e3e4 100644 (file)
@@ -472,6 +472,7 @@ static ssize_t sriov_numvfs_store(struct device *dev,
                                  const char *buf, size_t count)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
+       struct pci_sriov *iov = pdev->sriov;
        int ret;
        u16 num_vfs;
 
@@ -482,38 +483,46 @@ static ssize_t sriov_numvfs_store(struct device *dev,
        if (num_vfs > pci_sriov_get_totalvfs(pdev))
                return -ERANGE;
 
+       mutex_lock(&iov->dev->sriov->lock);
+
        if (num_vfs == pdev->sriov->num_VFs)
-               return count;           /* no change */
+               goto exit;
 
        /* is PF driver loaded w/callback */
        if (!pdev->driver || !pdev->driver->sriov_configure) {
                dev_info(&pdev->dev, "Driver doesn't support SRIOV configuration via sysfs\n");
-               return -ENOSYS;
+               ret = -ENOENT;
+               goto exit;
        }
 
        if (num_vfs == 0) {
                /* disable VFs */
                ret = pdev->driver->sriov_configure(pdev, 0);
-               if (ret < 0)
-                       return ret;
-               return count;
+               goto exit;
        }
 
        /* enable VFs */
        if (pdev->sriov->num_VFs) {
                dev_warn(&pdev->dev, "%d VFs already enabled. Disable before enabling %d VFs\n",
                         pdev->sriov->num_VFs, num_vfs);
-               return -EBUSY;
+               ret = -EBUSY;
+               goto exit;
        }
 
        ret = pdev->driver->sriov_configure(pdev, num_vfs);
        if (ret < 0)
-               return ret;
+               goto exit;
 
        if (ret != num_vfs)
                dev_warn(&pdev->dev, "%d VFs requested; only %d enabled\n",
                         num_vfs, ret);
 
+exit:
+       mutex_unlock(&iov->dev->sriov->lock);
+
+       if (ret < 0)
+               return ret;
+
        return count;
 }