linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* (no subject)
@ 2020-10-05 17:37 Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API Moritz Fischer
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Subject: [PATCH v2 00/10] Introduce devm_fpga_mgr_register()

This patchset introduces the devm_fpga_mgr_register API,
a devres managed version of fpga_mgr_register().

It reduces boilerplate being repeated literally in every
single driver by moving it to the fpga-mgr core.

Changes from v1:
- Addressed Hao's feedback
   - priv -> res
   - comment style
   - use fpga_mgr_devres consistently

- Addressed Tom's feedback
   - err -> ret
   - removed removal of deprecated API
   - added Reviewed-by: tags

Moritz Fischer (10):
  fpga: fpga-mgr: Add devm_fpga_mgr_register() API
  fpga: fpga-mgr: altera-ps-spi: Simplify registration
  fpga: fpga-mgr: dfl-fme-mgr: Simplify registration
  fpga: fpga-mgr: ice40-spi: Simplify registration
  fpga: fpga-mgr: machxo2-spi: Simplify registration
  fpga: fpga-mgr: socfpga: Simplify registration
  fpga: fpga-mgr: ts73xx: Simplify registration
  fpga: fpga-mgr: xilinx-spi: Simplify registration
  fpga: fpga-mgr: zynqmp: Simplify registration
  fpga: fpga-mgr: altera-pr-ip: Simplify registration

 drivers/fpga/altera-pr-ip-core-plat.c  | 10 ----
 drivers/fpga/altera-pr-ip-core.c       | 14 +----
 drivers/fpga/altera-ps-spi.c           | 14 +----
 drivers/fpga/dfl-fme-mgr.c             | 12 +---
 drivers/fpga/fpga-mgr.c                | 76 ++++++++++++++++++++++----
 drivers/fpga/ice40-spi.c               | 14 +----
 drivers/fpga/machxo2-spi.c             | 14 +----
 drivers/fpga/socfpga.c                 | 14 +----
 drivers/fpga/ts73xx-fpga.c             | 14 +----
 drivers/fpga/xilinx-spi.c              | 14 +----
 drivers/fpga/zynqmp-fpga.c             | 21 +------
 include/linux/fpga/altera-pr-ip-core.h |  1 -
 include/linux/fpga/fpga-mgr.h          |  2 +
 13 files changed, 77 insertions(+), 143 deletions(-)

-- 
2.28.0

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API
  2020-10-05 17:37 Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-09 21:25   ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 02/10] fpga: fpga-mgr: altera-ps-spi: Simplify registration Moritz Fischer
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Add a devm_fpga_mgr_register() API that can be used to register a FPGA
Manager that was created using devm_fpga_mgr_create().

Introduce a struct fpga_mgr_devres that makes the devres
allocation a little bit more readable and gets reused for
devm_fpga_mgr_create() devm_fpga_mgr_register().

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/fpga-mgr.c       | 81 +++++++++++++++++++++++++++++------
 include/linux/fpga/fpga-mgr.h |  2 +
 2 files changed, 71 insertions(+), 12 deletions(-)

diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index f38bab01432e..b85bc47c91a9 100644
--- a/drivers/fpga/fpga-mgr.c
+++ b/drivers/fpga/fpga-mgr.c
@@ -21,6 +21,10 @@
 static DEFINE_IDA(fpga_mgr_ida);
 static struct class *fpga_mgr_class;
 
