diff mbox series

[v3,6/9] fpga: dfl: factor out feature data creation from build_info_commit_dev()

Message ID 20240919203430.1278067-7-peter.colberg@intel.com (mailing list archive)
State New
Headers show
Series fpga: dfl: fix kernel warning on port release/assign for SRIOV | expand

Commit Message

Peter Colberg Sept. 19, 2024, 8:34 p.m. UTC
Add a separate function binfo_create_feature_dev_data() which allocates
and populates the feature platform data, and call the function from
build_info_commit_dev() which registers the feature platform device.

Signed-off-by: Peter Colberg <peter.colberg@intel.com>
Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
---
 drivers/fpga/dfl.c | 74 ++++++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 32 deletions(-)

Comments

Xu Yilun Sept. 24, 2024, 7:15 a.m. UTC | #1
On Thu, Sep 19, 2024 at 04:34:27PM -0400, Peter Colberg wrote:
> Add a separate function binfo_create_feature_dev_data() which allocates
> and populates the feature platform data, and call the function from
> build_info_commit_dev() which registers the feature platform device.
> 
> Signed-off-by: Peter Colberg <peter.colberg@intel.com>
> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
> ---
>  drivers/fpga/dfl.c | 74 ++++++++++++++++++++++++++--------------------
>  1 file changed, 42 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index 4c79d433d216..e644eb9fde39 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -749,12 +749,8 @@ static void dfl_fpga_cdev_add_port_data(struct dfl_fpga_cdev *cdev,
>  	mutex_unlock(&cdev->lock);
>  }
>  
> -/*
> - * register current feature device, it is called when we need to switch to
> - * another feature parsing or we have parsed all features on given device
> - * feature list.
> - */
> -static int build_info_commit_dev(struct build_feature_devs_info *binfo)
> +static struct dfl_feature_platform_data *
> +binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)
>  {
>  	struct platform_device *fdev = binfo->feature_dev;
>  	struct dfl_feature_platform_data *pdata;
> @@ -764,7 +760,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
>  
>  	type = feature_dev_id_type(fdev);
>  	if (WARN_ON_ONCE(type >= DFL_ID_MAX))
> -		return -EINVAL;
> +		return ERR_PTR(-EINVAL);
>  
>  	/*
>  	 * we do not need to care for the memory which is associated with
> @@ -774,7 +770,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
>  	 */
>  	pdata = kzalloc(struct_size(pdata, features, binfo->feature_num), GFP_KERNEL);
>  	if (!pdata)
> -		return -ENOMEM;
> +		return ERR_PTR(-ENOMEM);
>  
>  	pdata->dev = fdev;
>  	pdata->num = binfo->feature_num;
> @@ -799,7 +795,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
>  	fdev->resource = kcalloc(binfo->feature_num, sizeof(*fdev->resource),
>  				 GFP_KERNEL);
>  	if (!fdev->resource)
> -		return -ENOMEM;
> +		return ERR_PTR(-ENOMEM);
>  
>  	/* fill features and resource information for feature dev */
>  	list_for_each_entry_safe(finfo, p, &binfo->sub_features, node) {
> @@ -818,7 +814,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
>  						       finfo->params, finfo->param_size,
>  						       GFP_KERNEL);
>  			if (!feature->params)
> -				return -ENOMEM;
> +				return ERR_PTR(-ENOMEM);
>  
>  			feature->param_size = finfo->param_size;
>  		}
> @@ -834,8 +830,10 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
>  			feature->ioaddr =
>  				devm_ioremap_resource(binfo->dev,
>  						      &finfo->mmio_res);
> -			if (IS_ERR(feature->ioaddr))
> -				return PTR_ERR(feature->ioaddr);
> +			if (IS_ERR(feature->ioaddr)) {
> +				ret = PTR_ERR(feature->ioaddr);
> +				return ERR_PTR(ret);

Why change the type back and forth?

  return feature->ioaddr;

is it OK?

Thanks,
Yilun
Peter Colberg Oct. 25, 2024, 10:43 p.m. UTC | #2
On Tue, 2024-09-24 at 15:15 +0800, Xu Yilun wrote:
> On Thu, Sep 19, 2024 at 04:34:27PM -0400, Peter Colberg wrote:
> > Add a separate function binfo_create_feature_dev_data() which allocates
> > and populates the feature platform data, and call the function from
> > build_info_commit_dev() which registers the feature platform device.
> > 
> > Signed-off-by: Peter Colberg <peter.colberg@intel.com>
> > Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
> > ---
> >  drivers/fpga/dfl.c | 74 ++++++++++++++++++++++++++--------------------
> >  1 file changed, 42 insertions(+), 32 deletions(-)
> > 
> > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> > index 4c79d433d216..e644eb9fde39 100644
> > --- a/drivers/fpga/dfl.c
> > +++ b/drivers/fpga/dfl.c
> > @@ -749,12 +749,8 @@ static void dfl_fpga_cdev_add_port_data(struct dfl_fpga_cdev *cdev,
> >  	mutex_unlock(&cdev->lock);
> >  }
> >  
> > -/*
> > - * register current feature device, it is called when we need to switch to
> > - * another feature parsing or we have parsed all features on given device
> > - * feature list.
> > - */
> > -static int build_info_commit_dev(struct build_feature_devs_info *binfo)
> > +static struct dfl_feature_platform_data *
> > +binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)
> >  {
> >  	struct platform_device *fdev = binfo->feature_dev;
> >  	struct dfl_feature_platform_data *pdata;
> > @@ -764,7 +760,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
> >  
> >  	type = feature_dev_id_type(fdev);
> >  	if (WARN_ON_ONCE(type >= DFL_ID_MAX))
> > -		return -EINVAL;
> > +		return ERR_PTR(-EINVAL);
> >  
> >  	/*
> >  	 * we do not need to care for the memory which is associated with
> > @@ -774,7 +770,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
> >  	 */
> >  	pdata = kzalloc(struct_size(pdata, features, binfo->feature_num), GFP_KERNEL);
> >  	if (!pdata)
> > -		return -ENOMEM;
> > +		return ERR_PTR(-ENOMEM);
> >  
> >  	pdata->dev = fdev;
> >  	pdata->num = binfo->feature_num;
> > @@ -799,7 +795,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
> >  	fdev->resource = kcalloc(binfo->feature_num, sizeof(*fdev->resource),
> >  				 GFP_KERNEL);
> >  	if (!fdev->resource)
> > -		return -ENOMEM;
> > +		return ERR_PTR(-ENOMEM);
> >  
> >  	/* fill features and resource information for feature dev */
> >  	list_for_each_entry_safe(finfo, p, &binfo->sub_features, node) {
> > @@ -818,7 +814,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
> >  						       finfo->params, finfo->param_size,
> >  						       GFP_KERNEL);
> >  			if (!feature->params)
> > -				return -ENOMEM;
> > +				return ERR_PTR(-ENOMEM);
> >  
> >  			feature->param_size = finfo->param_size;
> >  		}
> > @@ -834,8 +830,10 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
> >  			feature->ioaddr =
> >  				devm_ioremap_resource(binfo->dev,
> >  						      &finfo->mmio_res);
> > -			if (IS_ERR(feature->ioaddr))
> > -				return PTR_ERR(feature->ioaddr);
> > +			if (IS_ERR(feature->ioaddr)) {
> > +				ret = PTR_ERR(feature->ioaddr);
> > +				return ERR_PTR(ret);
> 
> Why change the type back and forth?
> 
>   return feature->ioaddr;
> 
> is it OK?
> 
> Thanks,
> Yilun

Yes, this has been done in the revised patch "fpga: dfl: factor out
feature data creation from build_info_commit_dev()".

Thanks,
Peter
diff mbox series

Patch

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 4c79d433d216..e644eb9fde39 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -749,12 +749,8 @@  static void dfl_fpga_cdev_add_port_data(struct dfl_fpga_cdev *cdev,
 	mutex_unlock(&cdev->lock);
 }
 
-/*
- * register current feature device, it is called when we need to switch to
- * another feature parsing or we have parsed all features on given device
- * feature list.
- */
-static int build_info_commit_dev(struct build_feature_devs_info *binfo)
+static struct dfl_feature_platform_data *
+binfo_create_feature_dev_data(struct build_feature_devs_info *binfo)
 {
 	struct platform_device *fdev = binfo->feature_dev;
 	struct dfl_feature_platform_data *pdata;
@@ -764,7 +760,7 @@  static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 
 	type = feature_dev_id_type(fdev);
 	if (WARN_ON_ONCE(type >= DFL_ID_MAX))
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	/*
 	 * we do not need to care for the memory which is associated with
@@ -774,7 +770,7 @@  static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 	 */
 	pdata = kzalloc(struct_size(pdata, features, binfo->feature_num), GFP_KERNEL);
 	if (!pdata)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	pdata->dev = fdev;
 	pdata->num = binfo->feature_num;
@@ -799,7 +795,7 @@  static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 	fdev->resource = kcalloc(binfo->feature_num, sizeof(*fdev->resource),
 				 GFP_KERNEL);
 	if (!fdev->resource)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	/* fill features and resource information for feature dev */
 	list_for_each_entry_safe(finfo, p, &binfo->sub_features, node) {
@@ -818,7 +814,7 @@  static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 						       finfo->params, finfo->param_size,
 						       GFP_KERNEL);
 			if (!feature->params)
-				return -ENOMEM;
+				return ERR_PTR(-ENOMEM);
 
 			feature->param_size = finfo->param_size;
 		}
@@ -834,8 +830,10 @@  static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 			feature->ioaddr =
 				devm_ioremap_resource(binfo->dev,
 						      &finfo->mmio_res);
-			if (IS_ERR(feature->ioaddr))
-				return PTR_ERR(feature->ioaddr);
+			if (IS_ERR(feature->ioaddr)) {
+				ret = PTR_ERR(feature->ioaddr);
+				return ERR_PTR(ret);
+			}
 		} else {
 			feature->resource_index = res_idx;
 			fdev->resource[res_idx++] = finfo->mmio_res;
@@ -845,7 +843,7 @@  static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 			ctx = devm_kcalloc(binfo->dev, finfo->nr_irqs,
 					   sizeof(*ctx), GFP_KERNEL);
 			if (!ctx)
-				return -ENOMEM;
+				return ERR_PTR(-ENOMEM);
 
 			for (i = 0; i < finfo->nr_irqs; i++)
 				ctx[i].irq =
@@ -859,25 +857,7 @@  static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 		kfree(finfo);
 	}
 
