linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] patches for fpga
@ 2017-04-24 21:34 Alan Tull
  2017-04-24 21:34 ` [PATCH 1/3] fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe() Alan Tull
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alan Tull @ 2017-04-24 21:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Moritz Fischer, Alan Tull, linux-kernel, linux-fpga

Hi Greg,

Please take these three patches that fix minor
things for FPGA.  All have been reviewed on the
mailing lists.

Thanks,
Alan

Matthew Gerlach (1):
  fpga fr br: update supported version numbers

Tobias Klauser (2):
  fpga altera-hps2fpga: disable/unprepare clock on error in
    alt_fpga_bridge_probe()
  fpga: region: release FPGA region reference in error path

 drivers/fpga/altera-freeze-bridge.c | 30 +++++++++++++++++++-----------
 drivers/fpga/altera-hps2fpga.c      | 15 +++++++++------
 drivers/fpga/fpga-region.c          |  4 +++-
 3 files changed, 31 insertions(+), 18 deletions(-)

-- 
2.7.4

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

* [PATCH 1/3] fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe()
  2017-04-24 21:34 [PATCH 0/3] patches for fpga Alan Tull
@ 2017-04-24 21:34 ` Alan Tull
  2017-04-24 21:34 ` [PATCH 2/3] fpga: region: release FPGA region reference in error path Alan Tull
  2017-04-24 21:34 ` [PATCH 3/3] fpga fr br: update supported version numbers Alan Tull
  2 siblings, 0 replies; 4+ messages in thread
From: Alan Tull @ 2017-04-24 21:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Moritz Fischer, Alan Tull, linux-kernel, linux-fpga, Tobias Klauser

From: Tobias Klauser <tklauser@distanz.ch>

If either _alt_hps2fpga_enable_set() or fpga_bridge_register() fail in
alt_fpga_bridge_probe(), the clock remains enabled and prepared. Also,
in the error path for _alt_hps2fpga_enable_set() a call to
fpga_bridge_unregister() is made even though the bridge was not
registered yet.

Remove the unnecessary call to fpga_bridge_unregister() and call
clk_disable_unprepare() in both error paths in order to make sure the
clock gets properly disabled and unprepared.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Acked-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Alan Tull <atull@kernel.org>
---
 drivers/fpga/altera-hps2fpga.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/fpga/altera-hps2fpga.c b/drivers/fpga/altera-hps2fpga.c
index 4b354c7..3066b80 100644
--- a/drivers/fpga/altera-hps2fpga.c
+++ b/drivers/fpga/altera-hps2fpga.c
@@ -181,15 +181,18 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev)
 				 (enable ? "enabling" : "disabling"));
 
 			ret = _alt_hps2fpga_enable_set(priv, enable);
-			if (ret) {
-				fpga_bridge_unregister(&pdev->dev);
-				return ret;
-			}
+			if (ret)
+				goto err;
 		}
 	}
 
-	return fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops,
-				    priv);
+	ret = fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops,
+				   priv);
+err:
+	if (ret)
+		clk_disable_unprepare(priv->clk);
+
+	return ret;
 }
 
 static int alt_fpga_bridge_remove(struct platform_device *pdev)
-- 
2.7.4

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

* [PATCH 2/3] fpga: region: release FPGA region reference in error path
  2017-04-24 21:34 [PATCH 0/3] patches for fpga Alan Tull
  2017-04-24 21:34 ` [PATCH 1/3] fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe() Alan Tull
@ 2017-04-24 21:34 ` Alan Tull
  2017-04-24 21:34 ` [PATCH 3/3] fpga fr br: update supported version numbers Alan Tull
  2 siblings, 0 replies; 4+ messages in thread
From: Alan Tull @ 2017-04-24 21:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Moritz Fischer, Alan Tull, linux-kernel, linux-fpga, Tobias Klauser

From: Tobias Klauser <tklauser@distanz.ch>

If fpga_region_get_manager() fails in fpga_region_program_fpga(), a
reference to the fpga_manager instance previously acquired through
fpga_region_get() is retained. Make sure to properly release it in the
error case by using a separate jump label which will call
fpga_region_put() in before returning.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Acked-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Alan Tull <atull@kernel.org>
---
 drivers/fpga/fpga-region.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c
index ae4c61a..3b6b2f4 100644
--- a/drivers/fpga/fpga-region.c
+++ b/drivers/fpga/fpga-region.c
@@ -245,7 +245,8 @@ static int fpga_region_program_fpga(struct fpga_region *region,
 	mgr = fpga_region_get_manager(region);
 	if (IS_ERR(mgr)) {
 		pr_err("failed to get fpga region manager\n");
-		return PTR_ERR(mgr);
+		ret = PTR_ERR(mgr);
+		goto err_put_region;
 	}
 
 	ret = fpga_region_get_bridges(region, overlay);
@@ -281,6 +282,7 @@ static int fpga_region_program_fpga(struct fpga_region *region,
 	fpga_bridges_put(&region->bridge_list);
 err_put_mgr:
 	fpga_mgr_put(mgr);
+err_put_region:
 	fpga_region_put(region);
 
 	return ret;
-- 
2.7.4

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

* [PATCH 3/3] fpga fr br: update supported version numbers
  2017-04-24 21:34 [PATCH 0/3] patches for fpga Alan Tull
  2017-04-24 21:34 ` [PATCH 1/3] fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe() Alan Tull
  2017-04-24 21:34 ` [PATCH 2/3] fpga: region: release FPGA region reference in error path Alan Tull
@ 2017-04-24 21:34 ` Alan Tull
  2 siblings, 0 replies; 4+ messages in thread
