From patchwork Thu May 12 15:37:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 12847839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBE28C433F5 for ; Thu, 12 May 2022 15:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356021AbiELPhw (ORCPT ); Thu, 12 May 2022 11:37:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356023AbiELPhu (ORCPT ); Thu, 12 May 2022 11:37:50 -0400 Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F9325B07C; Thu, 12 May 2022 08:37:49 -0700 (PDT) Received: from hi2exch02.adit-jv.com (hi2exch02.adit-jv.com [10.72.92.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id BA68B3C04C0; Thu, 12 May 2022 17:37:47 +0200 (CEST) Received: from localhost.localdomain (10.72.94.11) by hi2exch02.adit-jv.com (10.72.92.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Thu, 12 May 2022 17:37:47 +0200 From: Eugeniu Rosca To: Greg Kroah-Hartman , Alan Stern , Mathias Nyman , Kai-Heng Feng , Rajat Jain , Andrew Lunn , Chris Chiu , Marek Szyprowski , , CC: Naveen kumar Sunkari , Bhuvanesh Surachari , Eugeniu Rosca , Eugeniu Rosca Subject: [PATCH v2] usb: hub: Simplify error and success path in port_over_current_notify Date: Thu, 12 May 2022 17:37:14 +0200 Message-ID: <1652369834-4480-1-git-send-email-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.94.11] X-ClientProxiedBy: hi2exch02.adit-jv.com (10.72.92.28) To hi2exch02.adit-jv.com (10.72.92.28) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Bhuvanesh Surachari 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 Signed-off-by: Eugeniu Rosca --- 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); }