Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3525851pxp; Tue, 8 Mar 2022 16:38:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCdPjxQWPVYBa+LPeTj19kg9sW0z4OZ5P/fhXyroWv2P2ngLsD8/5MV7JQaJaKZ8YjB/dD X-Received: by 2002:a05:6a00:194c:b0:4f7:29e7:f3e9 with SMTP id s12-20020a056a00194c00b004f729e7f3e9mr6928012pfk.74.1646786309539; Tue, 08 Mar 2022 16:38:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646786309; cv=none; d=google.com; s=arc-20160816; b=Fggae3UykxjGf1Trv7ZWjC/w4MqjJ23fRto8AoFgbiUWexL3RdX/ERDgatYqjzcTMh UzGuSJOH5MxiO6Fffvw+eYJjLkP6QC9aPbST5i5sl4pXQk1QDmfU/7CR1zVR8PB3HQdf Rls1fN1kbRRNZDWwumIkD75wkU9fZ+flP5IwfpaBax0x4hvAP0Gi2MyEu2kuhTxSykvp PiqCbNfp5UdU7DPYjwpjT20r6oMNkmTD6Ai9GbId/gvmtKGaXaqlkUYGHxqcpAWUs0c4 m4ZBjkTtDzTnEcTRo1+Oy16eFeyVlQyYesyKsStwEuTvUA1S2n0YWmWot0JYnjE7VWiu l0Hg== 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=sl7++UMhgRyF3hvAJLQK3CGORSDMpl2yCP0NOaLJN+c=; b=K3TL6bktA2RmLsy11LD/hGugIVeH0AwJH3QQCK7C2G5GIdrjjWYaBjqt0snsWM0wk8 XJzT6ugEFy6e8ZTG6IysFMAgIYCLYVDrVjjQgYLcgVXCD8POCWzpSpKi5XYTxZnDFK+H NO1LLJeU5yL72xNqXeEgWTiusHrOofFaLdt3NxEeU4MuC0TP/4mNxvnrIXeOQH/dv5sh InpJRdGDBNLttl8MDh7eKjfJPIDBVGtEX7yyDs2u/6JJcUHDquo+bs9EJRFMgDMvQOr1 zmMMU97tMBo0r6ndKPUCg0/OIFXv66Rng19HLDrqhQoR7bQj5hFaCmzOTLwsX8Kk/JRY YbVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EhIa4+r5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x1-20020a17090a6c0100b001bedf836c6csi531142pjj.30.2022.03.08.16.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:38:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EhIa4+r5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C12712755F; Tue, 8 Mar 2022 15:54:38 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344506AbiCHHKJ (ORCPT + 99 others); Tue, 8 Mar 2022 02:10:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344488AbiCHHKI (ORCPT ); Tue, 8 Mar 2022 02:10:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89ED433882; Mon, 7 Mar 2022 23:09:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 25AB561582; Tue, 8 Mar 2022 07:09:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0367AC340EB; Tue, 8 Mar 2022 07:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646723351; bh=Ykqhm2OjaBdscON2MKDblQOd82pwNXwdVIWReQQX+wE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EhIa4+r5vol4YPzhsiJlaNItlU5xbmUYgI//VgThOuUbCZZZbbedjwi3GyusORL9B naHlRfpDEuPN9FO3yXCNanZIiXETHbv6b7UMdo0S/Gkr0OavP2LHMP2JTMrw6t+zZL jcFX/sK6Y5cZtod4MRb8ocQFNkX/kseyCjM8MyUM= Date: Tue, 8 Mar 2022 08:09:07 +0100 From: Greg Kroah-Hartman To: Yeqi Fu Cc: Heikki Krogerus , 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=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 > --- > 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); > } How was this tested?