+struct fpga_mgr_devres {
+	struct fpga_manager *mgr;
+};
+
 /**
  * fpga_image_info_alloc - Allocate a FPGA image info struct
  * @dev: owning device
@@ -625,9 +629,9 @@ EXPORT_SYMBOL_GPL(fpga_mgr_free);
 
 static void devm_fpga_mgr_release(struct device *dev, void *res)
 {
-	struct fpga_manager *mgr = *(struct fpga_manager **)res;
+	struct fpga_mgr_devres *dr = res;
 
-	fpga_mgr_free(mgr);
+	fpga_mgr_free(dr->mgr);
 }
 
 /**
@@ -651,21 +655,21 @@ struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,
 					  const struct fpga_manager_ops *mops,
 					  void *priv)
 {
-	struct fpga_manager **ptr, *mgr;
+	struct fpga_mgr_devres *dr;
 
-	ptr = devres_alloc(devm_fpga_mgr_release, sizeof(*ptr), GFP_KERNEL);
-	if (!ptr)
+	dr = devres_alloc(devm_fpga_mgr_release, sizeof(*dr), GFP_KERNEL);
+	if (!dr)
 		return NULL;
 
-	mgr = fpga_mgr_create(dev, name, mops, priv);
-	if (!mgr) {
-		devres_free(ptr);
-	} else {
-		*ptr = mgr;
-		devres_add(dev, ptr);
+	dr->mgr = fpga_mgr_create(dev, name, mops, priv);
+	if (!dr->mgr) {
+		devres_free(dr);
+		return NULL;
 	}
 
-	return mgr;
+	devres_add(dev, dr);
+
+	return dr->mgr;
 }
 EXPORT_SYMBOL_GPL(devm_fpga_mgr_create);
 
@@ -722,6 +726,59 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)
 }
 EXPORT_SYMBOL_GPL(fpga_mgr_unregister);
 
+static int fpga_mgr_devres_match(struct device *dev, void *res,
+				 void *match_data)
+{
+	struct fpga_mgr_devres *dr = res;
+
+	return match_data == dr->mgr;
+}
+
+static void devm_fpga_mgr_unregister(struct device *dev, void *res)
+{
+	struct fpga_mgr_devres *dr = res;
+
+	fpga_mgr_unregister(dr->mgr);
+}
+
+/**
+ * devm_fpga_mgr_register - resource managed variant of fpga_mgr_register()
+ * @dev: managing device for this FPGA manager
+ * @mgr: fpga manager struct
+ *
+ * This is the devres variant of fpga_mgr_register() for which the unregister
+ * function will be called automatically when the managing device is detached.
+ */
+int devm_fpga_mgr_register(struct device *dev, struct fpga_manager *mgr)
+{
+	struct fpga_mgr_devres *dr;
+	int ret;
+
+	/*
+	 * Make sure that the struct fpga_manager * that is passed in is
+	 * managed itself.
+	 */
+	if (WARN_ON(!devres_find(dev, devm_fpga_mgr_release,
+				 fpga_mgr_devres_match, mgr)))
+		return -EINVAL;
+
+	dr = devres_alloc(devm_fpga_mgr_unregister, sizeof(*dr), GFP_KERNEL);
+	if (!dr)
+		return -ENOMEM;
+
+	ret = fpga_mgr_register(mgr);
+	if (ret) {
+		devres_free(dr);
+		return ret;
+	}
+
+	dr->mgr = mgr;
+	devres_add(dev, dr);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_fpga_mgr_register);
+
 static void fpga_mgr_dev_release(struct device *dev)
 {
 }
diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h
index e8ca62b2cb5b..2bc3030a69e5 100644
--- a/include/linux/fpga/fpga-mgr.h
+++ b/include/linux/fpga/fpga-mgr.h
@@ -198,6 +198,8 @@ void fpga_mgr_free(struct fpga_manager *mgr);
 int fpga_mgr_register(struct fpga_manager *mgr);
 void fpga_mgr_unregister(struct fpga_manager *mgr);
 
+int devm_fpga_mgr_register(struct device *dev, struct fpga_manager *mgr);
+
 struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,
 					  const struct fpga_manager_ops *mops,
 					  void *priv);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 02/10] fpga: fpga-mgr: altera-ps-spi: Simplify registration
  2020-10-05 17:37 Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 03/10] fpga: fpga-mgr: dfl-fme-mgr: " Moritz Fischer
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration by using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/altera-ps-spi.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c
index 0221dee8dd4c..23bfd4d1ad0f 100644
--- a/drivers/fpga/altera-ps-spi.c
+++ b/drivers/fpga/altera-ps-spi.c
@@ -307,18 +307,7 @@ static int altera_ps_probe(struct spi_device *spi)
 	if (!mgr)
 		return -ENOMEM;
 
