2020-10-04 05:16:12

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 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.

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


2020-10-04 05:16:12

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 02/10] fpga: fpga-mgr: altera-ps-spi: Simplify registration

Simplify registration by using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
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

2020-10-04 05:16:14

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API

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().

Signed-off-by: Moritz Fischer <[email protected]>
---
drivers/fpga/fpga-mgr.c | 76 ++++++++++++++++++++++++++++++-----
include/linux/fpga/fpga-mgr.h | 2 +
2 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
index f38bab01432e..774ac98fb69c 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
@@ -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,58 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)
}
EXPORT_SYMBOL_GPL(fpga_mgr_unregister);

+static int fpga_mgr_devres_match(struct device *dev, void *priv,
+ void *match_data)
+{
+ struct fpga_mgr_devres *dr = priv;
+
+ return match_data == dr->mgr;
+}
+
+static void devm_fpga_mgr_unregister(struct device *dev, void *priv)
+{
+ struct fpga_mgr_devres *dr = priv;
+
+ 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 err;
+
+ /* 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;
+
+ err = fpga_mgr_register(mgr);
+ if (err) {
+ devres_free(dr);
+ return err;
+ }
+
+ 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

2020-10-04 05:16:21

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 04/10] fpga: fpga-mgr: ice40-spi: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
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

2020-10-04 05:16:25

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 03/10] fpga: fpga-mgr: dfl-fme-mgr: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
drivers/fpga/dfl-fme-mgr.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/fpga/dfl-fme-mgr.c b/drivers/fpga/dfl-fme-mgr.c
index b3f7eee3c93f..3fc2be87d059 100644
--- a/drivers/fpga/dfl-fme-mgr.c
+++ b/drivers/fpga/dfl-fme-mgr.c
@@ -316,16 +316,7 @@ static int fme_mgr_probe(struct platform_device *pdev)
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 +324,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

2020-10-04 05:16:33

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 07/10] fpga: fpga-mgr: ts73xx: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
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

2020-10-04 05:17:15

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 09/10] fpga: fpga-mgr: zynqmp: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
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

2020-10-04 05:17:20

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 05/10] fpga: fpga-mgr: machxo2-spi: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
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

2020-10-04 05:17:39

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 06/10] fpga: fpga-mgr: socfpga: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
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

2020-10-04 05:17:53

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 10/10] fpga: fpga-mgr: altera-pr-ip: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.
Remove the now obsolete altera_pr_unregister() function.

Signed-off-by: Moritz Fischer <[email protected]>
---

We should take another look at this, IIRC correctly the point of
splitting this up into a separate driver was to make it useable by a
different (pci?) driver later on.

It doesn't seem like this happened, and I think we should just make this
a platform driver?

---
drivers/fpga/altera-pr-ip-core-plat.c | 10 ----------
drivers/fpga/altera-pr-ip-core.c | 14 +-------------
include/linux/fpga/altera-pr-ip-core.h | 1 -
3 files changed, 1 insertion(+), 24 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..dfdf21ed34c4 100644
--- a/drivers/fpga/altera-pr-ip-core.c
+++ b/drivers/fpga/altera-pr-ip-core.c
@@ -195,22 +195,10 @@ 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);

-void alt_pr_unregister(struct device *dev)
-{
- struct fpga_manager *mgr = dev_get_drvdata(dev);
-
- dev_dbg(dev, "%s\n", __func__);
-
- fpga_mgr_unregister(mgr);
-}
-EXPORT_SYMBOL_GPL(alt_pr_unregister);
-
MODULE_AUTHOR("Matthew Gerlach <[email protected]>");
MODULE_DESCRIPTION("Altera Partial Reconfiguration IP Core");
MODULE_LICENSE("GPL v2");
diff --git a/include/linux/fpga/altera-pr-ip-core.h b/include/linux/fpga/altera-pr-ip-core.h
index 0b08ac20ab16..a6b4c07858cc 100644
--- a/include/linux/fpga/altera-pr-ip-core.h
+++ b/include/linux/fpga/altera-pr-ip-core.h
@@ -13,6 +13,5 @@
#include <linux/io.h>

int alt_pr_register(struct device *dev, void __iomem *reg_base);
-void alt_pr_unregister(struct device *dev);

#endif /* _ALT_PR_IP_CORE_H */
--
2.28.0

2020-10-04 05:19:19

by Moritz Fischer

[permalink] [raw]
Subject: [PATCH 08/10] fpga: fpga-mgr: xilinx-spi: Simplify registration

Simplify registration using new devm_fpga_mgr_register() API.

Signed-off-by: Moritz Fischer <[email protected]>
---
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

2020-10-04 18:10:14

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API


On 10/3/20 10:14 PM, 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().
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/fpga-mgr.c | 76 ++++++++++++++++++++++++++++++-----
> include/linux/fpga/fpga-mgr.h | 2 +
> 2 files changed, 68 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index f38bab01432e..774ac98fb69c 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
> @@ -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,58 @@ void fpga_mgr_unregister(struct fpga_manager *mgr)
> }
> EXPORT_SYMBOL_GPL(fpga_mgr_unregister);
>
> +static int fpga_mgr_devres_match(struct device *dev, void *priv,
> + void *match_data)
> +{
> + struct fpga_mgr_devres *dr = priv;
> +
> + return match_data == dr->mgr;
> +}
> +
> +static void devm_fpga_mgr_unregister(struct device *dev, void *priv)
> +{
> + struct fpga_mgr_devres *dr = priv;
> +
> + 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 err;

nit

int ret;

Fine if it isn't changed.

Reviewed-by: Tom Rix <[email protected]>

> +
> + /* 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;
> +
> + err = fpga_mgr_register(mgr);
> + if (err) {
> + devres_free(dr);
> + return err;
> + }
> +
> + 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);

2020-10-04 18:17:29

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 02/10] fpga: fpga-mgr: altera-ps-spi: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration by using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/altera-ps-spi.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)

Looks fine

Reviewed-by: Tom Rix <[email protected]>

2020-10-04 18:24:08

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 03/10] fpga: fpga-mgr: dfl-fme-mgr: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/dfl-fme-mgr.c | 12 +-----------
> 1 file changed, 1 insertion(+), 11 deletions(-)
>
> diff --git a/drivers/fpga/dfl-fme-mgr.c b/drivers/fpga/dfl-fme-mgr.c
> index b3f7eee3c93f..3fc2be87d059 100644
> --- a/drivers/fpga/dfl-fme-mgr.c
> +++ b/drivers/fpga/dfl-fme-mgr.c
> @@ -316,16 +316,7 @@ static int fme_mgr_probe(struct platform_device *pdev)
> mgr->compat_id = compat_id;
> platform_set_drvdata(pdev, mgr);

Is this call is still needed ?

Tom

>
> - 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 +324,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);

2020-10-04 18:26:06

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 04/10] fpga: fpga-mgr: ice40-spi: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/ice40-spi.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)

LOTM

Reviewed-by: Tom Rix <[email protected]>


2020-10-04 18:27:38

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 05/10] fpga: fpga-mgr: machxo2-spi: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/machxo2-spi.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)

LOTM

Reviewed-by: Tom Rix <[email protected]>


2020-10-04 18:28:39

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 06/10] fpga: fpga-mgr: socfpga: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/socfpga.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)

LOTM

Reviewed-by: Tom Rix <[email protected]>


2020-10-04 18:30:04

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 07/10] fpga: fpga-mgr: ts73xx: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/ts73xx-fpga.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)

LOTM

Reviewed-by: Tom Rix <[email protected]>


2020-10-04 18:32:14

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 08/10] fpga: fpga-mgr: xilinx-spi: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/xilinx-spi.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)

LOTM

Reviewed-by: Tom Rix <[email protected]>


2020-10-04 18:35:32

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 09/10] fpga: fpga-mgr: zynqmp: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/zynqmp-fpga.c | 21 +--------------------
> 1 file changed, 1 insertion(+), 20 deletions(-)

LOTM

Reviewed-by: Tom Rix <[email protected]>


2020-10-04 18:50:05

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH 10/10] fpga: fpga-mgr: altera-pr-ip: Simplify registration


On 10/3/20 10:14 PM, Moritz Fischer wrote:
> Simplify registration using new devm_fpga_mgr_register() API.
> Remove the now obsolete altera_pr_unregister() function.
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
>
> We should take another look at this, IIRC correctly the point of
> splitting this up into a separate driver was to make it useable by a
> different (pci?) driver later on.
>
> It doesn't seem like this happened, and I think we should just make this
> a platform driver?
>
> ---
> drivers/fpga/altera-pr-ip-core-plat.c | 10 ----------
> drivers/fpga/altera-pr-ip-core.c | 14 +-------------
> include/linux/fpga/altera-pr-ip-core.h | 1 -
> 3 files changed, 1 insertion(+), 24 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..dfdf21ed34c4 100644
> --- a/drivers/fpga/altera-pr-ip-core.c
> +++ b/drivers/fpga/altera-pr-ip-core.c
> @@ -195,22 +195,10 @@ 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);
>
> -void alt_pr_unregister(struct device *dev)
> -{
> - struct fpga_manager *mgr = dev_get_drvdata(dev);
> -
> - dev_dbg(dev, "%s\n", __func__);
> -
> - fpga_mgr_unregister(mgr);
> -}
> -EXPORT_SYMBOL_GPL(alt_pr_unregister);

Similar to the others, except for removing this symbol.

A patch should do one logical thing.

I'd rather this be split out of the patchset.

Tom

> -
> MODULE_AUTHOR("Matthew Gerlach <[email protected]>");
> MODULE_DESCRIPTION("Altera Partial Reconfiguration IP Core");
> MODULE_LICENSE("GPL v2");
> diff --git a/include/linux/fpga/altera-pr-ip-core.h b/include/linux/fpga/altera-pr-ip-core.h
> index 0b08ac20ab16..a6b4c07858cc 100644
> --- a/include/linux/fpga/altera-pr-ip-core.h
> +++ b/include/linux/fpga/altera-pr-ip-core.h
> @@ -13,6 +13,5 @@
> #include <linux/io.h>
>
> int alt_pr_register(struct device *dev, void __iomem *reg_base);
> -void alt_pr_unregister(struct device *dev);
>
> #endif /* _ALT_PR_IP_CORE_H */

2020-10-04 23:40:44

by Moritz Fischer

[permalink] [raw]
Subject: Re: [PATCH 10/10] fpga: fpga-mgr: altera-pr-ip: Simplify registration

On Sun, Oct 04, 2020 at 11:47:26AM -0700, Tom Rix wrote:
>
> On 10/3/20 10:14 PM, Moritz Fischer wrote:
> > Simplify registration using new devm_fpga_mgr_register() API.
> > Remove the now obsolete altera_pr_unregister() function.
> >
> > Signed-off-by: Moritz Fischer <[email protected]>
> > ---
> >
> > We should take another look at this, IIRC correctly the point of
> > splitting this up into a separate driver was to make it useable by a
> > different (pci?) driver later on.
> >
> > It doesn't seem like this happened, and I think we should just make this
> > a platform driver?
> >
> > ---
> > drivers/fpga/altera-pr-ip-core-plat.c | 10 ----------
> > drivers/fpga/altera-pr-ip-core.c | 14 +-------------
> > include/linux/fpga/altera-pr-ip-core.h | 1 -
> > 3 files changed, 1 insertion(+), 24 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..dfdf21ed34c4 100644
> > --- a/drivers/fpga/altera-pr-ip-core.c
> > +++ b/drivers/fpga/altera-pr-ip-core.c
> > @@ -195,22 +195,10 @@ 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);
> >
> > -void alt_pr_unregister(struct device *dev)
> > -{
> > - struct fpga_manager *mgr = dev_get_drvdata(dev);
> > -
> > - dev_dbg(dev, "%s\n", __func__);
> > -
> > - fpga_mgr_unregister(mgr);
> > -}
> > -EXPORT_SYMBOL_GPL(alt_pr_unregister);
>
> Similar to the others, except for removing this symbol.
>
> A patch should do one logical thing.

