Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp436586iob; Tue, 3 May 2022 01:29:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz76QNCCFaB679geKGVeywxWf6C1PwpsyeInJuq70p1EAWbxEsGN1VzLoiOEAuvlZDJNvMg X-Received: by 2002:a2e:9649:0:b0:24f:15e6:a6c5 with SMTP id z9-20020a2e9649000000b0024f15e6a6c5mr9225232ljh.86.1651566566700; Tue, 03 May 2022 01:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651566566; cv=none; d=google.com; s=arc-20160816; b=bJtAaDfhLPWFWMxAu1r5tCtnB7o8XQFca0ilp0t/NH2cY2Qy41bCS3cMnoXXpoZpWC RX5MxxnmycWzLQ+xefszbnUAzjTC1iz+2b7FU9oA2wS4gtFc2e5FqrumVHbCXx/EQMPy WuOxFoT2/+dzCTVj1W+oEgDEGxHnoJlfb070icd35feXTodgN0EFCXhPOq6N7j9OOzuR 1g4kdR/a86B7FNdMmcjthkTfC3uX4KDQo14VKKn+VNZ2lOPFNE/ktNxiHoe6brSWe7SW jRGvitKckj481emiGGAGYaMdIMZpp3ZR2326bEg8z6uBtnU1C6Cvt4Kk/Ns4331yF0l3 UwLw== 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:date:subject:cc:to:from:message-id :dkim-signature; bh=a8VkqhTbS4VV0BGBP7YiwpU3oywneHl1xKAIjgRkWk0=; b=DrSiKrA09ajSay+RyRNffzMLB4tEV1yV0qr34ZhUug8KtWJKMRcNzkD0pJ/Bnt4wSX KWM2L74iz0r/JumdK8g8mJPtcbZDfYsCOPyU2ZztfIJIkT6HKEYQ5lGfe3dukKHDScm8 ODdim9RB2wxMJ3p+9PUtzoeXUpb6vWzXWe/0Ynj7/5OqYoVw5ZSLA5F10EDTGJVLa+kP Kr6+swawQ2Hfxt89Q7REGRUDIcoZrwrGNYfAn8v7alkexhNKWdAC6HIhA1+r8Tl6rCwd 1TJLKEruujDn1/SzES24xIKARARzlj0fkbGR95bn95K3p3oqNoF0RLwGUafGIb8CZ8E5 98eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=nP2TuOtX; 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=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y19-20020a2e3213000000b0024f2425d014si14326327ljy.257.2022.05.03.01.28.58; Tue, 03 May 2022 01:29:26 -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=@foxmail.com header.s=s201512 header.b=nP2TuOtX; 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=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231294AbiECHCz (ORCPT + 99 others); Tue, 3 May 2022 03:02:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231329AbiECHCw (ORCPT ); Tue, 3 May 2022 03:02:52 -0400 Received: from out162-62-57-64.mail.qq.com (out162-62-57-64.mail.qq.com [162.62.57.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD39238BC7 for ; Mon, 2 May 2022 23:59:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1651561155; bh=a8VkqhTbS4VV0BGBP7YiwpU3oywneHl1xKAIjgRkWk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nP2TuOtXfjVqrE2J7Q909uRTnswni4Ti7Kd7FXyCW3SR3Rirc/Zbpc0lIWcUDfRhr n6xbLaFW/Z5Ijr6lGvzGwqaKr20RK6STu3Yp1pgDuBSQWW+2f5N4BQ/laVP8bQ+yoj KiaDJpAdgqpxFvyPJZpB4ROtan5H4i1gzKRuEf/Y= Received: from localhost.localdomain ([59.172.176.242]) by newxmesmtplogicsvrsza5.qq.com (NewEsmtp) with SMTP id ECCB5CD9; Tue, 03 May 2022 14:59:12 +0800 X-QQ-mid: xmsmtpt1651561152t99slzn8x Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9fiOOpy28RahsysLz46Fk0MHtJ1qIf3ooguRaYv2E2SEpDXdxdQ aXuGsTh5C6I9uHZTwEmP2nTKCmjOAXyEKDZt+eo9gdpwkTWYkPgC1uyWU8w0wMxI89Cfrpmozxos n6wH7bH6TzRU8abdYmmUcpAaFKfgG6n1cLWW3elYap1EVkQrhp9EuDFzm87qQp+bRJWJhW7sbHOQ BbzbxEX+C5teAIfxVqzgFwXyhtCaXUBFwdyCpols2PVn65/8f0X2dMCA5cG60yQ4HUH5jfu7BCP6 XJ0MqHKzAPeShEG6Cvf8BBXeypPTrRAwX4NuF4WDOO7HQiTHrfiuSrYNsGcnuHoJkqXOP2pH+/e/ 9eBfSqUhFjaA+sQb8Zxe2h4E15UtrH0Q30fbSNIA3D8hodHZmkMYHDSlO9y7u5aP4Qj5Xe6MygX4 Dby3HqxCSbv0Mp+5ebkwxqqJwvJFZjTch9GftsF2ed/KHPJY9FRorpaZp2G8lN5L/gBkTw/NjT37 9HjtPx2WmpYXJ10KgfOvd9etDJEUW8mUex5ipbvh4TOPkXMsdd61NRnBg1iELD6LTjihKBn3zram Lkuq+LRU5Q5AVTXKybIpNz5sauibHQeQ6YzC5o9Tr0eVH+kXNUAIrpCFsJZCRBOVgiw/jBKxAYFH mjr69wY4DdvoGayerPDh/QX5MpfoazyxLTnKk/Er8RNqWRswEeHPggzj0kNcGBPFopJdF4fYGh3l Z+VQsSy+CkTkGKM/L8TkAkLTLBGfuzSVXPVednfqLf90WtcEzzFEJRb4Kc1TBlBNwCmnlVuLZTpX 0s5TJaX6BOLLWsvoFP7Ad+TDzKgITbvZNLVlcJ0QwUV29hNgHROALcrG4IAnm6iBBo6+MgChDU43 ifidUMT5GTWE43zLJKDhUHe30fZDFh4K+n6D6WhCGU1wXJpLd7QYKtvNjF96fKjMGAlvP/LWHwK5 t/CfKy7/KaYfAgPjlSPcT60BLLoRbx From: xkernel.wang@foxmail.com To: Larry.Finger@lwfinger.net, florian.c.schilhabel@googlemail.com, gregkh@linuxfoundation.org Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH 03/12] staging: rtl8712: fix potential memory leak in r8712_init_drv_sw() Date: Tue, 3 May 2022 14:58:55 +0800 X-OQ-MSGID: <20220503065855.3218-1-xkernel.wang@foxmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RDNS_DYNAMIC,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 In r8712_init_drv_sw(), there are various error paths do not properly release the previous allocated resources but directly return the error status, which leads to various memory leaks. To properly release the resources, this patch unifies the error handler of r8712_init_drv_sw(). According to the allocation sequence, if the init function returns failure, it will jump to the corresponding error tag. Signed-off-by: Xiaoke Wang --- drivers/staging/rtl8712/os_intfs.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c index 003e972..43a7953 100644 --- a/drivers/staging/rtl8712/os_intfs.c +++ b/drivers/staging/rtl8712/os_intfs.c @@ -304,10 +304,10 @@ int r8712_init_drv_sw(struct _adapter *padapter) padapter->cmdpriv.padapter = padapter; ret = r8712_init_evt_priv(&padapter->evtpriv); if (ret) - return ret; + goto free_cmd_priv; ret = r8712_init_mlme_priv(padapter); if (ret) - return ret; + goto free_evt_priv; _r8712_init_xmit_priv(&padapter->xmitpriv, padapter); _r8712_init_recv_priv(&padapter->recvpriv, padapter); memset((unsigned char *)&padapter->securitypriv, 0, @@ -316,13 +316,25 @@ int r8712_init_drv_sw(struct _adapter *padapter) r8712_use_tkipkey_handler, 0); ret = _r8712_init_sta_priv(&padapter->stapriv); if (ret) - return ret; + goto free_recv_priv; padapter->stapriv.padapter = padapter; r8712_init_bcmc_stainfo(padapter); r8712_init_pwrctrl_priv(padapter); mp871xinit(padapter); init_default_value(padapter); r8712_InitSwLeds(padapter); + return 0; + +free_recv_priv: + _r8712_free_recv_priv(&padapter->recvpriv); +free_xmit_priv: + _free_xmit_priv(&padapter->xmitpriv); +free_mlme_priv: + r8712_free_mlme_priv(&padapter->mlmepriv); +free_evt_priv: + r8712_free_evt_priv(&padapter->evtpriv); +free_cmd_priv: + r8712_free_cmd_priv(&padapter->cmdpriv); return ret; } --