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]
Message-ID: <20241025223714.394533-10-peter.colberg@intel.com>
Date: Fri, 25 Oct 2024 18:37:04 -0400
From: Peter Colberg <peter.colberg@...el.com>
To: Wu Hao <hao.wu@...el.com>,
	Tom Rix <trix@...hat.com>,
	Moritz Fischer <mdf@...nel.org>,
	Xu Yilun <yilun.xu@...el.com>,
	linux-fpga@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: Russ Weight <russ.weight@...ux.dev>,
	Marco Pagani <marpagan@...hat.com>,
	Matthew Gerlach <matthew.gerlach@...ux.intel.com>,
	Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@...ux.intel.com>,
	Peter Colberg <peter.colberg@...el.com>
Subject: [PATCH v4 09/19] fpga: dfl: factor out feature device registration

Add separate functions, feature_dev_{register,unregister}(), that wrap
platform_device_add() and platform_device_unregister(), respectively.
These are invoked once per feature device in this commit but will be
reused in a subsequent commit to destroy and recreate the platform
device when the corresponding port is released and reassigned.

The function feature_dev_register() will be extended in subsequent
commits to allocate the platform device, add resources and platform
data, and finally add the platform device to the device hierarchy.

The function feature_dev_unregister() is in its final form. After
unregistering the device, the device pointer in the feature data is
reset to NULL to signal that the platform device has been destroyed.
This will substitute device_is_registered() in a subsequent commit.

Signed-off-by: Peter Colberg <peter.colberg@...el.com>
Reviewed-by: Matthew Gerlach <matthew.gerlach@...ux.intel.com>
Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@...ux.intel.com>
---
Changes since v3:
- New patch extracted from last patch of v3 series.
---
 drivers/fpga/dfl.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index e8488a771337..13787b216e23 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -872,12 +872,35 @@ build_info_create_dev(struct build_feature_devs_info *binfo)
 	if (fdev->id < 0)
 		return fdev->id;
 
-	fdev->dev.parent = &binfo->cdev->region->dev;
-	fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);
+	return 0;
+}
+
+/*
+ * 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 feature_dev_register(struct dfl_feature_dev_data *fdata)
+{
+	struct platform_device *fdev = fdata->dev;
+	int ret;
+
+	fdev->dev.parent = &fdata->dfl_cdev->region->dev;
+	fdev->dev.devt = dfl_get_devt(dfl_devs[fdata->type].devt_type, fdev->id);
+
+	ret = platform_device_add(fdev);
+	if (ret)
+		return ret;
 
 	return 0;
 }
 
+static void feature_dev_unregister(struct dfl_feature_dev_data *fdata)
+{
+	platform_device_unregister(fdata->dev);
+	fdata->dev = NULL;
+}
+
 static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 {
 	struct dfl_feature_dev_data *fdata;
@@ -887,7 +910,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
 	if (IS_ERR(fdata))
 		return PTR_ERR(fdata);
 
-	ret = platform_device_add(binfo->feature_dev);
+	ret = feature_dev_register(fdata);
 	if (ret)
 		return ret;
 
@@ -1519,7 +1542,7 @@ static int remove_feature_dev(struct device *dev, void *data)
 	struct platform_device *pdev = to_platform_device(dev);
 	int id = pdev->id;
 
-	platform_device_unregister(pdev);
+	feature_dev_unregister(fdata);
 
 	dfl_id_free(fdata->type, id);
 
-- 
2.47.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