From patchwork Wed Oct 19 08:33:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp265652wrs; Wed, 19 Oct 2022 04:22:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63HQY51NKQXYBp6tHcsw08tCrtBUcTjeL9Ui1tASgJBbVciDodoOaQMo+oLnzpOcigAVph X-Received: by 2002:a17:907:a044:b0:78d:b569:b891 with SMTP id gz4-20020a170907a04400b0078db569b891mr6098785ejc.224.1666178573845; Wed, 19 Oct 2022 04:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178573; cv=none; d=google.com; s=arc-20160816; b=qMTgEagqMvIOhJFtDtsi1tX0RUDDxVK+0dgboGNCNPjVEGofJ3s5ixW8Q2hiTVVIyY lZVoB2kw2c9cAHoAmawtYaBRnEC4Uc3E1YNjhS9qC91YtefkUbcmkS+NWLxOHG+o3euN wPE0Z1bHn09GZKlMzINy+SP6v9NzJJvIamkny3OnafMj5YpWVR3iuAe+l78c235k9Xup oyT3WsgXh6Op4rVShQQ4WvnsFWzjqO6M6AiDTJUPoTnoRlL/8YxXCnlQxwsXcx/9+hbo NPkGljlx4wQ2WIAjgaxq6pzAfNIPpI/MWGmhpXH1EEKyLJYLEzgy195zkavAP0C5Fhbi xevQ== 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=ywd0ijHOhkmUc6xK9BIdftwvD03eD3MBYQeBdb9s6+DvSZbhFTt8fSITX4+aoMHGZY X6iya2IknLBGP8zZho1W/ieUXtKi1tV6wjAO8sdd4Tfe0xHdszH2LuOMSF9haWhayFjm 0J9ydQmYcZkph5wKKLKRWBy9k+VGWIpzLm4ug8Y6widXSYyAGbJVJpcIFzDK/s4UxmMl 7EsHN+/4Kw5E05Jlhv4XGWaM89oMKfN/rhAmVvpVhFUkynaUvbTz0dyWes/Acz899ELo IC7PLSMqibMmoFk3sGHjDGlfuYJJ8XO/yrUPMpo1wAt5DV3/eu1NcZFZ2uhE2t4AGsFz KDsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cDTynyAK; 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 l20-20020aa7cad4000000b0045bc92ef2c0si12266456edt.195.2022.10.19.04.22.29; Wed, 19 Oct 2022 04:22:53 -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=cDTynyAK; 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 S231601AbiJSLKv (ORCPT + 99 others); Wed, 19 Oct 2022 07:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbiJSLJX (ORCPT ); Wed, 19 Oct 2022 07:09:23 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E925917FD68; Wed, 19 Oct 2022 03:37:55 -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 sin.source.kernel.org (Postfix) with ESMTPS id 314E3CE2193; Wed, 19 Oct 2022 09:09:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0205C433D6; Wed, 19 Oct 2022 09:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170572; bh=KwB7yzHmIKvJrXcnQgncUVi1felkVMXMpemxmBu6DsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDTynyAKgDHr5rWF1WyloNQ8pl1QMj2G04eHzKXSBW8S4TbH4e2PYKt+g5XgCKQvm guT98zFdvzTwSsRvQbsjt2/XWWDrtkLbEPMBN2S/ASd1HO5PGX/E6ifhaLARiXsUfQ Gc+9HBDYryQSlGJmPb7YT2F9c8WTd51aiN521PWk= 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 6.0 704/862] wifi: ath11k: mhi: fix potential memory leak in ath11k_mhi_register() Date: Wed, 19 Oct 2022 10:33:11 +0200 Message-Id: <20221019083321.099861809@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747114864670420213?= X-GMAIL-MSGID: =?utf-8?q?1747114864670420213?= 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)