From: Alan Tull @ 2017-04-24 21:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Moritz Fischer, Alan Tull, linux-kernel, linux-fpga, Matthew Gerlach

From: Matthew Gerlach <matthew.gerlach@linux.intel.com>

The value in the version register of the altera freeze bridge
controller changed from the beta value of 2 to the
value of 0xad000003 in the official release of the IP.
This patch supports the old and new version numbers, and the
driver's probe function will fail if neither of the supported
versions is found.

Signed-off-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
Reviewed-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Alan Tull <atull@kernel.org>
---
 drivers/fpga/altera-freeze-bridge.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/fpga/altera-freeze-bridge.c b/drivers/fpga/altera-freeze-bridge.c
index 8c1bc7e..6159cfcf 100644
--- a/drivers/fpga/altera-freeze-bridge.c
+++ b/drivers/fpga/altera-freeze-bridge.c
@@ -28,6 +28,7 @@
 #define FREEZE_CSR_REG_VERSION			12
 
 #define FREEZE_CSR_SUPPORTED_VERSION		2
+#define FREEZE_CSR_OFFICIAL_VERSION		0xad000003
 
 #define FREEZE_CSR_STATUS_FREEZE_REQ_DONE	BIT(0)
 #define FREEZE_CSR_STATUS_UNFREEZE_REQ_DONE	BIT(1)
@@ -218,6 +219,7 @@ static int altera_freeze_br_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct device_node *np = pdev->dev.of_node;
+	void __iomem *base_addr;
 	struct altera_freeze_br_data *priv;
 	struct resource *res;
 	u32 status, revision;
@@ -225,26 +227,32 @@ static int altera_freeze_br_probe(struct platform_device *pdev)
 	if (!np)
 		return -ENODEV;
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base_addr = devm_ioremap_resource(dev, res);
+	if (IS_ERR(base_addr))
+		return PTR_ERR(base_addr);
+
+	revision = readl(base_addr + FREEZE_CSR_REG_VERSION);
+	if ((revision != FREEZE_CSR_SUPPORTED_VERSION) &&
+	    (revision != FREEZE_CSR_OFFICIAL_VERSION)) {
+		dev_err(dev,
+			"%s unexpected revision 0x%x != 0x%x != 0x%x\n",
+			__func__, revision, FREEZE_CSR_SUPPORTED_VERSION,
+			FREEZE_CSR_OFFICIAL_VERSION);
+		return -EINVAL;
+	}
+
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
 	priv->dev = dev;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	priv->base_addr = devm_ioremap_resource(dev, res);
-	if (IS_ERR(priv->base_addr))
-		return PTR_ERR(priv->base_addr);
-
-	status = readl(priv->base_addr + FREEZE_CSR_STATUS_OFFSET);
+	status = readl(base_addr + FREEZE_CSR_STATUS_OFFSET);
 	if (status & FREEZE_CSR_STATUS_UNFREEZE_REQ_DONE)
 		priv->enable = 1;
 
-	revision = readl(priv->base_addr + FREEZE_CSR_REG_VERSION);
-	if (revision != FREEZE_CSR_SUPPORTED_VERSION)
-		dev_warn(dev,
-			 "%s Freeze Controller unexpected revision %d != %d\n",
-			 __func__, revision, FREEZE_CSR_SUPPORTED_VERSION);
+	priv->base_addr = base_addr;
 
 	return fpga_bridge_register(dev, FREEZE_BRIDGE_NAME,
 				    &altera_freeze_br_br_ops, priv);
-- 
2.7.4

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

end of thread, other threads:[~2017-04-24 21:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-24 21:34 [PATCH 0/3] patches for fpga Alan Tull
2017-04-24 21:34 ` [PATCH 1/3] fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe() Alan Tull
2017-04-24 21:34 ` [PATCH 2/3] fpga: region: release FPGA region reference in error path Alan Tull
2017-04-24 21:34 ` [PATCH 3/3] fpga fr br: update supported version numbers Alan Tull

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