-	ret = platform_device_add(binfo->feature_dev);
-	if (!ret) {
-		if (type == PORT_ID)
-			dfl_fpga_cdev_add_port_data(binfo->cdev,
-						    pdata);
-		else
-			binfo->cdev->fme_dev =
-					get_device(&binfo->feature_dev->dev);
-		/*
-		 * reset it to avoid build_info_free() freeing their resource.
-		 *
-		 * The resource of successfully registered feature devices
-		 * will be freed by platform_device_unregister(). See the
-		 * comments in build_info_create_dev().
-		 */
-		binfo->feature_dev = NULL;
-	}
-
-	return ret;
+	return pdata;
 }
 
 static int
@@ -912,6 +892,36 @@  build_info_create_dev(struct build_feature_devs_info *binfo,
 	return 0;
 }
 
+static int build_info_commit_dev(struct build_feature_devs_info *binfo)
+{
+	struct dfl_feature_platform_data *pdata;
+	int ret;
+
+	pdata = binfo_create_feature_dev_data(binfo);
+	if (IS_ERR(pdata))
+		return PTR_ERR(pdata);
+
+	ret = platform_device_add(binfo->feature_dev);
+	if (ret)
+		return ret;
+
+	if (feature_dev_id_type(binfo->feature_dev) == PORT_ID)
+		dfl_fpga_cdev_add_port_data(binfo->cdev, pdata);
+	else
+		binfo->cdev->fme_dev = get_device(&binfo->feature_dev->dev);
+
+	/*
+	 * reset it to avoid build_info_free() freeing their resource.
+	 *
+	 * The resource of successfully registered feature devices
+	 * will be freed by platform_device_unregister(). See the
+	 * comments in build_info_create_dev().
+	 */
+	binfo->feature_dev = NULL;
+
+	return 0;
+}
+
 static void build_info_free(struct build_feature_devs_info *binfo)
 {
 	struct dfl_feature_info *finfo, *p;