Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1120086rwi; Wed, 19 Oct 2022 07:00:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67RMxpz4t37FmeZ1BO8vr7etCWX29BTkPQWegKLgcz7p59x4rUVQJ0TRr20LCvAts0rfbH X-Received: by 2002:a17:902:e88e:b0:183:dcb7:c4fc with SMTP id w14-20020a170902e88e00b00183dcb7c4fcmr8380529plg.32.1666188055493; Wed, 19 Oct 2022 07:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188055; cv=none; d=google.com; s=arc-20160816; b=xH8Tq1GTZXqMC6fg1RmzetxeV2UgsCVzgmPFE9z9yBGwvKGhf75BZBtGKA0il8PMIB pqqaP3i95aOGPQuaol9idWdTYWmoTe6YL7YLBkSDK5ibfOVfGAx8U7tOGtxs8rSkfIIl a+WhrT7dXB0lAy9qeA/j2deX5yVI0kag8Wx85zscUxSXpExF6Sa+1grn2FHyVSwEZI4x Xe5+94Ecrhh8MiZDujcrzdD+5eLb4v9GpXaJWJ6T35PL3eJQkMoRtAqzOeEHGIkm5YuL XILzR6BbJc8hQ8XGk3vpXOEKVewgldBBU3oWAQvyd3cXDnCyi+//UhXgmIitWxoi9pIt 6PFA== 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=y+BsHAJRDvz5QiRCJsFRXVtWVLW/Kh41cNxu5ogLHtc=; b=FIrlxqfZ+2YkTICF1XSeHotR6lwa29yoEPZLWYZSglA06wWYNiNJu9ilbwcXbgWwOf 7Sclf0U6HqNi8PBeynMSssL83l4VJLpO4E4Sb7MogZpE7m825qxFnekoW5kWVYgh/KZ3 cbwrEeNvwojmOhMEwcNARURyATG760yQLyGsqX5uYalrGzLZy17RgeLXgtrpLzLtELmw z+afPTJy8C7S1XHG4BMDlrvPb4R398eIPdwyfp1WJcLw3SE3L/m7UX1R2APxA+fmBAgO NQWadCwxk7tcM3BvlmsfTLOD4iuY69J/Rw4uN9uZR/WCEos9+7mqctZDnYPg5+j5UrRy 2rLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YNYQegpz; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a056a00080300b00535d7265923si20852532pfk.377.2022.10.19.07.00.38; Wed, 19 Oct 2022 07:00:55 -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=YNYQegpz; 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 S232546AbiJSNhY (ORCPT + 99 others); Wed, 19 Oct 2022 09:37:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232058AbiJSNgi (ORCPT ); Wed, 19 Oct 2022 09:36:38 -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 2855C18B4B5; Wed, 19 Oct 2022 06:25:19 -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 073EDB824F0; Wed, 19 Oct 2022 09:16:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 687F9C433D6; Wed, 19 Oct 2022 09:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170969; bh=v54vnW+bX4cKUN2tJYHQtuvmIGDk0z24Qkca/Gc9l6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YNYQegpzo/M1LWT5tIeUpfFyWcR5/pKbOskirTQJ5pDxFfjw7qnHExgRRfZC+6kXk IIdA1uxXEoEr4G1QLub463cWZ7qs3WDYj8Q7vMs/BCUEGJvTGgGZAmkZadrCLn6rCE 9k/oYnCC4MQ/noSVlddJ9flJUChSRbNyx3xbzrBQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoke Wang , Sasha Levin Subject: [PATCH 6.0 824/862] staging: rtl8723bs: fix potential memory leak in rtw_init_drv_sw() Date: Wed, 19 Oct 2022 10:35:11 +0200 Message-Id: <20221019083326.330272358@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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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