]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fpga: dfl: destroy/recreate feature platform device on port release/assign
authorXu Yilun <yilun.xu@intel.com>
Wed, 20 Nov 2024 01:10:34 +0000 (20:10 -0500)
committerXu Yilun <yilun.xu@linux.intel.com>
Wed, 18 Dec 2024 14:28:48 +0000 (22:28 +0800)
Now that the internal DFL APIs have been converted to consume DFL
enumeration info from a separate structure, dfl_feature_dev_data, which
lifetime is independent of the feature device, proceed to completely
destroy and recreate the feature platform device on port release and
assign, respectively. This resolves a longstanding issue in the use of
platform_device_add(), which states to "not call this routine more than
once for any device structure" and which used to print a kernel warning.

The function feature_dev_unregister() resets the device pointer in the
feature data to NULL to signal that the feature platform device has been
destroyed. This substitutes the previous device_is_registered() checks.

Signed-off-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Signed-off-by: Peter Colberg <peter.colberg@intel.com>
Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20241120011035.230574-19-peter.colberg@intel.com
Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
drivers/fpga/dfl.c

index c20937ef2c9a6d3a512da4760e159044b3479c33..7022657243c0a72bda2013386c66fb8bafe4b380 100644 (file)
@@ -1630,21 +1630,10 @@ EXPORT_SYMBOL_GPL(dfl_fpga_feature_devs_enumerate);
  */
 void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev)
 {
-       struct dfl_feature_dev_data *fdata, *ptmp;
-
        mutex_lock(&cdev->lock);
        if (cdev->fme_dev)
                put_device(cdev->fme_dev);
 
-       list_for_each_entry_safe(fdata, ptmp, &cdev->port_dev_list, node) {
-               struct platform_device *port_dev = fdata->dev;
-
-               /* remove released ports */
-               if (!device_is_registered(&port_dev->dev))
-                       platform_device_put(port_dev);
-
-               list_del(&fdata->node);
-       }
        mutex_unlock(&cdev->lock);
 
        remove_feature_devs(cdev);
@@ -1724,7 +1713,7 @@ int dfl_fpga_cdev_release_port(struct dfl_fpga_cdev *cdev, int port_id)
        if (!fdata)
                goto unlock_exit;
 
-       if (!device_is_registered(&fdata->dev->dev)) {
+       if (!fdata->dev) {
                ret = -EBUSY;
                goto unlock_exit;
        }
@@ -1735,7 +1724,7 @@ int dfl_fpga_cdev_release_port(struct dfl_fpga_cdev *cdev, int port_id)
        if (ret)
                goto unlock_exit;
 
-       platform_device_del(fdata->dev);
+       feature_dev_unregister(fdata);
        cdev->released_port_num++;
 unlock_exit:
        mutex_unlock(&cdev->lock);
@@ -1765,12 +1754,12 @@ int dfl_fpga_cdev_assign_port(struct dfl_fpga_cdev *cdev, int port_id)
        if (!fdata)
                goto unlock_exit;
 
-       if (device_is_registered(&fdata->dev->dev)) {
+       if (fdata->dev) {
                ret = -EBUSY;
                goto unlock_exit;
        }
 
-       ret = platform_device_add(fdata->dev);
+       ret = feature_dev_register(fdata);
        if (ret)
                goto unlock_exit;
 
@@ -1820,7 +1809,7 @@ void dfl_fpga_cdev_config_ports_pf(struct dfl_fpga_cdev *cdev)
 
        mutex_lock(&cdev->lock);
        list_for_each_entry(fdata, &cdev->port_dev_list, node) {
-               if (device_is_registered(&fdata->dev->dev))
+               if (fdata->dev)
                        continue;
 
                config_port_pf_mode(cdev->fme_dev, fdata->id);
@@ -1857,7 +1846,7 @@ int dfl_fpga_cdev_config_ports_vf(struct dfl_fpga_cdev *cdev, int num_vfs)
        }
 
        list_for_each_entry(fdata, &cdev->port_dev_list, node) {
-               if (device_is_registered(&fdata->dev->dev))
+               if (fdata->dev)
                        continue;
 
                config_port_vf_mode(cdev->fme_dev, fdata->id);