Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp166816rwi; Wed, 12 Oct 2022 17:59:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5zuOVy9wUe9q1EXJjxpydQMYMg4eGUkjbAa0NzHRFAE26sUdENJB3L5aF4IkHhmIpYqb2F X-Received: by 2002:a17:907:3e01:b0:730:a690:a211 with SMTP id hp1-20020a1709073e0100b00730a690a211mr23950441ejc.596.1665622762086; Wed, 12 Oct 2022 17:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665622762; cv=none; d=google.com; s=arc-20160816; b=Ur9a9EeVvDOxu1TOtUEsgsbQU1BeuiZppZ5fNf1ue9NneyWxXYAd/wyYxT16mRlzRA KKi4+gMjDmfUCliw0gRBIusAXtCKSabMbY9Ess8N1IrlMUQR+zGGEuPjQsSAlHf9VLJJ xYhk6oiHeNrRrMb6GwZMtnJA+Nq3LDZay6ug6coC5A59RVNjuziI/+dHGwV8Ro+9jol2 y4E8qAr6xeLRlE7zzgaaIGPuJitQBmYuqzELeP11/JBSV534OTBQKYB3V86Wabo4P4wD JGN/H4jgOWjBVqphz8Qd+ATXyiqD1k7HQMp26GE3/cIRtAR8WfnZwzWUxkYYaFPtTmBG jQXA== 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=y+BsHAJRDvz5QiRCJsFRXVtWVLW/Kh41cNxu5ogLHtc=; b=XAojzFl2lDMMum1FWkxKFwfQ4AoLwZkCggc9eVSkj8ddAMREXUbWVUfxcCKCWLr20t vf3qYUZ4WFNg9fTaLXiLVMt6HFNb8kVVkBKJ9FWvYR5UJljHll1+yjp4KPdyKJgp41/o oAJPdNjh6gCavqAjzUeZ0PqN6WcFJf395CZalkY44NRwfYrInuE9+Om3jOf/emhXFctg wldK+OHEkaPTVxRuCMCCL0trB8GGKC3+MMhLEIoURPr2+5SUWnhv/cMQa29gxhNk+wr0 Yh8GLbmaheICo1YBq2pT1HytE8ZSpM+LiNlzp4isNj6JDkTwU5ShMCX8NmFnIvgmrwZ5 CP4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IF21V7tj; 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 gb10-20020a170907960a00b007848e6eaef1si14171354ejc.733.2022.10.12.17.58.57; Wed, 12 Oct 2022 17:59:22 -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=IF21V7tj; 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 S230189AbiJMAU0 (ORCPT + 99 others); Wed, 12 Oct 2022 20:20:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbiJMATZ (ORCPT ); Wed, 12 Oct 2022 20:19:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A3D171CD1; Wed, 12 Oct 2022 17:17: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 7E411616B3; Thu, 13 Oct 2022 00:17:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9D23C433C1; Thu, 13 Oct 2022 00:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620258; bh=v54vnW+bX4cKUN2tJYHQtuvmIGDk0z24Qkca/Gc9l6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IF21V7tjfLsbYS1DqCutOE6nOeXYt6FGOYOC4YVUKf7TFptlHWn98h7suIbMpG9ep cBenltYGCvBUsfc2ALurDprFBsI75cm+yUKRLIZxBqXLs7J5P4o0bcO+RYUzXH0Hy2 Ki6Q9w1ZhDZzYLRgt4ZiOuAwP4q+Zvs9T2FiBb2Rtv/OD+K0qEfV/ez+d2z78Up1sJ GsPge7nZ+pEzThipCjppVFBgftVoqO510ErYbIOhZYqbgrZHexAUj5UK6ov+HqBpKx OufPEqcuNmu3jkIdbc2mmcKaoT5XytQQ07DlUug3y0H27E1J0X70xFsVCFDLjXerrv gJEdnVWFZEbuQ== 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, cgel.zte@gmail.com, macromorgan@hotmail.com, chi.minghao@zte.com.cn, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 6.0 45/67] staging: rtl8723bs: fix potential memory leak in rtw_init_drv_sw() Date: Wed, 12 Oct 2022 20:15:26 -0400 Message-Id: <20221013001554.1892206-45-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-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 380d8c9e1239..68bba3c0e757 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