Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2729689pxp; Tue, 8 Mar 2022 00:06:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFHYs3ZMe86Rs47Xsa/62Fln+duavnUCVRe5vO3+7d0ylPOhZTRkoXwar5SpeLu9PZTdtO X-Received: by 2002:a17:906:7953:b0:6da:951c:1173 with SMTP id l19-20020a170906795300b006da951c1173mr12359580ejo.465.1646726797192; Tue, 08 Mar 2022 00:06:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646726797; cv=none; d=google.com; s=arc-20160816; b=ml+YaCcsqYDklwMAn3xpeZKF+np7GU53kawnY2l1/t7VniJmxyCeVlMAzykCD3i0se HUBxNOMRr2AcyCrmfSHSV9Zxa8ELdk1KVQ+I0Tg+ex4+VVm8chroOG085lpoguoNs16h yjjbX1ZbKJkeHc4gm/y+3KYCZ6QbzWbxSfwtL499ZJ2D2KT5+ULJ1HzB9e155gBYWE1O +AU+tC+ZS8dVCMBm5EQN3c/guKoSw1yVyxiGDBpz2RdeGu4nj5WI5BOZWZ0Q9tWJWUII dsDol1AghcRImNZ9aL5pQ0khzZvLAZpvxBhw1zoQ6SPv54Lh+HIKkC7btvx7Rg5HOYci 4nUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0WGEDjomgTIAfweWu7avOEAcbJjxPD8+Y4IRBGqyTSs=; b=Z2AT9iBgZr79ixBI+D2LKZbGdHE8I/ZuLXxKeH1zdlCafTIIQIQP9+VzBSON1M6lpD sedYPgrGzZGBqrxNczx9bhXaHsvcThNycqP3SYKHM2QgkAPCrlBvhc6fy1VDjB9UxNrC Ul/DDvIzGv4iPp1Mpb+TlkOEiyqWz3xEopREf4yKDQCJjuKeqz/b7JS6//qWLAK01yHz /nPwkL2tYN7GAM1rP/+4amZXDEuglUfbZSDZxc9NpT1wga2UaFMGX7DrvYeVYRFmDaQ6 D9cCEDrKJfvrVa2gwllCV8cN9PdkG4JbNRUurw9GHvWKxmPFhU+REJP33LxTeaOFpFsC kajQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dy1nFUgJ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa20-20020a1709076d1400b006d8885a0cb9si11683449ejc.289.2022.03.08.00.06.14; Tue, 08 Mar 2022 00:06:37 -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=@gmail.com header.s=20210112 header.b=dy1nFUgJ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344045AbiCHG5X (ORCPT + 99 others); Tue, 8 Mar 2022 01:57:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240919AbiCHG5X (ORCPT ); Tue, 8 Mar 2022 01:57:23 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8741C3D1C1; Mon, 7 Mar 2022 22:56:27 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id n2so6713933plf.4; Mon, 07 Mar 2022 22:56:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0WGEDjomgTIAfweWu7avOEAcbJjxPD8+Y4IRBGqyTSs=; b=dy1nFUgJ/b+z32FJwqyUfd7xd5jlSvl/9LlZ8hNMpeM1uf4qwzJ6+yYSOV/tT7zMwZ 28NOTbJyeiNST9tkD+lM6obBQK43PjS2EyrYSVvuxWNQ5WTj32xvWvaf93aCPht939Wj alJDrQ3LUDYVjUENg0NkUpZqw5w4cGM/rbxBNzDRNxCQUr/ulPndrWdLTiVTfhbX+baq puztxakZHcR47C0xaqDCWERdE3uK/ANAKXPl0OCARlDfQKMKjXRTs9l4wd06UAQgqz8l WuFOXYeFBFDNglLnJuZWPm5Xc9aaFoc/6Ia4wYnD30r1abokHkY0HTPv3H88qVzjdXA6 4PNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0WGEDjomgTIAfweWu7avOEAcbJjxPD8+Y4IRBGqyTSs=; b=MVsWxhhepyTQhM9L6jqwC1bHBWGLdFM3AMXVmx4zl9/KMcvOw8EAulLLVbepqrr4Wx 0NToCoHB8mK5zuBG2NKhPwKRWr9MWkAZ19FGG17y9hzZET7HOI06/GASJPwGRINStmov VRIBk2WHJwJadEASQaCDF825Bgb1NomScqTxOGucCh9dhVnvHs+cv8HV7obIiE+t2PxT qMP5paGBWh5HBzaZAXh5bRgkFgND0W+dIF98CKAD/+94zqOzrqJl2lAW8j/zL+08jim4 3I1Rc+9CtJ5CEKNKYe8k+wi6rhSPm379+szz7W2TJGnRnWDX+bbPr8HJUCHb7K1lzu1u D9Bg== X-Gm-Message-State: AOAM53168TWlTQSnFTvwRnQhHaKz8PRxIfFFLaFyhG7KUW/o8hw/ynRb C2LQTQFTXH6ke59I++tBVtk= X-Received: by 2002:a17:902:c947:b0:151:a988:f3de with SMTP id i7-20020a170902c94700b00151a988f3demr16012133pla.104.1646722587079; Mon, 07 Mar 2022 22:56:27 -0800 (PST) Received: from ubuntu.. ([115.27.208.93]) by smtp.gmail.com with ESMTPSA id b10-20020a056a00114a00b004f701135460sm6474236pfm.146.2022.03.07.22.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 22:56:26 -0800 (PST) From: Yeqi Fu To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, lyz_cs@pku.edu.cn, Yeqi Fu Subject: [PATCH 2/2] usb: typec: fix memory leak Date: Mon, 7 Mar 2022 22:56:17 -0800 Message-Id: <20220308065617.90401-1-fufuyqqqqqq@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 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); } -- 2.30.2