Skip to contentSkip to conversation

mfd: omap-usb-tll: check clk_prepare return code

PATCH In review Karol Przybylski 3 participants 7 messages Nov 13, 2024 – Dec 5, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: omap-usb-tll: check clk_prepare return code

clk_prepare() is called in usbtll_omap_probe to fill clk array. Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and dev_dbg statement when it's not successful.

Found in coverity scan, CID 1594680

---
 drivers/mfd/omap-usb-tll.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +7 -4
index 0f7fdb99c809..2e9319ee1b74 100644
@@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 	struct device				*dev =  &pdev->dev;
 	struct usbtll_omap			*tll;
 	void __iomem				*base;
-	int					i, nch, ver;
+	int					i, nch, ver, err;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 					"usb_tll_hs_usb_ch%d_clk", i);
 		tll->ch_clk[i] = clk_get(dev, clkname);
 
-		if (IS_ERR(tll->ch_clk[i]))
+		if (IS_ERR(tll->ch_clk[i])) {
 			dev_dbg(dev, "can't get clock : %s\n", clkname);
-		else
-			clk_prepare(tll->ch_clk[i]);
+		} else {
+			err = clk_prepare(tll->ch_clk[i]);
+			if (err)
+				dev_dbg(dev, "clock prepare error for: %s\n", clkname);
+		}
 	}
 
 	pm_runtime_put_sync(dev);
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi,

Quoted 29 lines · Karol Przybylski

clk_prepare() is called in usbtll_omap_probe to fill clk array. Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and dev_dbg statement when it's not successful.

Found in coverity scan, CID 1594680

---
 drivers/mfd/omap-usb-tll.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -1
index 0f7fdb99c809..2e9319ee1b74 100644
@@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 	struct device				*dev =  &pdev->dev;
 	struct usbtll_omap			*tll;
 	void __iomem				*base;
-	int					i, nch, ver;
+	int					i, nch, ver, err;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 					"usb_tll_hs_usb_ch%d_clk", i);
 		tll->ch_clk[i] = clk_get(dev, clkname);

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 256

Quoted 10 lines
drivers/mfd/omap-usb-tll.c +5 -3
 
-		if (IS_ERR(tll->ch_clk[i]))
+		if (IS_ERR(tll->ch_clk[i])) {
 			dev_dbg(dev, "can't get clock : %s\n", clkname);
-		else
-			clk_prepare(tll->ch_clk[i]);
+		} else {
+			err = clk_prepare(tll->ch_clk[i]);
+			if (err)
+				dev_dbg(dev, "clock prepare error for: %s\n", clkname);

dev_err()?

I think we should return the error in this case. (after unpreparing the prepared clocks and clk_put())

Quoted 4 lines
drivers/mfd/omap-usb-tll.c +1 -0
+		}
 	}
 
 	pm_runtime_put_sync(dev);
Signature · 2 lines
cheers,
-roger
maintainer
#2 lore raw

Am Tue, 19 Nov 2024 15:10:23 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 29 lines

Hi,

Quoted 26 lines · Karol Przybylski

clk_prepare() is called in usbtll_omap_probe to fill clk array. Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and dev_dbg statement when it's not successful.

Found in coverity scan, CID 1594680

---
 drivers/mfd/omap-usb-tll.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -1
index 0f7fdb99c809..2e9319ee1b74 100644
@@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 	struct device				*dev =  &pdev->dev;
 	struct usbtll_omap			*tll;
 	void __iomem				*base;
-	int					i, nch, ver;
+	int					i, nch, ver, err;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
Quoted 7 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252

Quoted 7 lines
drivers/mfd/omap-usb-tll.c +1 -1
@@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 					"usb_tll_hs_usb_ch%d_clk", i);
 		tll->ch_clk[i] = clk_get(dev, clkname);
 
