* [PATCH] usb: misc: usb3503: call clk_disable_unprepare in the error handling
@ 2022-09-03 7:15 Dongliang Mu
2022-09-07 14:25 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Dongliang Mu @ 2022-09-03 7:15 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Dongliang Mu, linux-usb, linux-kernel
From: Dongliang Mu <mudongliangabcd@gmail.com>
Smatch reports the following warning:
vers/usb/misc/usb3503.c:267 usb3503_probe() warn: 'hub->clk'
from clk_prepare_enable() not released on lines: 240,246,252
Fix this by adding a flag to indicate if hub->clk is prepared or not and
invoke clk_disable_unprepare in the error handling.
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
drivers/usb/misc/usb3503.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
index 330f494cd158..add47dd964b2 100644
--- a/drivers/usb/misc/usb3503.c
+++ b/drivers/usb/misc/usb3503.c
@@ -160,6 +160,7 @@ static int usb3503_probe(struct usb3503 *hub)
struct usb3503_platform_data *pdata = dev_get_platdata(dev);
struct device_node *np = dev->of_node;
int err;
+ int is_clk_enable = 0;
u32 mode = USB3503_MODE_HUB;
const u32 *property;
enum gpiod_flags flags;
@@ -217,6 +218,8 @@ static int usb3503_probe(struct usb3503 *hub)
return err;
}
+ // set a flag for successful clk_prepare_enable
+ is_clk_enable = 1;
property = of_get_property(np, "disabled-ports", &len);
if (property && (len / sizeof(u32)) > 0) {
int i;
@@ -236,20 +239,29 @@ static int usb3503_probe(struct usb3503 *hub)
else
flags = GPIOD_OUT_HIGH;
hub->intn = devm_gpiod_get_optional(dev, "intn", flags);
- if (IS_ERR(hub->intn))
+ if (IS_ERR(hub->intn)) {
+ if (is_clk_enable)
+ clk_disable_unprepare(hub->clk);
return PTR_ERR(hub->intn);
+ }
if (hub->intn)
gpiod_set_consumer_name(hub->intn, "usb3503 intn");
hub->connect = devm_gpiod_get_optional(dev, "connect", GPIOD_OUT_LOW);
- if (IS_ERR(hub->connect))
+ if (IS_ERR(hub->connect)) {
+ if (is_clk_enable)
+ clk_disable_unprepare(hub->clk);
return PTR_ERR(hub->connect);
+ }
if (hub->connect)
gpiod_set_consumer_name(hub->connect, "usb3503 connect");
hub->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
- if (IS_ERR(hub->reset))
+ if (IS_ERR(hub->reset)) {
+ if (is_clk_enable)
+ clk_disable_unprepare(hub->clk);
return PTR_ERR(hub->reset);
+ }
if (hub->reset) {
/* Datasheet defines a hardware reset to be at least 100us */
usleep_range(100, 10000);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: misc: usb3503: call clk_disable_unprepare in the error handling
2022-09-03 7:15 [PATCH] usb: misc: usb3503: call clk_disable_unprepare in the error handling Dongliang Mu
@ 2022-09-07 14:25 ` Greg Kroah-Hartman
2022-09-08 6:01 ` Dongliang Mu
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-09-07 14:25 UTC (permalink / raw)
To: Dongliang Mu; +Cc: Dongliang Mu, linux-usb, linux-kernel
On Sat, Sep 03, 2022 at 03:15:40PM +0800, Dongliang Mu wrote:
> From: Dongliang Mu <mudongliangabcd@gmail.com>
>
> Smatch reports the following warning:
>
> vers/usb/misc/usb3503.c:267 usb3503_probe() warn: 'hub->clk'
> from clk_prepare_enable() not released on lines: 240,246,252
>
> Fix this by adding a flag to indicate if hub->clk is prepared or not and
> invoke clk_disable_unprepare in the error handling.
>
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> ---
> drivers/usb/misc/usb3503.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
> index 330f494cd158..add47dd964b2 100644
> --- a/drivers/usb/misc/usb3503.c
> +++ b/drivers/usb/misc/usb3503.c
> @@ -160,6 +160,7 @@ static int usb3503_probe(struct usb3503 *hub)
> struct usb3503_platform_data *pdata = dev_get_platdata(dev);
> struct device_node *np = dev->of_node;
> int err;
> + int is_clk_enable = 0;
bool?
> u32 mode = USB3503_MODE_HUB;
> const u32 *property;
> enum gpiod_flags flags;
> @@ -217,6 +218,8 @@ static int usb3503_probe(struct usb3503 *hub)
> return err;
> }
>
> + // set a flag for successful clk_prepare_enable
Comment isn't needed.
> + is_clk_enable = 1;
> property = of_get_property(np, "disabled-ports", &len);
> if (property && (len / sizeof(u32)) > 0) {
> int i;
> @@ -236,20 +239,29 @@ static int usb3503_probe(struct usb3503 *hub)
> else
> flags = GPIOD_OUT_HIGH;
> hub->intn = devm_gpiod_get_optional(dev, "intn", flags);
> - if (IS_ERR(hub->intn))
> + if (IS_ERR(hub->intn)) {
> + if (is_clk_enable)
> + clk_disable_unprepare(hub->clk);
> return PTR_ERR(hub->intn);
This is getting messy, any way to make a common error handler at the
bottom of the function instead? That's the common kernel coding style
for this type of thing.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: misc: usb3503: call clk_disable_unprepare in the error handling
2022-09-07 14:25 ` Greg Kroah-Hartman
@ 2022-09-08 6:01 ` Dongliang Mu
0 siblings, 0 replies; 3+ messages in thread
From: Dongliang Mu @ 2022-09-08 6:01 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Dongliang Mu, USB, linux-kernel
On Wed, Sep 7, 2022 at 10:25 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Sat, Sep 03, 2022 at 03:15:40PM +0800, Dongliang Mu wrote:
> > From: Dongliang Mu <mudongliangabcd@gmail.com>
> >
> > Smatch reports the following warning:
> >
> > vers/usb/misc/usb3503.c:267 usb3503_probe() warn: 'hub->clk'
> > from clk_prepare_enable() not released on lines: 240,246,252
> >
> > Fix this by adding a flag to indicate if hub->clk is prepared or not and
> > invoke clk_disable_unprepare in the error handling.
> >
> > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> > ---
> > drivers/usb/misc/usb3503.c | 18 +++++++++++++++---
> > 1 file changed, 15 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
> > index 330f494cd158..add47dd964b2 100644
> > --- a/drivers/usb/misc/usb3503.c
> > +++ b/drivers/usb/misc/usb3503.c
> > @@ -160,6 +160,7 @@ static int usb3503_probe(struct usb3503 *hub)
> > struct usb3503_platform_data *pdata = dev_get_platdata(dev);
> > struct device_node *np = dev->of_node;
> > int err;
> > + int is_clk_enable = 0;
>
> bool?
>
> > u32 mode = USB3503_MODE_HUB;
> > const u32 *property;
> > enum gpiod_flags flags;
> > @@ -217,6 +218,8 @@ static int usb3503_probe(struct usb3503 *hub)
> > return err;
> > }
> >
> > + // set a flag for successful clk_prepare_enable
>
> Comment isn't needed.
>
> > + is_clk_enable = 1;
> > property = of_get_property(np, "disabled-ports", &len);
> > if (property && (len / sizeof(u32)) > 0) {
> > int i;
> > @@ -236,20 +239,29 @@ static int usb3503_probe(struct usb3503 *hub)
> > else
> > flags = GPIOD_OUT_HIGH;
> > hub->intn = devm_gpiod_get_optional(dev, "intn", flags);
> > - if (IS_ERR(hub->intn))
> > + if (IS_ERR(hub->intn)) {
> > + if (is_clk_enable)
> > + clk_disable_unprepare(hub->clk);
> > return PTR_ERR(hub->intn);
>
> This is getting messy, any way to make a common error handler at the
> bottom of the function instead? That's the common kernel coding style
> for this type of thing.
I have addressed all the issues mentioned above:
1. change is_clk_enable to is_clk_enabled, and change its type to bool.
2. remove the comment and move the error handling code to the end of
probe function.
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-08 6:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-03 7:15 [PATCH] usb: misc: usb3503: call clk_disable_unprepare in the error handling Dongliang Mu
2022-09-07 14:25 ` Greg Kroah-Hartman
2022-09-08 6:01 ` Dongliang Mu
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).