I was on the fence with this. Tbh, this driver should be a platform
driver. I'll create a separate series for that.

>
> I'd rather this be split out of the patchset.
>
> Tom
>
> > -
> > MODULE_AUTHOR("Matthew Gerlach <[email protected]>");
> > MODULE_DESCRIPTION("Altera Partial Reconfiguration IP Core");
> > MODULE_LICENSE("GPL v2");
> > diff --git a/include/linux/fpga/altera-pr-ip-core.h b/include/linux/fpga/altera-pr-ip-core.h
> > index 0b08ac20ab16..a6b4c07858cc 100644
> > --- a/include/linux/fpga/altera-pr-ip-core.h
> > +++ b/include/linux/fpga/altera-pr-ip-core.h
> > @@ -13,6 +13,5 @@
> > #include <linux/io.h>
> >
> > int alt_pr_register(struct device *dev, void __iomem *reg_base);
> > -void alt_pr_unregister(struct device *dev);
> >
> > #endif /* _ALT_PR_IP_CORE_H */
>

Cheers,
Moritz

2020-10-04 23:41:32

by Moritz Fischer

[permalink] [raw]
Subject: Re: [PATCH 03/10] fpga: fpga-mgr: dfl-fme-mgr: Simplify registration

On Sun, Oct 04, 2020 at 11:22:31AM -0700, Tom Rix wrote:
>
> On 10/3/20 10:14 PM, Moritz Fischer wrote:
> > Simplify registration using new devm_fpga_mgr_register() API.
> >
> > Signed-off-by: Moritz Fischer <[email protected]>
> > ---
> > drivers/fpga/dfl-fme-mgr.c | 12 +-----------
> > 1 file changed, 1 insertion(+), 11 deletions(-)
> >
> > diff --git a/drivers/fpga/dfl-fme-mgr.c b/drivers/fpga/dfl-fme-mgr.c
> > index b3f7eee3c93f..3fc2be87d059 100644
> > --- a/drivers/fpga/dfl-fme-mgr.c
> > +++ b/drivers/fpga/dfl-fme-mgr.c
> > @@ -316,16 +316,7 @@ static int fme_mgr_probe(struct platform_device *pdev)
> > mgr->compat_id = compat_id;
> > platform_set_drvdata(pdev, mgr);
>
Nice catch. Will fix.
> Is this call is still needed ?
>
> Tom
>
> >
> > - 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 +324,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);
>