-	spi_set_drvdata(spi, mgr);
-
-	return fpga_mgr_register(mgr);
-}
-
-static int altera_ps_remove(struct spi_device *spi)
-{
-	struct fpga_manager *mgr = spi_get_drvdata(spi);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(&spi->dev, mgr);
 }
 
 static const struct spi_device_id altera_ps_spi_ids[] = {
@@ -337,7 +326,6 @@ static struct spi_driver altera_ps_driver = {
 	},
 	.id_table = altera_ps_spi_ids,
 	.probe = altera_ps_probe,
-	.remove = altera_ps_remove,
 };
 
 module_spi_driver(altera_ps_driver)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 03/10] fpga: fpga-mgr: dfl-fme-mgr: Simplify registration
  2020-10-05 17:37 Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 02/10] fpga: fpga-mgr: altera-ps-spi: Simplify registration Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 04/10] fpga: fpga-mgr: ice40-spi: " Moritz Fischer
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/dfl-fme-mgr.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/fpga/dfl-fme-mgr.c b/drivers/fpga/dfl-fme-mgr.c
index b3f7eee3c93f..d5861d13b306 100644
--- a/drivers/fpga/dfl-fme-mgr.c
+++ b/drivers/fpga/dfl-fme-mgr.c
@@ -314,18 +314,8 @@ static int fme_mgr_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	mgr->compat_id = compat_id;
-	platform_set_drvdata(pdev, mgr);
 
-	return fpga_mgr_register(mgr);
-}
-
-static int fme_mgr_remove(struct platform_device *pdev)
-{
-	struct fpga_manager *mgr = platform_get_drvdata(pdev);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(dev, mgr);
 }
 
 static struct platform_driver fme_mgr_driver = {
@@ -333,7 +323,6 @@ static struct platform_driver fme_mgr_driver = {
 		.name    = DFL_FPGA_FME_MGR,
 	},
 	.probe   = fme_mgr_probe,
-	.remove  = fme_mgr_remove,
 };
 
 module_platform_driver(fme_mgr_driver);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 04/10] fpga: fpga-mgr: ice40-spi: Simplify registration
  2020-10-05 17:37 Moritz Fischer
                   ` (2 preceding siblings ...)
  2020-10-05 17:37 ` [PATCH v2 03/10] fpga: fpga-mgr: dfl-fme-mgr: " Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 05/10] fpga: fpga-mgr: machxo2-spi: " Moritz Fischer
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/ice40-spi.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/fpga/ice40-spi.c b/drivers/fpga/ice40-spi.c
index 8d689fea0dab..69dec5af23c3 100644
--- a/drivers/fpga/ice40-spi.c
+++ b/drivers/fpga/ice40-spi.c
@@ -183,18 +183,7 @@ static int ice40_fpga_probe(struct spi_device *spi)
 	if (!mgr)
 		return -ENOMEM;
 
