Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5332951rwb; Wed, 7 Sep 2022 00:45:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ib+5mRkmiEMbvzrYI0qqIei3RPNnO7/UbyKhjOcq11oMua4otnEKbnrwSFw5L+0f2bWax X-Received: by 2002:a17:902:7249:b0:175:4643:f85c with SMTP id c9-20020a170902724900b001754643f85cmr2635014pll.31.1662536749846; Wed, 07 Sep 2022 00:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662536749; cv=none; d=google.com; s=arc-20160816; b=BLntAVCfRNT/UIGUQWMRMWfM/iBdAxXAzcWmRopJ+n42xpydzi8Xf2v9xp3YB5fbpc djBsj9ObyrNHzw/gkzsolk9ELH64X8P70rrUEkwteCVaPrButbFHOJijXINaL3qUnQot Y1E59lXLi3msU67pog3S5Nz/WD/xyfDzS5vm6lldz/E+slqWZeq/ZH8YVUmzX3s9298N 8oPrckTjYiSfTJAKy++j7aKUi4xS/VGF56p9G+6XIcamt2iGGkS3gmBo13SjxCdjSvWI GiCGl5RYDqo5L1uJUI6Z5NQgDBMbemd13sgs/uWsjiIpW8Tq5Ub8nxTkR8fevabGh/9S gI2Q== 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=5F0LvwMp5Uf995lkO/Kaz7oV49tMvldju3dPm9T1C4Y=; b=visppxKxGQN4GiJwVDljGCAZT1h2Gh2WZnFAbBYkEq4m1od36SX7+LsA5qJigorjUe 1xexow9pyQ4ogK9WetbF1mq55+fQfNJJw+h6I4QJEJUMA3o+oRq5Xk49+JeZf4Di1rQy ykNzAf0wZfSBYzWu0lqs85iTgQ7pxiJMtF0XBw2j0L1V8alcbIbtm/uvtBMevEm5Pqjm suTjFSoWpAWu0e51MpfzCtZCnivILG3ABe32XCph9Y8a+QMSkum0DFItUDRwb5RnGWoQ 0r0AG/xPlSyutR0OJy/Dm+yNgdOXOm3Mjul5VP8dsn+atnwZu5/RoUpxd0YA/gn+Yrqo 6pzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=e53lznAb; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 r20-20020aa79634000000b00535fa14ffaasi15022763pfg.116.2022.09.07.00.45.40; Wed, 07 Sep 2022 00:45:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=e53lznAb; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 S229715AbiIGHi7 (ORCPT + 64 others); Wed, 7 Sep 2022 03:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbiIGHi6 (ORCPT ); Wed, 7 Sep 2022 03:38:58 -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 62AF27B29E; Wed, 7 Sep 2022 00:38:56 -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=5F0Lv wMp5Uf995lkO/Kaz7oV49tMvldju3dPm9T1C4Y=; b=e53lznAbnIsVv5a8/sJWR iLV+M4ptv14xJo2wWlLLbt9f4oM0WfERvZl67bpjHKNH7oE2cS8UHjPzDUyTOQuU 0bzRvu6yxYjX8Z+U02/yEp9HxyNmCNwk1ssSTOKBcgTyNsRbs2xqqvAUiqAMkbWd pprZXGza2JZWRTYnfc64lY= Received: from localhost.localdomain (unknown [36.112.3.164]) by smtp4 (Coremail) with SMTP id HNxpCgAn1cUiShhj2zzxaw--.48992S4; Wed, 07 Sep 2022 15:37:17 +0800 (CST) From: Jianglei Nie To: kvalo@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: ath11k@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] ath11k: mhi: fix potential memory leak in ath11k_mhi_register() Date: Wed, 7 Sep 2022 15:37:04 +0800 Message-Id: <20220907073704.58806-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgAn1cUiShhj2zzxaw--.48992S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7uF1ruF4UKw1xJFW3uF13XFb_yoW8uFyDpF 4fW3y7AFyrArs3WFWrtF4kJFy3ua93Ar1DKrZrGw1fGwnavF90q345JF1rXFyakw4xGFyU ZF4Ut3W3Gas0qF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziCeHPUUUUU= X-Originating-IP: [36.112.3.164] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/xtbBOQB1jF-PPLP6bAAAsJ 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-wireless@vger.kernel.org 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 --- 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) -- 2.25.1