From patchwork Sat Oct 22 07:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1155431wrr; Sat, 22 Oct 2022 04:11:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM53/ZQEH43oSP4bIgdSGuMdpZyz/U48BQzacIkBXGBy5789ioTKdhevdm+IzQfH/0BmX57u X-Received: by 2002:aa7:8d17:0:b0:560:485a:e242 with SMTP id j23-20020aa78d17000000b00560485ae242mr23960666pfe.31.1666437109961; Sat, 22 Oct 2022 04:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666437109; cv=none; d=google.com; s=arc-20160816; b=Qa7Fy256IgMZ7NJJbwNpGCc4cARsTh1t0LrXn+X6uK+HZ9W8CarTMUxkLEUO8rM8LM GiN87WkMZ0gLaaJtH0QdO/6ImxYFn667xPJGebEK18rCRR3Juk+43hL71e1UB+yAZrfV Ssc5exbzwXVk+ZC+xGVdf0GVkzH2tR+epP6kaXs1BXFVU5G5ZGfs40u2qEFz5KVNmSkj Jxk33DjL7EJ+vPQSrqE5SRN9P9GuHlRJkgFXv3CmnExI3vynSKQQtNf4rOT++IXAv5yj w2+O1AS2Ww5atw7l7EwazlP7PMNxQxRVQ0U1vZn/C277VHw50BzneyV7K9JHH9iozYjM /9pQ== 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=VenNqY5hKrdYPa2DjzWSrUg7AQmG4wzq6INMp1C0n5cHK+BVcMsbYo1oen0x9sguC2 cyqnogxofzchOdlEEDtdo1Do2H7tiQEWAThcuPvrAohTA2LXbhFuJk2T/q4X6baJSulr 0aRi/kl2WfRLGf6Mk2IH9L3E8WeqJcYModKx1KCOWMXtvjta9VxxSfuW3/Ndr5D8bWGa aDgY82el5O5qs72VCQfHwQ/SLqTtz8AKSPQAW7PfXwXvXzkBSaSO4eN/GZGSgG6tbXh2 LSnFjGgMoXuN2Lf9MEaQnsL6efg+9dF8JItQjIJmgxQAhfK+jhARmQwdHUExhMh0oZWM oXlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l6GpWIJ6; 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 j4-20020a170902da8400b0017f6557bf88si33910703plx.588.2022.10.22.04.11.37; Sat, 22 Oct 2022 04:11:49 -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=l6GpWIJ6; 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 S230016AbiJVLJV (ORCPT + 99 others); Sat, 22 Oct 2022 07:09:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbiJVLI4 (ORCPT ); Sat, 22 Oct 2022 07:08:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6EE131857E; Sat, 22 Oct 2022 03:27:40 -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 DC41660B7B; Sat, 22 Oct 2022 08:06:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 012AFC433C1; Sat, 22 Oct 2022 08:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425988; bh=v54vnW+bX4cKUN2tJYHQtuvmIGDk0z24Qkca/Gc9l6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l6GpWIJ6siapBAji6Wm6HaF6nnvMBtGRQISybi2Vz4U3E9UohYqZEzvqr0/VN1lxO 4SG5cjxiDE6MeCK8nlQY+xZ1TfvKq4XBUth9/hPiU9wT7qQoGpB46023BveTGbgtSn ZZWsr1pHSkQmihkOCx1eiUJT/0A+POV1Igd+Gi4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoke Wang , Sasha Levin Subject: [PATCH 5.19 681/717] staging: rtl8723bs: fix potential memory leak in rtw_init_drv_sw() Date: Sat, 22 Oct 2022 09:29:20 +0200 Message-Id: <20221022072528.588527042@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@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?1747385959304328046?= X-GMAIL-MSGID: =?utf-8?q?1747385959304328046?= 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)