-	spi_set_drvdata(spi, mgr);
-
-	return fpga_mgr_register(mgr);
-}
-
-static int ice40_fpga_remove(struct spi_device *spi)
-{
-	struct fpga_manager *mgr = spi_get_drvdata(spi);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(dev, mgr);
 }
 
 static const struct of_device_id ice40_fpga_of_match[] = {
@@ -205,7 +194,6 @@ MODULE_DEVICE_TABLE(of, ice40_fpga_of_match);
 
 static struct spi_driver ice40_fpga_driver = {
 	.probe = ice40_fpga_probe,
-	.remove = ice40_fpga_remove,
 	.driver = {
 		.name = "ice40spi",
 		.of_match_table = of_match_ptr(ice40_fpga_of_match),
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 05/10] fpga: fpga-mgr: machxo2-spi: Simplify registration
  2020-10-05 17:37 Moritz Fischer
                   ` (3 preceding siblings ...)
  2020-10-05 17:37 ` [PATCH v2 04/10] fpga: fpga-mgr: ice40-spi: " Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 06/10] fpga: fpga-mgr: socfpga: " Moritz Fischer
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/machxo2-spi.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/fpga/machxo2-spi.c b/drivers/fpga/machxo2-spi.c
index b316369156fe..114a64d2b7a4 100644
--- a/drivers/fpga/machxo2-spi.c
+++ b/drivers/fpga/machxo2-spi.c
@@ -371,18 +371,7 @@ static int machxo2_spi_probe(struct spi_device *spi)
 	if (!mgr)
 		return -ENOMEM;
 
-	spi_set_drvdata(spi, mgr);
-
-	return fpga_mgr_register(mgr);
-}
-
-static int machxo2_spi_remove(struct spi_device *spi)
-{
-	struct fpga_manager *mgr = spi_get_drvdata(spi);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(dev, mgr);
 }
 
 static const struct of_device_id of_match[] = {
@@ -403,7 +392,6 @@ static struct spi_driver machxo2_spi_driver = {
 		.of_match_table = of_match_ptr(of_match),
 	},
 	.probe = machxo2_spi_probe,
-	.remove = machxo2_spi_remove,
 	.id_table = lattice_ids,
 };
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 06/10] fpga: fpga-mgr: socfpga: Simplify registration
  2020-10-05 17:37 Moritz Fischer
                   ` (4 preceding siblings ...)
  2020-10-05 17:37 ` [PATCH v2 05/10] fpga: fpga-mgr: machxo2-spi: " Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 07/10] fpga: fpga-mgr: ts73xx: " Moritz Fischer
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/socfpga.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/fpga/socfpga.c b/drivers/fpga/socfpga.c
index 4a8a2fcd4e6c..1f467173fc1f 100644
--- a/drivers/fpga/socfpga.c
+++ b/drivers/fpga/socfpga.c
@@ -576,18 +576,7 @@ static int socfpga_fpga_probe(struct platform_device *pdev)
 	if (!mgr)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, mgr);
-
-	return fpga_mgr_register(mgr);
-}
-
-static int socfpga_fpga_remove(struct platform_device *pdev)
-{
-	struct fpga_manager *mgr = platform_get_drvdata(pdev);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(dev, mgr);
 }
 
 #ifdef CONFIG_OF
@@ -601,7 +590,6 @@ MODULE_DEVICE_TABLE(of, socfpga_fpga_of_match);
 
 static struct platform_driver socfpga_fpga_driver = {
 	.probe = socfpga_fpga_probe,
-	.remove = socfpga_fpga_remove,
 	.driver = {
 		.name	= "socfpga_fpga_manager",
 		.of_match_table = of_match_ptr(socfpga_fpga_of_match),
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 07/10] fpga: fpga-mgr: ts73xx: Simplify registration
  2020-10-05 17:37 Moritz Fischer
                   ` (5 preceding siblings ...)
  2020-10-05 17:37 ` [PATCH v2 06/10] fpga: fpga-mgr: socfpga: " Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 08/10] fpga: fpga-mgr: xilinx-spi: " Moritz Fischer
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/ts73xx-fpga.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/fpga/ts73xx-fpga.c b/drivers/fpga/ts73xx-fpga.c
index 2888ff000e4d..101f016c6ed8 100644
--- a/drivers/fpga/ts73xx-fpga.c
+++ b/drivers/fpga/ts73xx-fpga.c
@@ -127,18 +127,7 @@ static int ts73xx_fpga_probe(struct platform_device *pdev)
 	if (!mgr)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, mgr);
-
-	return fpga_mgr_register(mgr);
-}
-
-static int ts73xx_fpga_remove(struct platform_device *pdev)
-{
-	struct fpga_manager *mgr = platform_get_drvdata(pdev);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(kdev, mgr);
 }
 
 static struct platform_driver ts73xx_fpga_driver = {
@@ -146,7 +135,6 @@ static struct platform_driver ts73xx_fpga_driver = {
 		.name	= "ts73xx-fpga-mgr",
 	},
 	.probe	= ts73xx_fpga_probe,
-	.remove	= ts73xx_fpga_remove,
 };
 module_platform_driver(ts73xx_fpga_driver);
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 08/10] fpga: fpga-mgr: xilinx-spi: Simplify registration
  2020-10-05 17:37 Moritz Fischer
                   ` (6 preceding siblings ...)
  2020-10-05 17:37 ` [PATCH v2 07/10] fpga: fpga-mgr: ts73xx: " Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 09/10] fpga: fpga-mgr: zynqmp: " Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 10/10] fpga: fpga-mgr: altera-pr-ip: " Moritz Fischer
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/xilinx-spi.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c
index 824abbbd631e..27defa98092d 100644
--- a/drivers/fpga/xilinx-spi.c
+++ b/drivers/fpga/xilinx-spi.c
@@ -259,18 +259,7 @@ static int xilinx_spi_probe(struct spi_device *spi)
 	if (!mgr)
 		return -ENOMEM;
 
