lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <1652369834-4480-1-git-send-email-erosca@de.adit-jv.com>
Date:   Thu, 12 May 2022 17:37:14 +0200
From:   Eugeniu Rosca <erosca@...adit-jv.com>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Alan Stern <stern@...land.harvard.edu>,
        Mathias Nyman <mathias.nyman@...ux.intel.com>,
        Kai-Heng Feng <kai.heng.feng@...onical.com>,
        Rajat Jain <rajatja@...gle.com>, Andrew Lunn <andrew@...n.ch>,
        Chris Chiu <chris.chiu@...onical.com>,
        Marek Szyprowski <m.szyprowski@...sung.com>,
        <linux-usb@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     Naveen kumar Sunkari <naveenkumar.sunkari@...bosch.com>,
        Bhuvanesh Surachari <Bhuvanesh_Surachari@...tor.com>,
        Eugeniu Rosca <erosca@...adit-jv.com>,
        Eugeniu Rosca <rosca.eugeniu@...il.com>
Subject: [PATCH v2] usb: hub: Simplify error and success path in port_over_current_notify

From: Bhuvanesh Surachari <Bhuvanesh_Surachari@...tor.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@...tor.com>
Signed-off-by: Eugeniu Rosca <erosca@...adit-jv.com>
---

v2:
 - [Greg Kroah-Hartman] Drop 'exit_path' and keep 'exit' instead

v1: https://lore.kernel.org/linux-usb/1652354127-3499-1-git-send-email-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..4a06892f9774 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;
 
@@ -5528,20 +5528,18 @@ static void port_over_current_notify(struct usb_port *port_dev)
 
 	envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
 	if (!envp[0])
-		goto exit_path;
+		goto exit;
 
 	envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
 			port_dev->over_current_count);
 	if (!envp[1])
 		goto exit;
 
-	envp[2] = NULL;
 	kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp);
 
-	kfree(envp[1]);
 exit:
+	kfree(envp[1]);
 	kfree(envp[0]);
-exit_path:
 	kfree(port_dev_path);
 }
 
-- 
2.36.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