Skip to contentSkip to conversation

media: imx-pxp: Check the return value from clk_prepare_enable()

PATCH Superseded Fabio Estevam 2 participants 6 messages Nov 6, 2018

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH v2 1/3 media: imx-pxp: Check the return value from clk_prepare_enable()

clk_prepare_enable() may fail, so we should better check its return value and propagate it in the case of error.

---
Changes since v1:
- Properly enumerate the series

 drivers/media/platform/imx-pxp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/imx-pxp.c +4 -1
index b76cd0e..27780f1 100644
@@ -1666,7 +1666,10 @@ static int pxp_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	clk_prepare_enable(dev->clk);
+	ret = clk_prepare_enable(dev->clk);
+	if (ret < 0)
+		return ret;
+
 	pxp_soft_reset(dev);
 
 	spin_lock_init(&dev->irqlock);
Signature · 1 line
2.7.4
author reviewer
#1 lore raw

PATCH v2 2/3 media: imx-pxp: Check for pxp_soft_reset() error

pxp_soft_reset() may fail with a timeout, so it is better to propagate the error in this case.

---
Changes since v1:
- None

 drivers/media/platform/imx-pxp.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/media/platform/imx-pxp.c +9 -3
index 27780f1..b3700b8 100644
@@ -1607,7 +1607,7 @@ static const struct v4l2_m2m_ops m2m_ops = {
 	.job_abort	= pxp_job_abort,
 };
 
-static void pxp_soft_reset(struct pxp_dev *dev)
+static int pxp_soft_reset(struct pxp_dev *dev)
 {
 	int ret;
 	u32 val;
@@ -1619,11 +1619,15 @@ static void pxp_soft_reset(struct pxp_dev *dev)
 
 	ret = readl_poll_timeout(dev->mmio + HW_PXP_CTRL, val,
 				 val & BM_PXP_CTRL_CLKGATE, 0, 100);
-	if (ret < 0)
+	if (ret < 0) {
 		pr_err("PXP reset timeout\n");
+		return ret;
+	}
 
 	writel(BM_PXP_CTRL_SFTRST, dev->mmio + HW_PXP_CTRL_CLR);
 	writel(BM_PXP_CTRL_CLKGATE, dev->mmio + HW_PXP_CTRL_CLR);
+
+	return 0;
 }
 
 static int pxp_probe(struct platform_device *pdev)
@@ -1670,7 +1674,9 @@ static int pxp_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
-	pxp_soft_reset(dev);
+	ret = pxp_soft_reset(dev);
+	if (ret < 0)
+		return ret;
 
 	spin_lock_init(&dev->irqlock);
 
Signature · 1 line
2.7.4
Reviewed-by on v2 2/3
#2 lore raw

Re: [PATCH v2 2/3] media: imx-pxp: Check for pxp_soft_reset() error

Quoted 25 lines · Fabio Estevam

pxp_soft_reset() may fail with a timeout, so it is better to propagate the error in this case.

---
Changes since v1:
- None

 drivers/media/platform/imx-pxp.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/media/platform/imx-pxp.c +1 -1
index 27780f1..b3700b8 100644
@@ -1607,7 +1607,7 @@ static const struct v4l2_m2m_ops m2m_ops = {
 	.job_abort	= pxp_job_abort,
 };
 
-static void pxp_soft_reset(struct pxp_dev *dev)
+static int pxp_soft_reset(struct pxp_dev *dev)
 {
 	int ret;
 	u32 val;

drivers/media/platform/imx-pxp.c static void pxp_soft_reset(struct pxp_dev *dev) · line 1627

Quoted 10 lines
drivers/media/platform/imx-pxp.c +3 -1
@@ -1619,11 +1619,15 @@ static void pxp_soft_reset(struct pxp_dev *dev)
 
 	ret = readl_poll_timeout(dev->mmio + HW_PXP_CTRL, val,
 				 val & BM_PXP_CTRL_CLKGATE, 0, 100);
-	if (ret < 0)
+	if (ret < 0) {
 		pr_err("PXP reset timeout\n");
+		return ret;
+	}
 
 	writel(BM_PXP_CTRL_SFTRST, dev->mmio + HW_PXP_CTRL_CLR);

I'm not sure if we should clear SFTRST again after a timeout. It probably doesn't matter as something went wrong anyway and the next probe will try to clear it again.

drivers/media/platform/imx-pxp.c static void pxp_soft_reset(struct pxp_dev *dev) · line 1628

Quoted 1 line
drivers/media/platform/imx-pxp.c +0 -0
 	writel(BM_PXP_CTRL_CLKGATE, dev->mmio + HW_PXP_CTRL_CLR);

Clearing CLKGATE if it was not set by the SFTRST in time should have no effect, so we could do this unconditionally as well.

drivers/media/platform/imx-pxp.c static void pxp_soft_reset(struct pxp_dev *dev) · line 1630

Quoted 2 lines
drivers/media/platform/imx-pxp.c +2 -0
+
+	return 0;

So you could just "return ret;" here instead of breaking out above. I have no preference either way.

drivers/media/platform/imx-pxp.c static int pxp_probe(struct platform_device *pdev) · line 1679

Quoted 11 lines
drivers/media/platform/imx-pxp.c +3 -1
 }
 
 static int pxp_probe(struct platform_device *pdev)