-		if (IS_ERR(tll->ch_clk[i]))
+		if (IS_ERR(tll->ch_clk[i])) {
 			dev_dbg(dev, "can't get clock : %s\n", clkname);

if you want dev_err() later, then why not here?

Quoted 9 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 256

Quoted 6 lines
drivers/mfd/omap-usb-tll.c +4 -2
-		else
-			clk_prepare(tll->ch_clk[i]);
+		} else {
+			err = clk_prepare(tll->ch_clk[i]);
+			if (err)
+				dev_dbg(dev, "clock prepare error for: %s\n", clkname);  

dev_err()?

So why do you want a different return handling here? (I doubt there is any clock having a real prepare() involved here)

As said in an earlier incarnation of this patch, the real question is whether having partial clocks available is a valid operating scenario. If yes, then the error should be ignored. If no, then bailing out early is a good idea.

clk_prepare() errors are catched by failing clk_enable() later, ch_clk[i] is checked later, too.

Quoted 3 lines

I think we should return the error in this case. (after unpreparing the prepared clocks and clk_put())

and pm_runtime_put_sync(dev)

Regards,
Andreas

maintainer
#3 lore raw
Quoted 36 lines · Andreas Kemnade

Am Tue, 19 Nov 2024 15:10:23 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 33 lines

Hi,

Quoted 30 lines · Karol Przybylski

clk_prepare() is called in usbtll_omap_probe to fill clk array. Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and dev_dbg statement when it's not successful.

Found in coverity scan, CID 1594680

---
 drivers/mfd/omap-usb-tll.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -1
index 0f7fdb99c809..2e9319ee1b74 100644
@@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 	struct device				*dev =  &pdev->dev;
 	struct usbtll_omap			*tll;
 	void __iomem				*base;
-	int					i, nch, ver;
+	int					i, nch, ver, err;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 					"usb_tll_hs_usb_ch%d_clk", i);
 		tll->ch_clk[i] = clk_get(dev, clkname);
 
Quoted 5 lines
Quoted 3 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252

Quoted 3 lines
drivers/mfd/omap-usb-tll.c +1 -1
-		if (IS_ERR(tll->ch_clk[i]))
+		if (IS_ERR(tll->ch_clk[i])) {
 			dev_dbg(dev, "can't get clock : %s\n", clkname);

if you want dev_err() later, then why not here?

Because clk is optional. If it is not there then we should not complain. But if it is there then it needs to be enabled successfully.

Quoted 10 lines
Quoted 10 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 256

Quoted 7 lines
drivers/mfd/omap-usb-tll.c +4 -2
-		else
-			clk_prepare(tll->ch_clk[i]);
+		} else {
+			err = clk_prepare(tll->ch_clk[i]);
+			if (err)
+				dev_dbg(dev, "clock prepare error for: %s\n", clkname);  

dev_err()?

Quoted 7 lines

So why do you want a different return handling here? (I doubt there is any clock having a real prepare() involved here)

As said in an earlier incarnation of this patch, the real question is whether having partial clocks available is a valid operating scenario. If yes, then the error should be ignored. If no, then bailing out early is a good idea.

In the DT binding, clocks is optional. So if it doesn't exist it is not an error condition.

Quoted 11 lines

clk_prepare() errors are catched by failing clk_enable() later, ch_clk[i] is checked later, too.

Quoted 3 lines

I think we should return the error in this case. (after unpreparing the prepared clocks and clk_put())

and pm_runtime_put_sync(dev)

Regards,
Andreas

Signature · 2 lines
cheers,
-roger
maintainer
#4 lore raw

Am Tue, 19 Nov 2024 16:16:42 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 37 lines · Andreas Kemnade
Quoted 36 lines

Am Tue, 19 Nov 2024 15:10:23 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 33 lines

Hi,

Quoted 30 lines · Karol Przybylski

clk_prepare() is called in usbtll_omap_probe to fill clk array. Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and dev_dbg statement when it's not successful.

Found in coverity scan, CID 1594680

---
 drivers/mfd/omap-usb-tll.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -1
index 0f7fdb99c809..2e9319ee1b74 100644
@@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 	struct device				*dev =  &pdev->dev;
 	struct usbtll_omap			*tll;
 	void __iomem				*base;
-	int					i, nch, ver;
+	int					i, nch, ver, err;
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
 					"usb_tll_hs_usb_ch%d_clk", i);
 		tll->ch_clk[i] = clk_get(dev, clkname);
 
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252

