Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp193274rwi; Wed, 12 Oct 2022 18:28:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FczUqdj/lN/w9HNO1VbolBebRMwNiwPAbKf0lWJwZxQeN3JTuCKckEExaZ15c37pFwo9B X-Received: by 2002:a05:6a00:1828:b0:563:24ea:5728 with SMTP id y40-20020a056a00182800b0056324ea5728mr23214650pfa.3.1665624511614; Wed, 12 Oct 2022 18:28:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665624511; cv=none; d=google.com; s=arc-20160816; b=TTBfIEt/c8hC0UEhWpFxDS1C81XtxXri9fNoULuzCU9NAKrCLCPhQSOmsJCY0ltKKZ p19uzeVsNifHInypXNAbHJKERdCyM3CQvbsr0Fce1Wh8q1imxGOcFHHwBips50GY2tPh 40dRHhgJOljFf5xjUbSi4O8Vkm+ufNV76cvJLYrPqXghoW9GZxQccNImK1aY8k90RT9U XYCOKynugg59tLG5JFfO+I855e1V3BI956MiM3Ojy5IYRbNPJxJB4SH4WTe5G6prtWjz wA4t2AJtl+X0s7BtS9Pnaobr1P8MsXW4Cxg8URlHt/huEe7dKywPmsPGtfAIawOz1CWl PGTw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z+jCTTgwLWvRoMsugQkhW1Pcb+h/mVljyL6bImSEzSU=; b=opzVnEAiyxGBa7IShE5g319+YCUrKLGM6Vk3ty4Fwo9MhyCupchAMK08tbSV02PHIb 2z+lu5j0IqBNvp5OzNya6yNAHmTG4itqWRU+7t6Bvx6+joyZ8Z9l3vZJCU9PhQHDGzGt YEQGTyWcmCGkspy7E6ySp4556y+lyuLh2Dtl8xkOq2yv3NJBJ+/qGd1+6MSkpxs968DC Iw6LqZg+k20X1OjqLO+bRhp6f8TeRA8rGMhOEhexxDQ+j5+95ChYyoA5L6DDsNGRi+/3 gBlEn+ADfwGyutJBHhoEVEO0LDmRiJFYyAwqUF2UYZF0rv/3mdYZ53pzgUmu+5rZNMCv WpsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AxjThRo6; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw18-20020a17090b4d1200b001fe30008cd0si4265810pjb.166.2022.10.12.18.28.19; Wed, 12 Oct 2022 18:28:31 -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=@kernel.org header.s=k20201202 header.b=AxjThRo6; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229961AbiJMB0X (ORCPT + 99 others); Wed, 12 Oct 2022 21:26:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbiJMB0T (ORCPT ); Wed, 12 Oct 2022 21:26:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3F9710B771; Wed, 12 Oct 2022 18:25:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8C506B81CE3; Thu, 13 Oct 2022 00:22:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E63FC433C1; Thu, 13 Oct 2022 00:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620575; bh=qd6LVdBCL3Cil1E7dDFfBwIQmLB/mefnb3pIebjmg/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AxjThRo6OO0cRVPDKd2zr5IWrWJn8Rtxl/zm2xlYCrudiApkE0U2I0IovV7txz4M/ VajHY7r/vPbwHPG73UYgKl1cmzbARYWSq+IH5bYiZN4WKpzkOJ0eTmP0NN0P1etpbW F73fGBU0SAGvjXmw6TuHNssn2OxwL4H98oXB1+ebIVnMIgNFVwqOaDLhWg+7e7Pasp xfG69pF+s/5jl7CxQ8sJF2THFk4HxvRs+8H4Q54cD7Y7DEDy3ch9sOUZXNdGDv+hU/ RN4KlhUJP4Tcl5lU/NaX9KPr/8vSWnlcgw2JaB97T3U0sVUWRbmgcyXvxSsarZC8hX Px0EVb98dWG7A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiaoke Wang , Greg Kroah-Hartman , Sasha Levin , kuba@kernel.org, hdegoede@redhat.com, macromorgan@hotmail.com, chi.minghao@zte.com.cn, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 5.15 35/47] staging: rtl8723bs: fix potential memory leak in rtw_init_drv_sw() Date: Wed, 12 Oct 2022 20:21:10 -0400 Message-Id: <20221013002124.1894077-35-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org> References: <20221013002124.1894077-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 From: Xiaoke Wang [ Upstream commit 5a5aa9cce621e2c0e25a1e5d72d6be1749167cc0 ] In rtw_init_drv_sw(), there are various init functions are called to populate the padapter structure and some checks for their return value. However, except for the first one error path, the other five error paths do not properly release the previous allocated resources, which leads to various memory leaks. This patch fixes them and keeps the success and error separate. Note that these changes keep the form of `rtw_init_drv_sw()` in "drivers/staging/r8188eu/os_dep/os_intfs.c". As there is no proper device to test with, no runtime testing was performed. Signed-off-by: Xiaoke Wang Link: https://lore.kernel.org/r/tencent_C3B899D2FC3F1BC827F3552E0B0734056006@qq.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/rtl8723bs/os_dep/os_intfs.c | 60 +++++++++++---------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/staging/rtl8723bs/os_dep/os_intfs.c b/drivers/staging/rtl8723bs/os_dep/os_intfs.c index f78bf174de8e..23f4f706f935 100644 --- a/drivers/staging/rtl8723bs/os_dep/os_intfs.c +++ b/drivers/staging/rtl8723bs/os_dep/os_intfs.c @@ -664,51 +664,36 @@ void rtw_reset_drv_sw(struct adapter *padapter) u8 rtw_init_drv_sw(struct adapter *padapter) { - u8 ret8 = _SUCCESS; - rtw_init_default_value(padapter); rtw_init_hal_com_default_value(padapter); - if (rtw_init_cmd_priv(&padapter->cmdpriv)) { - ret8 = _FAIL; - goto exit; - } + if (rtw_init_cmd_priv(&padapter->cmdpriv)) + return _FAIL; padapter->cmdpriv.padapter = padapter; - if (rtw_init_evt_priv(&padapter->evtpriv)) { - ret8 = _FAIL; - goto exit; - } + if (rtw_init_evt_priv(&padapter->evtpriv)) + goto free_cmd_priv; - - if (rtw_init_mlme_priv(padapter) == _FAIL) { - ret8 = _FAIL; - goto exit; - } + if (rtw_init_mlme_priv(padapter) == _FAIL) + goto free_evt_priv; init_mlme_ext_priv(padapter); - if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) { - ret8 = _FAIL; - goto exit; - } + if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) + goto free_mlme_ext; - if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) { - ret8 = _FAIL; - goto exit; - } + if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) + goto free_xmit_priv; /* add for CONFIG_IEEE80211W, none 11w also can use */ spin_lock_init(&padapter->security_key_mutex); /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */ /* memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv)); */ - if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) { - ret8 = _FAIL; - goto exit; - } + if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) + goto free_recv_priv; padapter->stapriv.padapter = padapter; padapter->setband = GHZ24_50; @@ -719,9 +704,26 @@ u8 rtw_init_drv_sw(struct adapter *padapter) rtw_hal_dm_init(padapter); -exit: + return _SUCCESS; + +free_recv_priv: + _rtw_free_recv_priv(&padapter->recvpriv); + +free_xmit_priv: + _rtw_free_xmit_priv(&padapter->xmitpriv); + +free_mlme_ext: + free_mlme_ext_priv(&padapter->mlmeextpriv); - return ret8; + rtw_free_mlme_priv(&padapter->mlmepriv); + +free_evt_priv: + rtw_free_evt_priv(&padapter->evtpriv); + +free_cmd_priv: + rtw_free_cmd_priv(&padapter->cmdpriv); + + return _FAIL; } void rtw_cancel_all_timer(struct adapter *padapter) -- 2.35.1