Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5379497rwb; Wed, 7 Sep 2022 01:44:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6rfhEyFs8wcXuJ7phoX/TK3bd+5uugi2atF2dgX1YcDICN7SAZATnX6zdFjI5eM9obZM/g X-Received: by 2002:a05:6402:5024:b0:440:e4ad:f7b6 with SMTP id p36-20020a056402502400b00440e4adf7b6mr2242299eda.358.1662540266710; Wed, 07 Sep 2022 01:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662540266; cv=none; d=google.com; s=arc-20160816; b=H9Uhd4FZmNT5gygZ8f7qKeSNz4KmeuXeUvBMXZUSJpvvWgj5c+9OnItiN+uus8eSnt /cxC6K84Afi6xs9tQYiKH3dKL+lmZ9qAF/rouKzrN860aAi7gx4qClwwZ3dunzN17Bh4 tuUaX0hz5VrPPXU+VTtXeShD5EokRYixUcxu5ystXgqVIiA0XLaGAOA2ce3JJdlk125+ VrJRD3+cbbskqEMi2NvHGC6qg3YYI7SrFN2G9p+vEeW4Fym2dxjyRJ46JzOHNhA/PWcH hPFLUPhQg85bPO4W1Kv63Bc+7kfKh4CiBA8Sv8Xbn8Ggu8dzIV4SMRvnmV3/e6qtl7PF t42g== 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=Msj1QC6+hqxSIXMSAOcQBdkaMXFRb0rZzELsEToclcY=; b=zFwhebuxZ/wODJLRngRjP2xcw0mQfIK9rT8HtF6BH6SkQBvBVpV5iAH6f+wjPKG9/G jURoMypCGOepVnj9YWwx19bYGKSHkBrgZbOzvAuM/tN5wzQA78E3XHHMHcGV2nahRc4u cG3eCI9zRJrbMjnZ+Tpm+LyelhaQkvjOrqOSVgar1uy3p1mZIEslWy6uvgt4Cp9qwjyX SJVHavaqK48ZfZxIstAnNop/1cBA0zLRHmzdWRL/ERrkwSoCj2fm7wLwM5nS04IeZDjE HUi77nSxngE6iZCn0m29MeT1/UUmiBi9405WsB8W9koTbYBhoV9m4xAGjRkWeGTAI3Og UUIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=eROGLvT6; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020a50d087000000b00445f21c2b32si635469edd.132.2022.09.07.01.44.00; Wed, 07 Sep 2022 01:44:26 -0700 (PDT) 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=@163.com header.s=s110527 header.b=eROGLvT6; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbiIGH7Q (ORCPT + 99 others); Wed, 7 Sep 2022 03:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbiIGH7O (ORCPT ); Wed, 7 Sep 2022 03:59:14 -0400 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E1F6CA896A; Wed, 7 Sep 2022 00:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Msj1Q C6+hqxSIXMSAOcQBdkaMXFRb0rZzELsEToclcY=; b=eROGLvT6ZOUSfEHfGlLUZ ild251wKOwzt+OFp21CXsHjGFxPCgeBPf2JezhARPzQHLHOnVFUg+8Pr7uZwQrlL VEtQ1aeHAY13WUSVeIjR9SDiIM52i2n/FnyhiuiVn9whB8hlIsiGJNWc8boGXQYq WaUbySz05BK2jM7+zIv4gc= Received: from localhost.localdomain (unknown [36.112.3.164]) by smtp4 (Coremail) with SMTP id HNxpCgCnKeAsTxhjktH0aw--.22456S4; Wed, 07 Sep 2022 15:58:49 +0800 (CST) From: Jianglei Nie To: pawell@cadence.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] usb: cdnsp: Fix potential memory leak in cdnsp_alloc_stream_info() Date: Wed, 7 Sep 2022 15:58:35 +0800 Message-Id: <20220907075835.60436-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgCnKeAsTxhjktH0aw--.22456S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7GrWrXr47Kw1fWFW8AFyDtrb_yoWDXFc_ZF 4a9FZrGF1jkws7Gw1Fqr98urWqyr42vFWkXa12qr4fGF18ur93AryxZr4xXFW7J3y5Jrnr Z348t3y5ur1kJjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_F4i7UUUUU== X-Originating-IP: [36.112.3.164] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiQxl1jFc7bS78jwAAs- X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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 cdnsp_alloc_stream_info() allocates stream context array for stream_info ->stream_ctx_array with cdnsp_alloc_stream_ctx(). When some error occurs, stream_info->stream_ctx_array is not released, which will lead to a memory leak. We can fix it by releasing the stream_info->stream_ctx_array with cdnsp_free_stream_ctx() on the error path to avoid the potential memory leak. Signed-off-by: Jianglei Nie --- drivers/usb/cdns3/cdnsp-mem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/cdns3/cdnsp-mem.c b/drivers/usb/cdns3/cdnsp-mem.c index 97866bfb2da9..319037848151 100644 --- a/drivers/usb/cdns3/cdnsp-mem.c +++ b/drivers/usb/cdns3/cdnsp-mem.c @@ -631,6 +631,7 @@ int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, stream_info->stream_rings[cur_stream] = NULL; } } + cdnsp_free_stream_ctx(pdev, pep); cleanup_stream_rings: kfree(pep->stream_info.stream_rings); -- 2.25.1