Quoted 3 lines
drivers/mfd/omap-usb-tll.c +1 -1
-		if (IS_ERR(tll->ch_clk[i]))
+		if (IS_ERR(tll->ch_clk[i])) {
 			dev_dbg(dev, "can't get clock : %s\n", clkname);  

if you want dev_err() later, then why not here?

Because clk is optional. If it is not there then we should not complain. But if it is there then it needs to be enabled successfully.

I guess you mean *prepared*, the clock is enabled later (with error checking). But your reasoning makes sense.

Quoted 13 lines
Quoted 13 lines
Quoted 10 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 256

Quoted 7 lines
drivers/mfd/omap-usb-tll.c +4 -2
-		else
-			clk_prepare(tll->ch_clk[i]);
+		} else {
+			err = clk_prepare(tll->ch_clk[i]);
+			if (err)
+				dev_dbg(dev, "clock prepare error for: %s\n", clkname);    

dev_err()?

So why do you want a different return handling here? (I doubt there is any clock having a real prepare() involved here)

Quoted 16 lines
Quoted 4 lines

As said in an earlier incarnation of this patch, the real question is whether having partial clocks available is a valid operating scenario. If yes, then the error should be ignored. If no, then bailing out early is a good idea.

In the DT binding, clocks is optional. So if it doesn't exist it is not an error condition.

Quoted 8 lines

clk_prepare() errors are catched by failing clk_enable() later, ch_clk[i] is checked later, too.

Quoted 3 lines

I think we should return the error in this case. (after unpreparing the prepared clocks and clk_put())

and pm_runtime_put_sync(dev)

which can probably be done before dealing with the clocks. It is only needed for the register access.

Regards,
Andreas

author
#5 lore raw
Quoted 78 lines · Andreas Kemnade

Am Tue, 19 Nov 2024 16:16:42 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 37 lines · Andreas Kemnade
Quoted 36 lines

Am Tue, 19 Nov 2024 15:10:23 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 33 lines

Hi,

Quoted 30 lines · Karol Przybylski

clk_prepare() is called in usbtll_omap_probe to fill clk array. Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and dev_dbg statement when it's not successful.

Found in coverity scan, CID 1594680

---
 drivers/mfd/omap-usb-tll.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -1
index 0f7fdb99c809..2e9319ee1b74 100644
@@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
  struct device                           *dev =  &pdev->dev;
  struct usbtll_omap                      *tll;
  void __iomem                            *base;
- int                                     i, nch, ver;
+ int                                     i, nch, ver, err;
 
  dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
                                  "usb_tll_hs_usb_ch%d_clk", i);
          tll->ch_clk[i] = clk_get(dev, clkname);
 
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252

