Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2168957imw; Wed, 6 Jul 2022 01:00:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t/v5zjeK/V4ZxieWQitHLQZqB8LzEjvpKuUajCYRjpfzW5fJns8x31ViRUmI4GKvuTVIZe X-Received: by 2002:a05:6a00:8cb:b0:510:9ec4:8f85 with SMTP id s11-20020a056a0008cb00b005109ec48f85mr45970349pfu.24.1657094459055; Wed, 06 Jul 2022 01:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657094459; cv=none; d=google.com; s=arc-20160816; b=XnIOpbCx6C9LKMco3rbRcpyozJ4gn519ZMA8P/boCc5arjzjbWITPWoFe3AI04VruS 9xe4gtSozgJ1+uSW4yk17dlsdwHdlD5gNIRyo+sUI/fZ5W8lv/C1Gwbky/i7UBtaof25 Wt7jMFDwXw8Jv5LqHkl45t5R1esx/WlhcRER1t7sQriwIu9Yrzk9f2kyudHWkNhBB+ce S8DZ86JAg7PFUqGmehP/QwfsGrkhs+fPK6acyuGbYe6i7MqCbZIguBnHp9Kmo39PtCkC JtBhckwv6R2tDsIcmeGBeGQWp2UfF9hYUxbNzFafEDW6xywE2RFPl+WUjtIzLSKIfaMw BqMw== 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=Lj9phpkDaUMumELan8boAqGDPaY6eZGi/okJ0Y8UAU1F4SLJOx3X5FQ7qx7DOBcsKI BO+ZLLVE29c5sCh8o055VpDlYEfcWUJp5d0TTi5KQNPkVQZiBeDtx9cv3wQkwGCeZKil m6OIi8JNrckWK04HFD2uhkblfEAh8O/PtT/gMh+z3PlAi6L/c0KNFam0Qh3vxxG/TvMJ 6mjyFLNIlrd/hlRn5DusJlorBL1vBdoIGQNAA5a9mUbygWE0VA/9kB7BZ/6rImlHFIzy sVi+5pixY9Kgy/rdzRt7oewA3i+v/TDjS6D6fVV9o1swmsXiSf7IDneqcW0QF8PUpxhh /sfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jelA2TkP; 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 nn4-20020a17090b38c400b001e066ee4c01si30681459pjb.79.2022.07.06.01.00.43; Wed, 06 Jul 2022 01:00:59 -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=jelA2TkP; 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 S231693AbiGFIAI (ORCPT + 99 others); Wed, 6 Jul 2022 04:00:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231476AbiGFIAF (ORCPT ); Wed, 6 Jul 2022 04:00:05 -0400 Received: from mail-m971.mail.163.com (mail-m971.mail.163.com [123.126.97.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31B6A1900E; Wed, 6 Jul 2022 01:00:02 -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=jelA2TkPCVEuiP2+Yihjz xFKo0/E7JG030cyO9VHgg97hNhNIgflovw9X2j6b7ZVXGAqVo0MR5FR8KbfKc51S vLHGaVRM66raANWQoJepMw8DdFZyRBzvrQmt93aFb4Bx7SdXca59ZudGX/3vRIF9 CH9V3SpbI0Cezu4/2muWno= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp1 (Coremail) with SMTP id GdxpCgDHlqHaQMVimzpAMw--.41942S4; Wed, 06 Jul 2022 15:59:55 +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, 6 Jul 2022 15:59:21 +0800 Message-Id: <20220706075921.2255059-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GdxpCgDHlqHaQMVimzpAMw--.41942S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7GrWrXr47Kw1fWFW8AFyDtrb_yoWDXFc_ZF 4a9FZrGF1jkws7Gw1Fqr98urWqyr42vFWkXa12qr4fGF18ur93AryxZr4xXFW7J3y5Jrnr Z348t3y5ur1kJjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREK9atUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/xtbBORs2jF-POXSRtQAAsh 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