-	spi_set_drvdata(spi, mgr);
-
-	return fpga_mgr_register(mgr);
-}
-
-static int xilinx_spi_remove(struct spi_device *spi)
-{
-	struct fpga_manager *mgr = spi_get_drvdata(spi);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(&spi->dev, mgr);
 }
 
 static const struct of_device_id xlnx_spi_of_match[] = {
@@ -285,7 +274,6 @@ static struct spi_driver xilinx_slave_spi_driver = {
 		.of_match_table = of_match_ptr(xlnx_spi_of_match),
 	},
 	.probe = xilinx_spi_probe,
-	.remove = xilinx_spi_remove,
 };
 
 module_spi_driver(xilinx_slave_spi_driver)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 09/10] fpga: fpga-mgr: zynqmp: Simplify registration
  2020-10-05 17:37 Moritz Fischer
                   ` (7 preceding siblings ...)
  2020-10-05 17:37 ` [PATCH v2 08/10] fpga: fpga-mgr: xilinx-spi: " Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 17:37 ` [PATCH v2 10/10] fpga: fpga-mgr: altera-pr-ip: " Moritz Fischer
  9 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Reviewed-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/fpga/zynqmp-fpga.c | 21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/drivers/fpga/zynqmp-fpga.c b/drivers/fpga/zynqmp-fpga.c
index 4a1139e05280..125743c9797f 100644
--- a/drivers/fpga/zynqmp-fpga.c
+++ b/drivers/fpga/zynqmp-fpga.c
@@ -95,7 +95,6 @@ static int zynqmp_fpga_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct zynqmp_fpga_priv *priv;
 	struct fpga_manager *mgr;
-	int ret;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -108,24 +107,7 @@ static int zynqmp_fpga_probe(struct platform_device *pdev)
 	if (!mgr)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, mgr);