Cheers,
Moritz

2020-10-05 05:20:29

by Wu Hao

[permalink] [raw]
Subject: RE: [PATCH 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API

> Subject: [PATCH 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API
>
> 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().
>
> Signed-off-by: Moritz Fischer <[email protected]>
> ---
> drivers/fpga/fpga-mgr.c | 76 ++++++++++++++++++++++++++++++-----
> include/linux/fpga/fpga-mgr.h | 2 +
> 2 files changed, 68 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index f38bab01432e..774ac98fb69c 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
> @@ -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);

Should we update devm_fpga_mgr_release function to use fpga_mgr_devres as well?

> + 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,58 @@ void fpga_mgr_unregister(struct fpga_manager
> *mgr)
> }
> EXPORT_SYMBOL_GPL(fpga_mgr_unregister);
>
> +static int fpga_mgr_devres_match(struct device *dev, void *priv,

Maybe it's better to use "res" instead of "priv" which matches the
dr_match_t, and also devm_fpga_mgr_release function.

> + void *match_data)
> +{
> + struct fpga_mgr_devres *dr = priv;
> +
> + return match_data == dr->mgr;
> +}
> +
> +static void devm_fpga_mgr_unregister(struct device *dev, void *priv)
> +{

Same.

> + struct fpga_mgr_devres *dr = priv;
> +
> + 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 err;
> +
> + /* Make sure that the struct fpga_manager * that is passed in is
> + * managed itself.
> + */

Should we use the same style for code comments here,
I see other places in this file are using style like

/*
* ......
*/

Thanks
Hao

2020-10-05 16:49:05

by Moritz Fischer

[permalink] [raw]
Subject: Re: [PATCH 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API

Hi Hao,

On Mon, Oct 05, 2020 at 05:18:40AM +0000, Wu, Hao wrote:
> > Subject: [PATCH 01/10] fpga: fpga-mgr: Add devm_fpga_mgr_register() API
> >
> > 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().
> >
> > Signed-off-by: Moritz Fischer <[email protected]>
> > ---
> > drivers/fpga/fpga-mgr.c | 76 ++++++++++++++++++++++++++++++-----
> > include/linux/fpga/fpga-mgr.h | 2 +
> > 2 files changed, 68 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> > index f38bab01432e..774ac98fb69c 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
> > @@ -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);
>
> Should we update devm_fpga_mgr_release function to use fpga_mgr_devres as well?
Yes!
>
> > + 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,58 @@ void fpga_mgr_unregister(struct fpga_manager
> > *mgr)
> > }
> > EXPORT_SYMBOL_GPL(fpga_mgr_unregister);
> >
> > +static int fpga_mgr_devres_match(struct device *dev, void *priv,
>
> Maybe it's better to use "res" instead of "priv" which matches the
> dr_match_t, and also devm_fpga_mgr_release function.
Can do.
>
> > + void *match_data)
> > +{
> > + struct fpga_mgr_devres *dr = priv;
> > +
> > + return match_data == dr->mgr;
> > +}
> > +
> > +static void devm_fpga_mgr_unregister(struct device *dev, void *priv)
> > +{
>
> Same.
Ditto.
>
> > + struct fpga_mgr_devres *dr = priv;
> > +
> > + 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 err;
> > +
> > + /* Make sure that the struct fpga_manager * that is passed in is
> > + * managed itself.
> > + */
>
> Should we use the same style for code comments here,
> I see other places in this file are using style like
Can do.
>
> /*
> * ......
> */
>
> Thanks
> Hao
Thanks,
Moritz