Quoted 3 lines
drivers/mfd/omap-usb-tll.c +1 -1
-         if (IS_ERR(tll->ch_clk[i]))
+         if (IS_ERR(tll->ch_clk[i])) {
                  dev_dbg(dev, "can't get clock : %s\n", clkname);

if you want dev_err() later, then why not here?

Because clk is optional. If it is not there then we should not complain. But if it is there then it needs to be enabled successfully.

I guess you mean *prepared*, the clock is enabled later (with error checking). But your reasoning makes sense.

Quoted 25 lines
Quoted 10 lines
Quoted 10 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 256

Quoted 7 lines
drivers/mfd/omap-usb-tll.c +4 -2
-         else
-                 clk_prepare(tll->ch_clk[i]);
+         } else {
+                 err = clk_prepare(tll->ch_clk[i]);
+                 if (err)
+                         dev_dbg(dev, "clock prepare error for: %s\n", clkname);

dev_err()?

Quoted 7 lines

So why do you want a different return handling here? (I doubt there is any clock having a real prepare() involved here)

As said in an earlier incarnation of this patch, the real question is whether having partial clocks available is a valid operating scenario. If yes, then the error should be ignored. If no, then bailing out early is a good idea.

In the DT binding, clocks is optional. So if it doesn't exist it is not an error condition.

Quoted 4 lines

clk_prepare() errors are catched by failing clk_enable() later, ch_clk[i] is checked later, too.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

I think we should return the error in this case. (after unpreparing the prepared clocks and clk_put())

and pm_runtime_put_sync(dev)

which can probably be done before dealing with the clocks. It is only needed for the register access.

I'm fairly new to this subsystem and I'm trying to understand the conclusion. In the end, we should add dev_err() here after clk_prepare() with appropriate handling?

Quoted 3 lines

Regards,
Andreas

Best regards,
Karol

maintainer
#6 lore raw

Am Thu, 5 Dec 2024 22:54:05 +0100
schrieb Karol P <[email protected]>:

Quoted 82 lines · Andreas Kemnade
Quoted 81 lines

Am Tue, 19 Nov 2024 16:16:42 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 37 lines · Andreas Kemnade
Quoted 36 lines

Am Tue, 19 Nov 2024 15:10:23 +0200
schrieb Roger Quadros <[email protected]>:

Quoted 33 lines

Hi,

Quoted 30 lines · Karol Przybylski

clk_prepare() is called in usbtll_omap_probe to fill clk array. Return code is not checked, leaving possible error condition unhandled.

Added variable to hold return value from clk_prepare() and dev_dbg statement when it's not successful.

Found in coverity scan, CID 1594680

---
 drivers/mfd/omap-usb-tll.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -1
index 0f7fdb99c809..2e9319ee1b74 100644
@@ -202,7 +202,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)
  struct device                           *dev =  &pdev->dev;
  struct usbtll_omap                      *tll;
  void __iomem                            *base;
- int                                     i, nch, ver;
+ int                                     i, nch, ver, err;
 
  dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
@@ -248,10 +248,13 @@ static int usbtll_omap_probe(struct platform_device *pdev)
                                  "usb_tll_hs_usb_ch%d_clk", i);
          tll->ch_clk[i] = clk_get(dev, clkname);
 
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252

Quoted 3 lines
drivers/mfd/omap-usb-tll.c +1 -1
-         if (IS_ERR(tll->ch_clk[i]))
+         if (IS_ERR(tll->ch_clk[i])) {
                  dev_dbg(dev, "can't get clock : %s\n", clkname);  

if you want dev_err() later, then why not here?

Because clk is optional. If it is not there then we should not complain. But if it is there then it needs to be enabled successfully.

I guess you mean *prepared*, the clock is enabled later (with error checking). But your reasoning makes sense.

Quoted 28 lines
Quoted 10 lines
Quoted 10 lines

drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 256

Quoted 7 lines
drivers/mfd/omap-usb-tll.c +4 -2
-         else
-                 clk_prepare(tll->ch_clk[i]);
+         } else {
+                 err = clk_prepare(tll->ch_clk[i]);
+                 if (err)
+                         dev_dbg(dev, "clock prepare error for: %s\n", clkname);  

dev_err()?

Quoted 7 lines

So why do you want a different return handling here? (I doubt there is any clock having a real prepare() involved here)

As said in an earlier incarnation of this patch, the real question is whether having partial clocks available is a valid operating scenario. If yes, then the error should be ignored. If no, then bailing out early is a good idea.

In the DT binding, clocks is optional. So if it doesn't exist it is not an error condition.

Quoted 7 lines

clk_prepare() errors are catched by failing clk_enable() later, ch_clk[i] is checked later, too.

Quoted 3 lines

I think we should return the error in this case. (after unpreparing the prepared clocks and clk_put())

Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

and pm_runtime_put_sync(dev)

which can probably be done before dealing with the clocks. It is only needed for the register access.

I'm fairly new to this subsystem and I'm trying to understand the conclusion. In the end, we should add dev_err() here after clk_prepare() with appropriate handling?

we must make sure pm_runtime_put/get are paired and _put is called in any case. Looking around a bit:
I think a good solution would be along this lines:
https://lore.kernel.org/linux-omap/[email protected]/T/#u

using devm_clk_get_prepared() things can be simplified.

Regards,
Andreas