-
-	ret = fpga_mgr_register(mgr);
-	if (ret) {
-		dev_err(dev, "unable to register FPGA manager");
-		return ret;
-	}
-
-	return 0;
-}
-
-static int zynqmp_fpga_remove(struct platform_device *pdev)
-{
-	struct fpga_manager *mgr = platform_get_drvdata(pdev);
-
-	fpga_mgr_unregister(mgr);
-
-	return 0;
+	return devm_fpga_mgr_register(dev, mgr);
 }
 
 static const struct of_device_id zynqmp_fpga_of_match[] = {
@@ -137,7 +119,6 @@ MODULE_DEVICE_TABLE(of, zynqmp_fpga_of_match);
 
 static struct platform_driver zynqmp_fpga_driver = {
 	.probe = zynqmp_fpga_probe,
-	.remove = zynqmp_fpga_remove,
 	.driver = {
 		.name = "zynqmp_fpga_manager",
 		.of_match_table = of_match_ptr(zynqmp_fpga_of_match),
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 10/10] fpga: fpga-mgr: altera-pr-ip: Simplify registration
  2020-10-05 17:37 Moritz Fischer
                   ` (8 preceding siblings ...)
  2020-10-05 17:37 ` [PATCH v2 09/10] fpga: fpga-mgr: zynqmp: " Moritz Fischer
@ 2020-10-05 17:37 ` Moritz Fischer
  2020-10-05 20:13   ` Tom Rix
  9 siblings, 1 reply; 13+ messages in thread
From: Moritz Fischer @ 2020-10-05 17:37 UTC (permalink / raw)
  To: linux-fpga
  Cc: trix, hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach, Moritz Fischer

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <mdf@kernel.org>
---

Changes from v1:
- Removed part that removes unused symbol

---
 drivers/fpga/altera-pr-ip-core-plat.c | 10 ----------
 drivers/fpga/altera-pr-ip-core.c      |  4 +---
 2 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/fpga/altera-pr-ip-core-plat.c b/drivers/fpga/altera-pr-ip-core-plat.c
index 99b9cc0e70f0..b008a6b8d2d3 100644
--- a/drivers/fpga/altera-pr-ip-core-plat.c
+++ b/drivers/fpga/altera-pr-ip-core-plat.c
@@ -28,15 +28,6 @@ static int alt_pr_platform_probe(struct platform_device *pdev)
 	return alt_pr_register(dev, reg_base);
 }
 
-static int alt_pr_platform_remove(struct platform_device *pdev)
-{
-	struct device *dev = &pdev->dev;
-
-	alt_pr_unregister(dev);
-
-	return 0;
-}
-
 static const struct of_device_id alt_pr_of_match[] = {
 	{ .compatible = "altr,a10-pr-ip", },
 	{},
@@ -46,7 +37,6 @@ MODULE_DEVICE_TABLE(of, alt_pr_of_match);
 
 static struct platform_driver alt_pr_platform_driver = {
 	.probe = alt_pr_platform_probe,
-	.remove = alt_pr_platform_remove,
 	.driver = {
 		.name	= "alt_a10_pr_ip",
 		.of_match_table = alt_pr_of_match,
diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c
index 2cf25fd5e897..5b130c4d9882 100644
--- a/drivers/fpga/altera-pr-ip-core.c
+++ b/drivers/fpga/altera-pr-ip-core.c
@@ -195,9 +195,7 @@ int alt_pr_register(struct device *dev, void __iomem *reg_base)
 	if (!mgr)
 		return -ENOMEM;
 
-	dev_set_drvdata(dev, mgr);
-
-	return fpga_mgr_register(mgr);
+	return devm_fpga_mgr_register(dev, mgr);
 }
 EXPORT_SYMBOL_GPL(alt_pr_register);
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 10/10] fpga: fpga-mgr: altera-pr-ip: Simplify registration
  2020-10-05 17:37 ` [PATCH v2 10/10] fpga: fpga-mgr: altera-pr-ip: " Moritz Fischer
@ 2020-10-05 20:13   ` Tom Rix
  0 siblings, 0 replies; 13+ messages in thread
From: Tom Rix @ 2020-10-05 20:13 UTC (permalink / raw)
  To: Moritz Fischer, linux-fpga
  Cc: hao.wu, michal.simek, linux-kernel, linux-arm-kernel,
	russell.h.weight, matthew.gerlach


On 10/5/20 10:37 AM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.

Should change old commit message to something about removing symbol

alt_pr_platform_remove

Otherwise fine.

Reviewed-by: Tom Rix <trix@redhat.com>

>
> Signed-off-by: Moritz Fischer <mdf@kernel.org>
> ---
>
> Changes from v1:
> - Removed part that removes unused symbol
>
> ---
>  drivers/fpga/altera-pr-ip-core-plat.c | 10 ----------
>  drivers/fpga/altera-pr-ip-core.c      |  4 +---
>  2 files changed, 1 insertion(+), 13 deletions(-)
>
> diff --git a/drivers/fpga/altera-pr-ip-core-plat.c b/drivers/fpga/altera-pr-ip-core-plat.c
> index 99b9cc0e70f0..b008a6b8d2d3 100644
> --- a/drivers/fpga/altera-pr-ip-core-plat.c
> +++ b/drivers/fpga/altera-pr-ip-core-plat.c
> @@ -28,15 +28,6 @@ static int alt_pr_platform_probe(struct platform_device *pdev)
>  	return alt_pr_register(dev, reg_base);
>  }
>  
> -static int alt_pr_platform_remove(struct platform_device *pdev)
> -{
> -	struct device *dev = &pdev->dev;
> -
> -	alt_pr_unregister(dev);
> -
> -	return 0;
> -}
> -
>  static const struct of_device_id alt_pr_of_match[] = {
>  	{ .compatible = "altr,a10-pr-ip", },
>  	{},
> @@ -46,7 +37,6 @@ MODULE_DEVICE_TABLE(of, alt_pr_of_match);
>  
>  static struct platform_driver alt_pr_platform_driver = {
>  	.probe = alt_pr_platform_probe,
> -	.remove = alt_pr_platform_remove,
>  	.driver = {
>  		.name	= "alt_a10_pr_ip",
>  		.of_match_table = alt_pr_of_match,
> diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c
> index 2cf25fd5e897..5b130c4d9882 100644
> --- a/drivers/fpga/altera-pr-ip-core.c
> +++ b/drivers/fpga/altera-pr-ip-core.c
> @@ -195,9 +195,7 @@ int alt_pr_register(struct device *dev, void __iomem *reg_base)
>  	if (!mgr)
>  		return -ENOMEM;
>  
> -	dev_set_drvdata(dev, mgr);
> -
> -	return fpga_mgr_register(mgr);
> +	return devm_fpga_mgr_register(dev, mgr);
>  }
>  EXPORT_SYMBOL_GPL(alt_pr_register);
>  


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API
  2020-10-05 17:37 ` [PATCH v2 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API Moritz Fischer
@ 2020-10-09 21:25   ` Moritz Fischer
  0 siblings, 0 replies; 13+ messages in thread
From: Moritz Fischer @ 2020-10-09 21:25 UTC (permalink / raw)
  To: Moritz Fischer
  Cc: linux-fpga, trix, hao.wu, michal.simek, linux-kernel,
	linux-arm-kernel, russell.h.weight, matthew.gerlach

On Mon, Oct 05, 2020 at 10:37:26AM -0700, Moritz Fischer wrote:
> Add a devm_fpga_mgr_register() API that can be used to register a FPGA
> Manager that was created using devm_fpga_mgr_create().
> 
> Introduce a struct fpga_mgr_devres that makes the devres
> allocation a little bit more readable and gets reused for
> devm_fpga_mgr_create() devm_fpga_mgr_register().
> 
> Reviewed-by: Tom Rix <trix@redhat.com>
> Signed-off-by: Moritz Fischer <mdf@kernel.org>
> ---
>  drivers/fpga/fpga-mgr.c       | 81 +++++++++++++++++++++++++++++------
>  include/linux/fpga/fpga-mgr.h |  2 +
>  2 files changed, 71 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index f38bab01432e..b85bc47c91a9 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -21,6 +21,10 @@
>  static DEFINE_IDA(fpga_mgr_ida);
>  static struct class *fpga_mgr_class;
>  
> +struct fpga_mgr_devres {
> +	struct fpga_manager *mgr;
> +};
> +
>  /**
>   * fpga_image_info_alloc - Allocate a FPGA image info struct
>   * @dev: owning device
> @@ -625,9 +629,9 @@ EXPORT_SYMBOL_GPL(fpga_mgr_free);
>  
>  static void devm_fpga_mgr_release(struct device *dev, void *res)
>  {
> -	struct fpga_manager *mgr = *(struct fpga_manager **)res;
> +	struct fpga_mgr_devres *dr = res;
>  
> -	fpga_mgr_free(mgr);
> +	fpga_mgr_free(dr->mgr);
>  }
>  
>  /**
> @@ -651,21 +655,21 @@ struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,
>  					  const struct fpga_manager_ops *mops,
>  					  void *priv)
>  {
> -	struct fpga_manager **ptr, *mgr;
> +	struct fpga_mgr_devres *dr;
>  
> -	ptr = devres_alloc(devm_fpga_mgr_release, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> +	dr = devres_alloc(devm_fpga_mgr_release, sizeof(*dr), GFP_KERNEL);
> +	if (!dr)
>  		return NULL;
>  
> -	mgr = fpga_mgr_create(dev, name, mops, priv);
> -	if (!mgr) {
> -		devres_free(ptr);
> -	} else {
> -		*ptr = mgr;
> -		devres_add(dev, ptr);
> +	dr->mgr = fpga_mgr_create(dev, name, mops, priv);
> +	if (!dr->mgr) {
> +		devres_free(dr);
> +		return NULL;
>  	}
>  
> -	return mgr;
> +	devres_add(dev, dr);
> +
> +	return dr->mgr;
>  }
>  EXPORT_SYMBOL_GPL(devm_fpga_mgr_create);
>  
> @@ -722,6 +726,59 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)
>  }
>  EXPORT_SYMBOL_GPL(fpga_mgr_unregister);
>  
> +static int fpga_mgr_devres_match(struct device *dev, void *res,
> +				 void *match_data)
> +{
> +	struct fpga_mgr_devres *dr = res;
> +
> +	return match_data == dr->mgr;
> +}
> +
> +static void devm_fpga_mgr_unregister(struct device *dev, void *res)
> +{
> +	struct fpga_mgr_devres *dr = res;
> +
> +	fpga_mgr_unregister(dr->mgr);
> +}
> +
> +/**
> + * devm_fpga_mgr_register - resource managed variant of fpga_mgr_register()
> + * @dev: managing device for this FPGA manager
> + * @mgr: fpga manager struct
> + *
> + * This is the devres variant of fpga_mgr_register() for which the unregister
> + * function will be called automatically when the managing device is detached.
> + */
> +int devm_fpga_mgr_register(struct device *dev, struct fpga_manager *mgr)
> +{
> +	struct fpga_mgr_devres *dr;
> +	int ret;
> +
> +	/*
> +	 * Make sure that the struct fpga_manager * that is passed in is
> +	 * managed itself.
> +	 */
> +	if (WARN_ON(!devres_find(dev, devm_fpga_mgr_release,
> +				 fpga_mgr_devres_match, mgr)))
> +		return -EINVAL;
> +
> +	dr = devres_alloc(devm_fpga_mgr_unregister, sizeof(*dr), GFP_KERNEL);
> +	if (!dr)
> +		return -ENOMEM;
> +
> +	ret = fpga_mgr_register(mgr);
> +	if (ret) {
> +		devres_free(dr);
> +		return ret;
> +	}
> +
> +	dr->mgr = mgr;
> +	devres_add(dev, dr);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(devm_fpga_mgr_register);
> +
>  static void fpga_mgr_dev_release(struct device *dev)
>  {
>  }
> diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h
> index e8ca62b2cb5b..2bc3030a69e5 100644
> --- a/include/linux/fpga/fpga-mgr.h
> +++ b/include/linux/fpga/fpga-mgr.h
> @@ -198,6 +198,8 @@ void fpga_mgr_free(struct fpga_manager *mgr);
>  int fpga_mgr_register(struct fpga_manager *mgr);
>  void fpga_mgr_unregister(struct fpga_manager *mgr);
>  
> +int devm_fpga_mgr_register(struct device *dev, struct fpga_manager *mgr);
> +
>  struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name,
>  					  const struct fpga_manager_ops *mops,
>  					  void *priv);
> -- 
> 2.28.0
> 
Applied series to for-next,

Thanks

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-10-09 21:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 17:37 Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API Moritz Fischer
2020-10-09 21:25   ` Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 02/10] fpga: fpga-mgr: altera-ps-spi: Simplify registration Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 03/10] fpga: fpga-mgr: dfl-fme-mgr: " Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 04/10] fpga: fpga-mgr: ice40-spi: " Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 05/10] fpga: fpga-mgr: machxo2-spi: " Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 06/10] fpga: fpga-mgr: socfpga: " Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 07/10] fpga: fpga-mgr: ts73xx: " Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 08/10] fpga: fpga-mgr: xilinx-spi: " Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 09/10] fpga: fpga-mgr: zynqmp: " Moritz Fischer
2020-10-05 17:37 ` [PATCH v2 10/10] fpga: fpga-mgr: altera-pr-ip: " Moritz Fischer
2020-10-05 20:13   ` Tom Rix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).