* [PATCH] usb: hub: Simplify error and success path in port_over_current_notify
@ 2022-05-12 11:15 Eugeniu Rosca
2022-05-12 11:38 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Eugeniu Rosca @ 2022-05-12 11:15 UTC (permalink / raw)
To: Greg Kroah-Hartman, Alan Stern, Mathias Nyman, Kai-Heng Feng,
Rajat Jain, Andrew Lunn, Chris Chiu, Marek Szyprowski, linux-usb,
linux-kernel
Cc: Naveen kumar Sunkari, Bhuvanesh Surachari, Eugeniu Rosca, Eugeniu Rosca
From: Bhuvanesh Surachari <Bhuvanesh_Surachari@mentor.com>
kasprintf() returns NULL or valid pointer. Since kfree() can handle
NULL pointer condition, simplify error and success paths in function
port_over_current_notify() by removing multiple error path labels.
Signed-off-by: Bhuvanesh Surachari <Bhuvanesh_Surachari@mentor.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
drivers/usb/core/hub.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 1460857026e0..9ab8abf14790 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -5511,7 +5511,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
/* Handle notifying userspace about hub over-current events */
static void port_over_current_notify(struct usb_port *port_dev)
{
- char *envp[3];
+ char *envp[3] = { NULL, NULL, NULL };
struct device *hub_dev;
char *port_dev_path;
@@ -5533,15 +5533,13 @@ static void port_over_current_notify(struct usb_port *port_dev)
envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
port_dev->over_current_count);
if (!envp[1])
- goto exit;
+ goto exit_path;
- envp[2] = NULL;
kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp);
+exit_path:
kfree(envp[1]);
-exit:
kfree(envp[0]);
-exit_path:
kfree(port_dev_path);
}
--
2.36.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: hub: Simplify error and success path in port_over_current_notify
2022-05-12 11:15 [PATCH] usb: hub: Simplify error and success path in port_over_current_notify Eugeniu Rosca
@ 2022-05-12 11:38 ` Greg Kroah-Hartman
2022-05-12 15:44 ` Eugeniu Rosca
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-05-12 11:38 UTC (permalink / raw)
To: Eugeniu Rosca
Cc: Alan Stern, Mathias Nyman, Kai-Heng Feng, Rajat Jain,
Andrew Lunn, Chris Chiu, Marek Szyprowski, linux-usb,
linux-kernel, Naveen kumar Sunkari, Bhuvanesh Surachari,
Eugeniu Rosca
On Thu, May 12, 2022 at 01:15:27PM +0200, Eugeniu Rosca wrote:
> From: Bhuvanesh Surachari <Bhuvanesh_Surachari@mentor.com>
>
> kasprintf() returns NULL or valid pointer. Since kfree() can handle
> NULL pointer condition, simplify error and success paths in function
> port_over_current_notify() by removing multiple error path labels.
>
> Signed-off-by: Bhuvanesh Surachari <Bhuvanesh_Surachari@mentor.com>
> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> ---
> drivers/usb/core/hub.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index 1460857026e0..9ab8abf14790 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -5511,7 +5511,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
> /* Handle notifying userspace about hub over-current events */
> static void port_over_current_notify(struct usb_port *port_dev)
> {
> - char *envp[3];
> + char *envp[3] = { NULL, NULL, NULL };
> struct device *hub_dev;
> char *port_dev_path;
>
> @@ -5533,15 +5533,13 @@ static void port_over_current_notify(struct usb_port *port_dev)
> envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
> port_dev->over_current_count);
> if (!envp[1])
> - goto exit;
> + goto exit_path;
No need to rename this, right?
>
> - envp[2] = NULL;
> kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp);
>
> +exit_path:
> kfree(envp[1]);
> -exit:
Move this up one line?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: hub: Simplify error and success path in port_over_current_notify
2022-05-12 11:38 ` Greg Kroah-Hartman
@ 2022-05-12 15:44 ` Eugeniu Rosca
0 siblings, 0 replies; 3+ messages in thread
From: Eugeniu Rosca @ 2022-05-12 15:44 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Eugeniu Rosca, Alan Stern, Mathias Nyman, Kai-Heng Feng,
Rajat Jain, Andrew Lunn, Chris Chiu, Marek Szyprowski, linux-usb,
linux-kernel, Naveen kumar Sunkari, Bhuvanesh Surachari,
Eugeniu Rosca
Dear Greg,
On Do, Mai 12, 2022 at 01:38:36 +0200, Greg Kroah-Hartman wrote:
> On Thu, May 12, 2022 at 01:15:27PM +0200, Eugeniu Rosca wrote:
> > From: Bhuvanesh Surachari <Bhuvanesh_Surachari@mentor.com>
[..]
> > if (!envp[1])
> > - goto exit;
> > + goto exit_path;
>
> No need to rename this, right?
>
> >
> > - envp[2] = NULL;
> > kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp);
> >
> > +exit_path:
> > kfree(envp[1]);
> > -exit:
>
> Move this up one line?
Thank you for your comments. Much appreciated.
Please, find the updated version at:
https://lore.kernel.org/linux-usb/1652369834-4480-1-git-send-email-erosca@de.adit-jv.com
Best regards,
Eugeniu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-05-12 15:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 11:15 [PATCH] usb: hub: Simplify error and success path in port_over_current_notify Eugeniu Rosca
2022-05-12 11:38 ` Greg Kroah-Hartman
2022-05-12 15:44 ` Eugeniu Rosca
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).