Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3547051pxb; Mon, 4 Apr 2022 20:47:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcfGYfp993QeRt3Y7QTPSdWJdEVAqdTv9V8sDJo1bNPz6HCELjeYwGIitawlDJex6Ed4Rb X-Received: by 2002:a05:6a00:1828:b0:4fd:e0e5:6115 with SMTP id y40-20020a056a00182800b004fde0e56115mr1494411pfa.52.1649130447580; Mon, 04 Apr 2022 20:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649130447; cv=none; d=google.com; s=arc-20160816; b=Mklhio2m3Xb/8yraY+PHF7eLpb3L6ivRzsMg6uGBYr4IGv9zrQb7qFdx+DyiXsZswK Hmvm35HOLQ19iHm7/qeYzfhdjZvClonOBOkxhPdVQTcl6jekx3dZpNRaOTTzyaPiH515 uUMM/9E+2YYYS5NjraD/FzR4atL69qwVR4+K+1SBE1olbf6/ZvGt1ouuQO2Nj0Az4+X/ LVZk8DxNdyiXnrJ83CsDePwPxQi9QsdxVf/PEpfHvSA6XObSTrKMOHYfQm4bdFnl3wS2 obTVsvZYvSPEVOmkq6FeP5qzN7jbuQAhJvpgyZJqV3DFz4hOgKKrRty0uWjthloBcj3P n5Sg== 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:date :subject:cc:to:from:message-id:dkim-signature; bh=Ms67zyBdNV6hrxEaPT360CJpu7jbKuKGKMPZ/d3UlO4=; b=n01x12NsxMWYEpfwmRZeQctOIDoFAe1JRWn7fs5P+JRBBfkiORpthX/TZZG5MGwOjr 7+oSAdB07DG+OHiAgcg6vZXKZZ0BaFU/2nJPbtNevQXNmzALJYK9sWGtuRq43fJlCjzk FBk3vMmCal666rGr0/Vf2tk4FUrj4jtVmQRLMq7UR8g/KkvhM7bDCKyXdqgWQVUkIjep gx7OOgh9EXGLz3/x+Ru2CAapDNZE5iFR/DfyYarkMJHSJweV8dJCM1TeRcVjA7BNnGMn 784yiI49CV3HP6hUKI/S+VVUltnl7NnREiXVHhbbfguh+uEqSiPaMks8tdGNHpwfZp9+ jGQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=jI8TLh0M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u18-20020a170902a61200b0015674044b0esi7886711plq.188.2022.04.04.20.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 20:47:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=jI8TLh0M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 950F82BC566; Mon, 4 Apr 2022 19:50:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbiDECuV (ORCPT + 99 others); Mon, 4 Apr 2022 22:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230231AbiDECuL (ORCPT ); Mon, 4 Apr 2022 22:50:11 -0400 Received: from out203-205-221-235.mail.qq.com (out203-205-221-235.mail.qq.com [203.205.221.235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4849F1BB19E for ; Mon, 4 Apr 2022 19:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1649125663; bh=Ms67zyBdNV6hrxEaPT360CJpu7jbKuKGKMPZ/d3UlO4=; h=From:To:Cc:Subject:Date; b=jI8TLh0MCXxFl+aH5xm+9Npb/oEWTH5wwfnHGaJSCLKPKngwXg2JWgjUT6HRi7R4T JlGmxzZ5QQGL3Rgy++coO5DMZTvgNfIE5tX7n6P+Hk0vOpwVmQ/sdUFk11FnEwjxak PN94yqlKtXCb56xNUv9QHTMxDV6WheYgDOCkUIuQ= Received: from localhost.localdomain ([218.197.153.188]) by newxmesmtplogicsvrszc6.qq.com (NewEsmtp) with SMTP id 6E804CEE; Tue, 05 Apr 2022 10:27:40 +0800 X-QQ-mid: xmsmtpt1649125660t9z6hhdk4 Message-ID: X-QQ-XMAILINFO: Mv3le6n+CjtdFPofKatnGY7vR5sSKoj1wt14/b6/rM15br6fjRBKA66dToNbUg te6DlAnhPi7E2r3czmflgm8TK9fEe9cBdHknXytTp5C8ZNKDWL1jWBZBw8PByB9gVnI2fxyRJW4g BqGX86UnpqC8sTGz1LOOFcKZmXUVgx4hyg49mrJor142N5Xiepky2cmwrKKMO4PlBOkFMQFbkgVL XTS6FhhuiPXV0GF6799VuDeyxn4TaS4j4yEkpQOc9axe/rzjwNkb7edpCmUL7QMfAcbFClQgRsOt 5W6T7MTE9UMch6GX2l+ksJ1VsevmrT8l70vtrwCsY7EyvvE5bUQR8lZzu6vTfBHebWRUkwxXXhub OM7PJdy42pK5ph1ZeCx/pBvbNGPdrZ+9nEnfEANenQODmS7/V43hO4Cz1pJDd/l5QuuVIqgZBNlo YfAUmghyrfDEMjZldsrERhjmW9mpheFmz9dA7xETg6QbuIxasIlNFHsQbNzlzR6fkKLSiqNpvsVZ lScdH0Y+tmlk37NM8O5a56vjAq5h5SLKU0iIhiwidaM2/9miJFHiJYQTAcFIif1UxQlmaFxfMKPF tZbqgrwKf9/PyFEeFGgKIKlYIDLccxpaMxHyOZxtjedVIaohoDOO+dJav8bM0bp1l3KfKseC07Jn gK4w4qm0xHRLX4nV1ZuB7SSXV737L3YfiQUgwCo1JG3K5gGc72FjrZ2B7QUWuITCeCLmrOvyU0ho yxIHUbrfSygnLF3wnPbAJ7Eke19HU2CVooNC6PnabzLGgCCj4jLt2InvpqI5P+Io/Dn1JHtIhWaP 1bnJoqkeMvJMpa+pKQwQcL5K5T4TvnaEKVeCvxF1jYA76jtwx0Ir+uuXyWM7BHqaDuXg8g3talPV ZKec/De+HdwFWF9jIZVFvh94p4GWoD6uRxh13zEd0zGWPtnQ68UcNFNyHXURQYF1aAxBR9P+Stgs 5s+sy/WP4= From: xkernel.wang@foxmail.com To: gregkh@linuxfoundation.org Cc: Larry.Finger@lwfinger.net, florian.c.schilhabel@googlemail.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH v2 1/3] staging: rtl8712: fix potential memory leak in r8712_init_drv_sw() Date: Tue, 5 Apr 2022 10:27:14 +0800 X-OQ-MSGID: <20220405022714.10949-1-xkernel.wang@foxmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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(), some error paths do not properly release the resources allocated by its callees. This patch is to free them and provide proper error handlers for other error validations. Signed-off-by: Xiaoke Wang --- ChangeLog: v1->v2 adjust the sequence of the patches in this series. This patch is for providing proper error handlers. 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 9502f6a..1f7ccec 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; } --