mfd: omap-usb-tll: handle clk_prepare return code in usbtll_omap_probe
Subsystems (2)
PATCH 1/1 mfd: omap-usb-tll: handle clk_prepare return code in usbtll_omap_probe
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 return statement when it's not successful.
Found in coverity scan, CID 1594680
--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mfd/omap-usb-tll.c +6 -2
@@ -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" );
@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);else -clk_prepare (tll->ch_clk[i]); + err =clk_prepare (tll->ch_clk[i]); +if (err) { +dev_err (dev,"Unable to prepare clock\n" ); +return err; + } }pm_runtime_put_sync (dev);
Signature · 1 line
2.34.1
Quoted 27 lines · Karol Przybylski
clk_prepare()is called inusbtll_omap_probeto fill clk array. Return code is not checked, leaving possible error condition unhandled.Added variable to hold return value from
clk_prepare()and return statement when it's not successful.Found in coverity scan, CID 1594680
Signed-off-by Karol Przybylski <[email protected]>--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +1
-1@@ -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" );
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 254
Quoted 4 lines
drivers/mfd/omap-usb-tll.c +0
-1@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);else -clk_prepare (tll->ch_clk[i]);
Braces for the conditional don't looks right.
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 257
Quoted 4 lines
drivers/mfd/omap-usb-tll.c +4
-0+ err =clk_prepare (tll->ch_clk[i]); +if (err) { +dev_err (dev,"Unable to prepare clock\n" ); +return err;
Did you check to see if callers handle this new error return in this path?
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 258
Quoted 1 line
drivers/mfd/omap-usb-tll.c +1
-0+ }
Same here
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 260
Quoted 2 lines
drivers/mfd/omap-usb-tll.c +0
-0}
Same here
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 1 line
drivers/mfd/omap-usb-tll.c +0
-0pm_runtime_put_sync (dev);
thanks,
-- Shuah
Andreas Kemnade
maintainerAm Wed, 6 Nov 2024 23:33:24 +0100
schrieb Karol Przybylski <[email protected]>:
Quoted 27 lines
clk_prepare()is called inusbtll_omap_probeto fill clk array. Return code is not checked, leaving possible error condition unhandled.Added variable to hold return value from
clk_prepare()and return statement when it's not successful.Found in coverity scan, CID 1594680
Signed-off-by Karol Przybylski <[email protected]>--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +1
-1@@ -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" );
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252
Quoted 2 lines
drivers/mfd/omap-usb-tll.c +0
-0@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);
if you add more intensive error checking, then why is this error ignored and not returned?
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 255
Quoted 4 lines
drivers/mfd/omap-usb-tll.c +2
-1else -clk_prepare (tll->ch_clk[i]); + err =clk_prepare (tll->ch_clk[i]); +if (err) {
unnatural braces, if (err) is not in the else branch ?!
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 6 lines
drivers/mfd/omap-usb-tll.c +3
-0+dev_err (dev,"Unable to prepare clock\n" ); +return err; + } }pm_runtime_put_sync (dev);
and this one is not called if you return early.
Regards,
Andreas
Quoted 28 lines · Andreas Kemnade
Am Wed, 6 Nov 2024 23:33:24 +0100
schrieb Karol Przybylski <[email protected]>:Quoted 24 lines
clk_prepare()is called inusbtll_omap_probeto fill clk array. Return code is not checked, leaving possible error condition unhandled.Added variable to hold return value from
clk_prepare()and return statement when it's not successful.Found in coverity scan, CID 1594680
Signed-off-by Karol Przybylski <[email protected]>--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +1
-1@@ -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;
Quoted 8 lines
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +0
-0dev_dbg (dev,"starting TI HSUSB TLL Controller\n" );@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);if you add more intensive error checking, then why is this error ignored and not returned?
Thank you for the feedback. It does seem that elevated error checking is not the way
to go in this case. Do you think it would be good to add a similar statement instead of
my initial changes? It would look something like this:
+ else {
err = clk_prepare(tll->ch_clk[i]);+ if (err)
+ dev_dbg(dev, "clock prepare error for:
%s\n", clkname);
+ }
Quoted 16 lines
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 255
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +2
-1else -clk_prepare (tll->ch_clk[i]); + err =clk_prepare (tll->ch_clk[i]); +if (err) {unnatural braces, if (err) is not in the else branch ?!
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 6 lines
drivers/mfd/omap-usb-tll.c +3
-0+dev_err (dev,"Unable to prepare clock\n" ); +return err; + } }pm_runtime_put_sync (dev);and this one is not called if you return early.
Regards,
Andreas
Andreas Kemnade
maintainerAm Thu, 7 Nov 2024 12:12:52 +0100
schrieb Karol P <[email protected]>:
Quoted 38 lines · Andreas Kemnade
Quoted 28 lines
Am Wed, 6 Nov 2024 23:33:24 +0100
schrieb Karol Przybylski <[email protected]>:Quoted 24 lines
clk_prepare()is called inusbtll_omap_probeto fill clk array. Return code is not checked, leaving possible error condition unhandled.Added variable to hold return value from
clk_prepare()and return statement when it's not successful.Found in coverity scan, CID 1594680
Signed-off-by Karol Przybylski <[email protected]>--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +1
-1@@ -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;Quoted 8 lines
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +0
-0dev_dbg (dev,"starting TI HSUSB TLL Controller\n" );@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);if you add more intensive error checking, then why is this error ignored and not returned?
Quoted 3 lines
Thank you for the feedback. It does seem that elevated error checking is not the way
to go in this case.
As far as I can see everything checks ch_clk[i] for validity before usage. Also clk_enable() called later is checked which would catch clk_prepare() failures, if there were even possible here.
So the only question which I am not 100% sure about is whether having ch_clk sparsly populated is normal operation. If that is the case, then more error checking is not useful. If not, then it might let us better sleep. As said as far as I can see errors are catched later.
@Roger: what is your opintion towards this?
BTW: If you do this kind of work, you could also use W=1 or CONFIG_WERROR during compiling to catch easy things. At least I see new compile warnings with your patch.
Regards,
Andreas
Roger Quadros
maintainerHi,
Quoted 49 lines · Andreas Kemnade
Am Thu, 7 Nov 2024 12:12:52 +0100
schrieb Karol P <[email protected]>:Quoted 38 lines · Andreas Kemnade
Quoted 28 lines
Am Wed, 6 Nov 2024 23:33:24 +0100
schrieb Karol Przybylski <[email protected]>:Quoted 24 lines
clk_prepare()is called inusbtll_omap_probeto fill clk array. Return code is not checked, leaving possible error condition unhandled.Added variable to hold return value from
clk_prepare()and return statement when it's not successful.Found in coverity scan, CID 1594680
Signed-off-by Karol Przybylski <[email protected]>--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +1
-1@@ -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;Quoted 8 lines
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +0
-0dev_dbg (dev,"starting TI HSUSB TLL Controller\n" );@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);if you add more intensive error checking, then why is this error ignored and not returned?
Quoted 3 lines
Thank you for the feedback. It does seem that elevated error checking is not the way
to go in this case.As far as I can see everything checks ch_clk[i] for validity before usage. Also
clk_enable()called later is checked which would catchclk_prepare()failures, if there were even possible here.
Quoted 6 lines
So the only question which I am not 100% sure about is whether having
ch_clksparsly populated is normal operation. If that is the case, then more error checking is not useful. If not, then it might let us better sleep. As said as far as I can see errors are catched later.@Roger: what is your opintion towards this?
I don't see usb_tll_hs_usb_ch?_clk in any of the OMAP device trees. Could it be that they are optional?
If so then we could convert it to devm_clk_get_optional()?
While at that, maybe the device tree binding could also be updated and converted to yaml.
Quoted 7 lines
BTW: If you do this kind of work, you could also use W=1 or
CONFIG_WERRORduring compiling to catch easy things. At least I see new compile warnings with your patch.Regards,
Andreas
Signature · 2 lines
cheers, -roger
Andreas Kemnade
maintainerAm Mon, 11 Nov 2024 16:41:47 +0200
schrieb Roger Quadros <[email protected]>:
Quoted 57 lines
Hi,
Quoted 54 lines · Andreas Kemnade
Am Thu, 7 Nov 2024 12:12:52 +0100
schrieb Karol P <[email protected]>:Quoted 38 lines · Andreas Kemnade
Quoted 28 lines
Am Wed, 6 Nov 2024 23:33:24 +0100
schrieb Karol Przybylski <[email protected]>:Quoted 24 lines
clk_prepare()is called inusbtll_omap_probeto fill clk array. Return code is not checked, leaving possible error condition unhandled.Added variable to hold return value from
clk_prepare()and return statement when it's not successful.Found in coverity scan, CID 1594680
Signed-off-by Karol Przybylski <[email protected]>--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +1
-1@@ -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;Quoted 8 lines
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +0
-0dev_dbg (dev,"starting TI HSUSB TLL Controller\n" );@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);if you add more intensive error checking, then why is this error ignored and not returned?
Quoted 3 lines
Thank you for the feedback. It does seem that elevated error checking is not the way
to go in this case.As far as I can see everything checks ch_clk[i] for validity before usage. Also
clk_enable()called later is checked which would catchclk_prepare()failures, if there were even possible here.So the only question which I am not 100% sure about is whether having
ch_clksparsly populated is normal operation. If that is the case, then more error checking is not useful. If not, then it might let us better sleep. As said as far as I can see errors are catched later.
Quoted 6 lines
Quoted 1 line
@Roger: what is your opintion towards this?
I don't see usb_tll_hs_usb_ch?_clk in any of the OMAP device trees. Could it be that they are optional?
If so then we could convert it todevm_clk_get_optional()?
They live in drivers/clk/ti/clk-[54]4xx.c
But nothing about omap3. So apparently we can have valid use cases where these clocks are not available. So no real need more anything more than dev_dbg output here.
Regards,
Andreas
Quoted 67 lines · Andreas Kemnade
Am Mon, 11 Nov 2024 16:41:47 +0200
schrieb Roger Quadros <[email protected]>:Quoted 57 lines
Hi,
Quoted 54 lines · Andreas Kemnade
Am Thu, 7 Nov 2024 12:12:52 +0100
schrieb Karol P <[email protected]>:Quoted 38 lines · Andreas Kemnade
Quoted 28 lines
Am Wed, 6 Nov 2024 23:33:24 +0100
schrieb Karol Przybylski <[email protected]>:Quoted 24 lines
clk_prepare()is called inusbtll_omap_probeto fill clk array. Return code is not checked, leaving possible error condition unhandled.Added variable to hold return value from
clk_prepare()and return statement when it's not successful.Found in coverity scan, CID 1594680
Signed-off-by Karol Przybylski <[email protected]>--- drivers/mfd/omap-usb-tll.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +1
-1@@ -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;Quoted 8 lines
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 252
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +0
-0dev_dbg (dev,"starting TI HSUSB TLL Controller\n" );@@ -251,7 +251,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)if (IS_ERR (tll->ch_clk[i]))dev_dbg (dev,"can't get clock : %s\n" , clkname);if you add more intensive error checking, then why is this error ignored and not returned?
Quoted 3 lines
Thank you for the feedback. It does seem that elevated error checking is not the way
to go in this case.As far as I can see everything checks ch_clk[i] for validity before usage. Also
clk_enable()called later is checked which would catchclk_prepare()failures, if there were even possible here.So the only question which I am not 100% sure about is whether having
ch_clksparsly populated is normal operation. If that is the case, then more error checking is not useful. If not, then it might let us better sleep. As said as far as I can see errors are catched later.Quoted 6 lines
Quoted 1 line
@Roger: what is your opintion towards this?
I don't see usb_tll_hs_usb_ch?_clk in any of the OMAP device trees. Could it be that they are optional?
If so then we could convert it todevm_clk_get_optional()?
Quoted 7 lines
They live in drivers/clk/ti/clk-[54]4xx.c
But nothing about omap3. So apparently we can have valid use cases where these clocks are not available. So no real need more anything more thandev_dbgoutput here.Regards,
Andreas
Thanks, I will send in a new patch then. I can also take a look at updating device tree binding.
Best regards,
Karol