From patchwork Thu Jun 30 00:51:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianglei Nie X-Patchwork-Id: 12900922 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 15A02C43334 for ; Thu, 30 Jun 2022 00:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230418AbiF3AwL (ORCPT ); Wed, 29 Jun 2022 20:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiF3AwK (ORCPT ); Wed, 29 Jun 2022 20:52:10 -0400 Received: from mail-m973.mail.163.com (mail-m973.mail.163.com [123.126.97.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B4F763FDAB; Wed, 29 Jun 2022 17:52:08 -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=W5+aqmNpOBgWQCZ2244BF DQdm/Ucmg63hkZqJHkcRA5UomTaxYRlctL97y4dwznuMMiOkNRtt5SHwduEzCEFC uGBD1aGJJwkhqgSj+7CTjbq/New4grv2sPBVrXYInlkqrIwTKjLVuPA8J29eIZ28 exzyNuQNlDUheK2IIqk/wI= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp3 (Coremail) with SMTP id G9xpCgAHs5un87xiTZlmMg--.54029S4; Thu, 30 Jun 2022 08:52:00 +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: Thu, 30 Jun 2022 08:51:48 +0800 Message-Id: <20220630005148.2166473-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: G9xpCgAHs5un87xiTZlmMg--.54029S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7GrWrXr47Kw1fWFW8AFyDtrb_yoWDXFc_ZF 4a9FZrGF1jkws7Gw1Fqr98urWqyr42vFWkXa12qr4fGF18ur93AryxZr4xXFW7J3y5Jrnr Z348t3y5ur1kJjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRE7PEPUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiFRAwjF5mLi7PcwAAs9 Precedence: bulk List-ID: X-Mailing-List: linux-usb@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);