From patchwork Thu May 12 11:15:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 12847591 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 E43C3C433EF for ; Thu, 12 May 2022 11:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353278AbiELLUZ (ORCPT ); Thu, 12 May 2022 07:20:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353205AbiELLS6 (ORCPT ); Thu, 12 May 2022 07:18:58 -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 D2A2F64BD0; Thu, 12 May 2022 04:17:17 -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 621ED3C04C0; Thu, 12 May 2022 13:17:15 +0200 (CEST) Received: from localhost.localdomain (10.72.94.15) 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 13:17:14 +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] usb: hub: Simplify error and success path in port_over_current_notify Date: Thu, 12 May 2022 13:15:27 +0200 Message-ID: <1652354127-3499-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.15] 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 --- 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); }