@@ -1670,7 +1674,9 @@ static int pxp_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
-	pxp_soft_reset(dev);
+	ret = pxp_soft_reset(dev);
+	if (ret < 0)
+		return ret;

This should "goto err_clk;" instead, though. With that changed,

regards
Philipp

author reviewer
#3 lore raw

PATCH v2 3/3 media: imx-pxp: Improve pxp_soft_reset() error message

In reply to Fabio Estevam

Improve the pxp_soft_reset() error message by moving it to the caller function, associating it with a proper device and also by displaying the error code.

---
Changes since v1:
- Newly introduced in this version

 drivers/media/platform/imx-pxp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/imx-pxp.c +4 -4
index b3700b8..1b765c9 100644
@@ -1619,10 +1619,8 @@ static int pxp_soft_reset(struct pxp_dev *dev)
 
 	ret = readl_poll_timeout(dev->mmio + HW_PXP_CTRL, val,
 				 val & BM_PXP_CTRL_CLKGATE, 0, 100);
-	if (ret < 0) {
-		pr_err("PXP reset timeout\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	writel(BM_PXP_CTRL_SFTRST, dev->mmio + HW_PXP_CTRL_CLR);
 	writel(BM_PXP_CTRL_CLKGATE, dev->mmio + HW_PXP_CTRL_CLR);
@@ -1675,8 +1673,10 @@ static int pxp_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = pxp_soft_reset(dev);
-	if (ret < 0)
+	if (ret < 0) {
+		dev_err(&pdev->dev, "PXP reset timeout: %d\n", ret);
 		return ret;
+	}
 
 	spin_lock_init(&dev->irqlock);
 
Signature · 1 line
2.7.4
Reviewed-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] media: imx-pxp: Improve pxp_soft_reset() error message

Quoted 29 lines · Fabio Estevam

Improve the pxp_soft_reset() error message by moving it to the caller function, associating it with a proper device and also by displaying the error code.

---
Changes since v1:
- Newly introduced in this version

 drivers/media/platform/imx-pxp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/imx-pxp.c +1 -3
index b3700b8..1b765c9 100644
@@ -1619,10 +1619,8 @@ static int pxp_soft_reset(struct pxp_dev *dev)
 
 	ret = readl_poll_timeout(dev->mmio + HW_PXP_CTRL, val,
 				 val & BM_PXP_CTRL_CLKGATE, 0, 100);
-	if (ret < 0) {
-		pr_err("PXP reset timeout\n");
+	if (ret < 0)
 		return ret;
-	}
 
 	writel(BM_PXP_CTRL_SFTRST, dev->mmio + HW_PXP_CTRL_CLR);
 	writel(BM_PXP_CTRL_CLKGATE, dev->mmio + HW_PXP_CTRL_CLR);

drivers/media/platform/imx-pxp.c static int pxp_probe(struct platform_device *pdev) · line 1681

Quoted 10 lines
drivers/media/platform/imx-pxp.c +3 -1
@@ -1675,8 +1673,10 @@ static int pxp_probe(struct platform_device *pdev)
 		return ret;
 
 	ret = pxp_soft_reset(dev);
-	if (ret < 0)
+	if (ret < 0) {
+		dev_err(&pdev->dev, "PXP reset timeout: %d\n", ret);
 		return ret;
+	}
 
 	spin_lock_init(&dev->irqlock);

This should be rebased onto the fixed 2/2 or squashed into it, but otherwise

regards
Philipp

Reviewed-by on v2 1/3
#5 lore raw
In reply to Fabio Estevam

Hi Fabio,

thank you for the fixes!

Quoted 17 lines · Fabio Estevam

clk_prepare_enable() may fail, so we should better check its return value and propagate it in the case of error.

---
Changes since v1:
- Properly enumerate the series

 drivers/media/platform/imx-pxp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/imx-pxp.c +0 -0
index b76cd0e..27780f1 100644
@@ -1666,7 +1666,10 @@ static int pxp_probe(struct platform_device *pdev)
 		return ret;

drivers/media/platform/imx-pxp.c static int pxp_probe(struct platform_device *pdev) · line 1675

Quoted 10 lines
drivers/media/platform/imx-pxp.c +4 -1
 	}
 
-	clk_prepare_enable(dev->clk);
+	ret = clk_prepare_enable(dev->clk);
+	if (ret < 0)
+		return ret;
+
 	pxp_soft_reset(dev);
 
 	spin_lock_init(&dev->irqlock);

regards
Philipp