Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3082529pxp; Tue, 8 Mar 2022 07:25:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxP19qABHugkBZDD9OcHUjIhredx8moKq/li3lQmbD+xaVxO63NTrdj2uxI0PPxac6oP06 X-Received: by 2002:a17:902:f145:b0:151:a441:433a with SMTP id d5-20020a170902f14500b00151a441433amr18203802plb.44.1646753124094; Tue, 08 Mar 2022 07:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646753124; cv=none; d=google.com; s=arc-20160816; b=EUPR1kKxqqNrrbwBDAmCn8RC3C7p6IKqTyhFnLDZubEWkU+e7zloZZmasf2mB3rzNd e4ZjaQTCSzJpI84XkrQvbm1jeb9TvJra/58uhWBs6VvBycXu39Mgz4d0Ka472cNLZ9h9 Bl+k7QplZfivmbnMOwJ+GmORHEM1WCRPl0h4TOLXSbf8MbXoyOzROqv9D8mPIKS7/Xg/ LYTB/rYK+Vjz0HQBNhQUvwOmp9cjNuY2wPNlZOIoI+91H+pPEC77cz/jL4/PESAu37Bd z6oSlHjR8MpLFEKlI/xdlGLNuu6Zaglb5vA1yHS5krXrQmDwM3w8asvRQCBz6UnFH1JY YjkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9MOCu6wO9j/R74ihoqw8FpiBdSecWppUH+tZYpCs6jo=; b=l0Vg8PxbHoMKJF32nS6edDCsHI+aWEcYNblEBKsdDABkSyUZxevtzpmrkXaw+K79e0 razeYpHsv6gnPZRuL/LLekEabNh1qQaX8PUaKp5suWHIkvoMwX5SeFbY+OyNKX7Bwxeb YuTLNIzw4upH2BeMT3DZC1baJnD3n5Gxo5ESpr9wF9msTUDR7NoC6+qume3PggdQ9Vrf K8Er2DDLGXmZqXKT7Wpf587kaP5M7kf9wbOAK5OFdeDrJHMWCrYq+aGOqZO/YC+f79TE s7VG7wOoYXEnLJYbfTPJacWCLSzbIVTIAu46h0BGVuQd/+iLdDkLX9QLMAKn0JoRqNlV FylA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MIh5mULQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bj7-20020a056a02018700b00378bbeba906si14578818pgb.191.2022.03.08.07.25.06; Tue, 08 Mar 2022 07:25:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MIh5mULQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238728AbiCHH3t (ORCPT + 99 others); Tue, 8 Mar 2022 02:29:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230488AbiCHH3s (ORCPT ); Tue, 8 Mar 2022 02:29:48 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C563631DE2; Mon, 7 Mar 2022 23:28:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646724530; x=1678260530; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=eSgr7kllToWa09Si12r9LxFjIEKFGm4w4wNIAFIoQ1U=; b=MIh5mULQaNKbI35JKWSNUD3fcNPG6sarTW9u2OplzWa4U3/GgHFKlnpD X9EmdTF84jzyyBiMXVyYLxpA+d4CJjmem/1qvfVLpsyB8mA5klL+mbgm0 776exdvZ3NPOqb9y7T90wNgYjsFzzTOED9Aq7eNjP3XmCNXwrkEMeKDpF QykbEHEC/GDuY1/GAnWmxFWRFcYtWtdiw5eh3nXNBl3VLpXa76WexTcf7 6mRIAmO5EfhrHuS+ZVa2vI5REnfvPkG+g1B7Si30i7jWQdujD7mcE3WKD cFPneFGz/FmFS0+5Ox87CftoCUCv2KkvZSXX3c0RPdYQofLn2xvNKcytk w==; X-IronPort-AV: E=McAfee;i="6200,9189,10279"; a="252188011" X-IronPort-AV: E=Sophos;i="5.90,163,1643702400"; d="scan'208";a="252188011" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 23:28:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,163,1643702400"; d="scan'208";a="687832143" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmsmga001.fm.intel.com with SMTP; 07 Mar 2022 23:28:47 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Tue, 08 Mar 2022 09:28:47 +0200 Date: Tue, 8 Mar 2022 09:28:47 +0200 From: Heikki Krogerus To: Yeqi Fu Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, lyz_cs@pku.edu.cn, Yeqi Fu Subject: Re: [PATCH 2/2] usb: typec: fix memory leak Message-ID: References: <20220308065617.90401-1-fufuyqqqqqq@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220308065617.90401-1-fufuyqqqqqq@gmail.com> X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 07, 2022 at 10:56:17PM -0800, Yeqi Fu wrote: > From: Yeqi Fu > > Resource release is needed on the error handling branch > to prevent memory leak. Fix this by adding kfree to the > error handling branch. > > Signed-off-by: Yeqi Fu NAK. That resources are released in the release callback - typec_release() in this case. > --- > drivers/usb/typec/class.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index ee0e520707dd..e210109c696d 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -2099,6 +2099,7 @@ struct typec_port *typec_register_port(struct device *parent, > port->cap = kmemdup(cap, sizeof(*cap), GFP_KERNEL); > if (!port->cap) { > put_device(&port->dev); > + kfree(port); > return ERR_PTR(-ENOMEM); > } > > @@ -2106,6 +2107,7 @@ struct typec_port *typec_register_port(struct device *parent, > if (IS_ERR(port->sw)) { > ret = PTR_ERR(port->sw); > put_device(&port->dev); > + kfree(port); > return ERR_PTR(ret); > } > > @@ -2113,6 +2115,7 @@ struct typec_port *typec_register_port(struct device *parent, > if (IS_ERR(port->mux)) { > ret = PTR_ERR(port->mux); > put_device(&port->dev); > + kfree(port); > return ERR_PTR(ret); > } > > @@ -2120,6 +2123,7 @@ struct typec_port *typec_register_port(struct device *parent, > if (ret) { > dev_err(parent, "failed to register port (%d)\n", ret); > put_device(&port->dev); > + kfree(port); > return ERR_PTR(ret); > } thanks, -- heikki