From patchwork Sat Oct 22 07:27:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1107792wrr; Sat, 22 Oct 2022 01:42:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM664Rg8FtzYGJcU3C9lWUM3DcGX6YUWrdi5eaG2tULM7KdHH+1jfttPG86HVq7PzVlrfZQ2 X-Received: by 2002:a17:906:4fcd:b0:78d:4b28:9d57 with SMTP id i13-20020a1709064fcd00b0078d4b289d57mr18915216ejw.303.1666428127632; Sat, 22 Oct 2022 01:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428127; cv=none; d=google.com; s=arc-20160816; b=TQOvI3VAPy0budEoqLnEMbt3TY93/5c61pppDVIXEhPGnK7CyfHWeMqzsQlCASbOmj tza0b5uDi/JPKL0KmVz6QhyUeSYqQZee+kjZe6wcpi4AJzHm3ui7XohknQVZijdAwtqU hxF1zxN/eXpoqnfWeVsKHPZyWTkWN085K1NrEPdCfAazFchOY6NKaYPMMK4jF3rr1TIO LFy2vK19hV5PApxfBW1dxV/dXgnRyDYQ/aB+SO1yAGKktKQiqHB/OrKihF99BeJu7pd6 YvMy5IDoSi9yIP6iB+WFCsNwfAQCdxRFwkok11Mbl129av5zDFqglFWIYkh+iqayjRnF ZwCQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2VOXCrhkt3yMI2X3yLDsiYR4GyOqlswowtkIaYtOYnE=; b=cNX7L7eMn4HXRa9Dib+7gziu1xU3ASZALGf7Afv3s0b0A0tV9ZwKxiV9e68LybPAHd gz64BCudgkOZbBZmgsirZzOQxTvTuoSIeMGSheol4HHIfLiYOVMQ9zmH0DCg3EwKB830 E27ZzO4Hvpq/C/oO5c8bktypMiTS59d1arWn0nJAjzRKpI6avyJ7A51u5O9Fog6tjk82 MYCcuk7IwT6hyrI7/LIL3/BWRjK8dkh+CZ+OxyPCAk+OQGBX7z0ZPN5Fv6Ez1mfzoNV8 TZ3yNXSF2+/P7cPnVLC6oafeUb3Tz6r3bnZLIoSYDYBCwTW1TRFlnV3dI0npzWq7QM5M c2rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TivkKSJT; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd43-20020a17090796ab00b0079fe11e92ddsi2199817ejc.906.2022.10.22.01.41.40; Sat, 22 Oct 2022 01:42:07 -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=@linuxfoundation.org header.s=korg header.b=TivkKSJT; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234433AbiJVIiG (ORCPT + 99 others); Sat, 22 Oct 2022 04:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234021AbiJVIcX (ORCPT ); Sat, 22 Oct 2022 04:32:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCA5B2E533F; Sat, 22 Oct 2022 01:03:39 -0700 (PDT) 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 ACEDE60B8C; Sat, 22 Oct 2022 08:01:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF3F2C433D6; Sat, 22 Oct 2022 08:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425671; bh=KwB7yzHmIKvJrXcnQgncUVi1felkVMXMpemxmBu6DsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TivkKSJTZtKGxkOWNeFX6cmmIORzVsVt30BEvkG7DZoO/AEhoKvnjBo8izbJHRMOT zzQmz3O/Tsqz55Klwi3hXfkvVD6tuDsRPpurmWAwE53DkwvxGVFFkFCvCaoB+6zH5f ME7TsmXqn7AzideB/oFrIqjGEchEstA5kTmlkB6U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , Jeff Johnson , Kalle Valo , Sasha Levin Subject: [PATCH 5.19 577/717] wifi: ath11k: mhi: fix potential memory leak in ath11k_mhi_register() Date: Sat, 22 Oct 2022 09:27:36 +0200 Message-Id: <20221022072523.940891229@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376540081726165?= X-GMAIL-MSGID: =?utf-8?q?1747376540081726165?= From: Jianglei Nie [ Upstream commit 43e7c3505ec70db3d3c6458824d5fa40f62e3e7b ] mhi_alloc_controller() allocates a memory space for mhi_ctrl. When gets some error, mhi_ctrl should be freed with mhi_free_controller(). But when ath11k_mhi_read_addr_from_dt() fails, the function returns without calling mhi_free_controller(), which will lead to a memory leak. We can fix it by calling mhi_free_controller() when ath11k_mhi_read_addr_from_dt() fails. Signed-off-by: Jianglei Nie Reviewed-by: Jeff Johnson Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20220907073704.58806-1-niejianglei2021@163.com Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath11k/mhi.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/mhi.c b/drivers/net/wireless/ath/ath11k/mhi.c index c44df17719f6..86995e8dc913 100644 --- a/drivers/net/wireless/ath/ath11k/mhi.c +++ b/drivers/net/wireless/ath/ath11k/mhi.c @@ -402,8 +402,7 @@ int ath11k_mhi_register(struct ath11k_pci *ab_pci) ret = ath11k_mhi_get_msi(ab_pci); if (ret) { ath11k_err(ab, "failed to get msi for mhi\n"); - mhi_free_controller(mhi_ctrl); - return ret; + goto free_controller; } if (!test_bit(ATH11K_FLAG_MULTI_MSI_VECTORS, &ab->dev_flags)) @@ -412,7 +411,7 @@ int ath11k_mhi_register(struct ath11k_pci *ab_pci) if (test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) { ret = ath11k_mhi_read_addr_from_dt(mhi_ctrl); if (ret < 0) - return ret; + goto free_controller; } else { mhi_ctrl->iova_start = 0; mhi_ctrl->iova_stop = 0xFFFFFFFF; @@ -440,18 +439,22 @@ int ath11k_mhi_register(struct ath11k_pci *ab_pci) default: ath11k_err(ab, "failed assign mhi_config for unknown hw rev %d\n", ab->hw_rev); - mhi_free_controller(mhi_ctrl); - return -EINVAL; + ret = -EINVAL; + goto free_controller; } ret = mhi_register_controller(mhi_ctrl, ath11k_mhi_config); if (ret) { ath11k_err(ab, "failed to register to mhi bus, err = %d\n", ret); - mhi_free_controller(mhi_ctrl); - return ret; + goto free_controller; } return 0; + +free_controller: + mhi_free_controller(mhi_ctrl); + ab_pci->mhi_ctrl = NULL; + return ret; } void ath11k_mhi_unregister(struct ath11k_pci *ab_pci)