From: Peter Colberg <peter.colberg@intel.com>
To: Wu Hao <hao.wu@intel.com>, Tom Rix <trix@redhat.com>,
Moritz Fischer <mdf@kernel.org>, Xu Yilun <yilun.xu@intel.com>,
linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Russ Weight <russ.weight@linux.dev>,
Marco Pagani <marpagan@redhat.com>,
Matthew Gerlach <matthew.gerlach@linux.intel.com>,
Basheer Ahmed Muddebihal
<basheer.ahmed.muddebihal@linux.intel.com>,
Peter Colberg <peter.colberg@intel.com>
Subject: [PATCH v4 06/19] fpga: dfl: factor out feature data creation from build_info_commit_dev()
Date: Fri, 25 Oct 2024 18:37:01 -0400 [thread overview]
Message-ID: <20241025223714.394533-7-peter.colberg@intel.com> (raw)
In-Reply-To: <20241025223714.394533-1-peter.colberg@intel.com>
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>
Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com>
---
Changes since v3:
- Replace ERR_PTR(PTR_ERR(feature->ioaddr) with feature->ioaddr and
remove unneeded local variable ret.
- Add missing commas in description.
Changes since v2:
- New patch extracted from monolithic v1 patch.
---
drivers/fpga/dfl.c | 72 +++++++++++++++++++++++++---------------------
1 file changed, 40 insertions(+), 32 deletions(-)
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 4c79d433d216..56a32f5146a3 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -749,22 +749,18 @@ 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;
struct dfl_feature_info *finfo, *p;
enum dfl_id_type type;
- int ret, index = 0, res_idx = 0;
+ int index = 0, res_idx = 0;
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;
}
@@ -835,7 +831,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
devm_ioremap_resource(binfo->dev,
&finfo->mmio_res);
if (IS_ERR(feature->ioaddr))
- return PTR_ERR(feature->ioaddr);
+ return feature->ioaddr;
} else {
feature->resource_index = res_idx;
fdev->resource[res_idx++] = finfo->mmio_res;
@@ -845,7 +841,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 +855,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 +890,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;
--
2.47.0
next prev parent reply other threads:[~2024-10-25 22:37 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-25 22:36 [PATCH v4 00/19] fpga: dfl: fix kernel warning on port release/assign for SRIOV Peter Colberg
2024-10-25 22:36 ` [PATCH v4 01/19] fpga: dfl: omit unneeded argument pdata from dfl_feature_instance_init() Peter Colberg
2024-10-25 22:36 ` [PATCH v4 02/19] fpga: dfl: return platform data from dfl_fpga_inode_to_feature_dev_data() Peter Colberg
2024-10-25 22:36 ` [PATCH v4 03/19] fpga: dfl: afu: use parent device to log errors on port enable/disable Peter Colberg
2024-10-25 22:36 ` [PATCH v4 04/19] fpga: dfl: afu: define local pointer to feature device Peter Colberg
2024-10-25 22:37 ` [PATCH v4 05/19] fpga: dfl: pass feature platform data instead of device as argument Peter Colberg
2024-10-25 22:37 ` Peter Colberg [this message]
2024-10-25 22:37 ` [PATCH v4 07/19] fpga: dfl: store FIU type in feature platform data Peter Colberg
2024-10-25 22:37 ` [PATCH v4 08/19] fpga: dfl: refactor internal DFL APIs to take/return feature device data Peter Colberg
2024-10-25 22:37 ` [PATCH v4 09/19] fpga: dfl: factor out feature device registration Peter Colberg
2024-10-25 22:37 ` [PATCH v4 10/19] fpga: dfl: factor out feature device data from platform device data Peter Colberg
2024-10-25 22:37 ` [PATCH v4 11/19] fpga: dfl: convert features from flexible array member to separate array Peter Colberg
2024-10-25 22:37 ` [PATCH v4 12/19] fpga: dfl: store MMIO resources in feature device data Peter Colberg
2024-10-25 22:37 ` [PATCH v4 13/19] fpga: dfl: store platform device name " Peter Colberg
2024-10-25 22:37 ` [PATCH v4 14/19] fpga: dfl: store platform device id " Peter Colberg
2024-11-18 14:34 ` Xu Yilun
2024-11-19 23:34 ` Colberg, Peter
2024-10-25 22:37 ` [PATCH v4 15/19] fpga: dfl: convert is_feature_dev_detected() to use FIU type Peter Colberg
2024-11-18 14:32 ` Xu Yilun
2024-11-18 23:00 ` Colberg, Peter
2024-11-19 1:19 ` Xu Yilun
2024-11-19 23:37 ` Colberg, Peter
2024-10-25 22:37 ` [PATCH v4 16/19] fpga: dfl: allocate platform device after feature device data Peter Colberg
2024-11-18 14:51 ` Xu Yilun
2024-11-18 23:04 ` Colberg, Peter
2024-11-19 23:39 ` Colberg, Peter
2024-10-25 22:37 ` [PATCH v4 17/19] fpga: dfl: remove unneeded function build_info_create_dev() Peter Colberg
2024-11-18 14:58 ` Xu Yilun
2024-11-19 23:40 ` Colberg, Peter
2024-10-25 22:37 ` [PATCH v4 18/19] fpga: dfl: drop unneeded get_device() and put_device() of feature device Peter Colberg
2024-11-18 15:01 ` Xu Yilun
2024-10-25 22:37 ` [PATCH v4 19/19] fpga: dfl: destroy/recreate feature platform device on port release/assign Peter Colberg
2024-11-18 15:09 ` Xu Yilun
2024-11-19 23:46 ` Colberg, Peter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241025223714.394533-7-peter.colberg@intel.com \
--to=peter.colberg@intel.com \
--cc=basheer.ahmed.muddebihal@linux.intel.com \
--cc=hao.wu@intel.com \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marpagan@redhat.com \
--cc=matthew.gerlach@linux.intel.com \
--cc=mdf@kernel.org \
--cc=russ.weight@linux.dev \
--cc=trix@redhat.com \
--cc=yilun.xu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome