Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp465274pxb; Thu, 31 Mar 2022 09:19:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdxG+O5T/VEZe7cNwy8+Wc3L2XPoPjt2ZLDpsd+HFaJ+lE9hmGWCcO2Y68u3KgP5b5+mj2 X-Received: by 2002:a17:907:7fa3:b0:6e0:94bf:1ec3 with SMTP id qk35-20020a1709077fa300b006e094bf1ec3mr5493165ejc.447.1648743571098; Thu, 31 Mar 2022 09:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648743571; cv=none; d=google.com; s=arc-20160816; b=AQGOyKke1RcAPGlUEBG0ymnprYOZbfBBXazDPlu4+Y6zoVOJcsmY+jEFb04DwJF9cf eXQroQ80/+252rCotGqxoVrKBeT10vmscuB2VCxyv/dy46Tgu7kw/tpYF9HRRJabSrwj auGhc+R83nMrMOXUEmXqQa/wvVsZUHkSmH5F9gK+tiIoA0A2pDE/O7oVer0TS1A1ZEgv 0uvL9TuGPBbY4tY79gzJKuDKBL4FmoznL7o3JDTmwTF2DmbpAgIsoVuUMUSwN8B3MSSn l818sTATQ3QytcML+Vlvuaf5OLen1u9R8dS3rFxMJBpxwm+UcoUb8ttKDThnGMYsWgPO VM2Q== 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=2lHPRv4qX+qjn934MuW0oHQYA3Tg/r5CBkNflSNV2Vw=; b=DCOj7p4Ra7ZDw2kA54RCuO1n31gpctCdvW59g0/VuUOnB5Kk5rxmRbV+LS192nyf4l fUC0FSDljDGNZ7PS6LmrOOMwjMHZpEtIOvp200Bbu20hPHrAUupgEZyPjYNVk2M0BMvt 2nAe+rALHTx4cWZvtJ0nYQWHd+qC80A4o1p5hWoHzJMrBBE706uffxmHO2Pz6ztXRIQc 4LK5bKzp5ZkcieKiiy6kyQhJRiHDR4tJg77ijgpM0oDooZEXEDaBSl0tiUamN1HS0IEE WWoIX0RUYVc6qtxTsME+cq7WaQr69Hsh0qwCGa58VNm3+PnjgKGg2qHvx5csc8XYedaM uY/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=mQiyTApk; 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 j12-20020a50e0cc000000b00418c2b5bdc8si79502edl.170.2022.03.31.09.19.03; Thu, 31 Mar 2022 09:19:31 -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=mQiyTApk; 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 S235469AbiCaMvW (ORCPT + 99 others); Thu, 31 Mar 2022 08:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233225AbiCaMvV (ORCPT ); Thu, 31 Mar 2022 08:51:21 -0400 Received: from out203-205-251-80.mail.qq.com (out203-205-251-80.mail.qq.com [203.205.251.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F579BC5 for ; Thu, 31 Mar 2022 05:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1648730970; bh=2lHPRv4qX+qjn934MuW0oHQYA3Tg/r5CBkNflSNV2Vw=; h=From:To:Cc:Subject:Date; b=mQiyTApkPEyF53TQRUaQ1keFoabC6xBHycCCJhP+RUg30jKHLGdrXnx1AFrfHBm48 oVD5mcU5iSQHLLAHO5l1LAKQiBS+NgVrIc2Ox2hbQQqtvFGsWVLKvbE4fg2v9lOWTW 0/2wlD2DelBiTdfcnw5dYDlvTR8VTHoTI703pcVo= Received: from localhost.localdomain ([218.197.153.188]) by newxmesmtplogicsvrszc6.qq.com (NewEsmtp) with SMTP id C5A80A8D; Thu, 31 Mar 2022 20:49:26 +0800 X-QQ-mid: xmsmtpt1648730966tvlxw2aws Message-ID: X-QQ-XMAILINFO: N7h1OCCDntujBiT1TPLAgTayvup/iQClN36R+hwGF6RJYRMgOEwwR7smGdJ1vl t67cpKX+aiZYJa4kXdpb1/f2hS/M+udrEZky5OhaFFcdv4eL1gMm81K/cDH5UBWgB+kUhjOLEbGt P7HtPw0ocJRA18yRh8GhzIRxZVmVUwDlXsJVv8Qd5fZgZU/4vfOHjXHXr3RrH9KHijBZU7QEZHax 61l6S8YOCJgTZoeCtXasQ7SJSnjKbrVwrqVe++7Gy8AzgE8SC8f62JrbYb6gY0jAKfH+y/DwiHtC cTidpsUFfFdWySkpd8BYUCA7ZdMS4VJ4eZ4gVhFNSl9ZrvQMZrs5LLcLSWxX0n6bzH41XtBkp3nn sCQPMU/Ndi2ecW/esYAZCYfH9Z2jpDrBTT1tVYytrtHn0yuc+SDONaUnUTgeHktTzh6ko2WIJ46m qJ9ivJYQe4OfczhOaiCEc7JJVLvci9TT1UNbvDXRaD8Lqz/u6tigACU88iP1xMUKhbMEBGAU1oVk I1G2x6EJZeNboc7eF2il9E7We4OoQ60O17cBiky7S/JHDRWQTOBcl2tJEXgjdFmBsVauD/dkY4Px xPRShE1n2csmEiG5bMhV0fuXRM6KpB/5LA8KR3CwtPDThaXFODD4scs6pHAXVaSCH+OYiigMf+UV fXlmQ2ZwmBkZK0GpwswiAlPz2MM58cw86V5QGuLmHCiPeCJGHbP1OAeuftEb338yIeUaZ27kNznS AKMR474rmUI/q8/kUYb6r9o/f71PobYvdYg43kI3IiyWuVBYOs9B07ijbou+8Y15QT/C+gSFUYQu xp0Lr6Sr/JoSDoJzNEiXqeEipp7KEhymzdbd4+S2VwTnfwegGXMTDwVhrKg6R9xSPrudAuis5raV jFZLC97usNgnH1iKTeZOrK4fvcfeyYS+m2hPVf4OeD7NoZzBJcAHy+66qHFyMbEjIXtc/a8+Lf4f 2Qn61kavN5wG5sImMZ/w== From: xkernel.wang@foxmail.com To: gregkh@linuxfoundation.org Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() Date: Thu, 31 Mar 2022 20:49:16 +0800 X-OQ-MSGID: <20220331124916.8412-1-xkernel.wang@foxmail.com> 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,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,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 rtw_init_cmd_priv(), if `pcmdpriv->rsp_allocated_buf` is allocated in failure, `pcmdpriv->cmd_allocated_buf` is not properly released. This patch is to free it. Signed-off-by: Xiaoke Wang --- drivers/staging/rtl8723bs/core/rtw_cmd.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c index e574893..9126ea9 100644 --- a/drivers/staging/rtl8723bs/core/rtw_cmd.c +++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c @@ -161,8 +161,6 @@ static struct cmd_hdl wlancmds[] = { int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) { - int res = 0; - init_completion(&pcmdpriv->cmd_queue_comp); init_completion(&pcmdpriv->terminate_cmdthread_comp); @@ -175,18 +173,17 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->cmd_allocated_buf = rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ); - if (!pcmdpriv->cmd_allocated_buf) { - res = -ENOMEM; - goto exit; - } + if (!pcmdpriv->cmd_allocated_buf) + return -ENOMEM; pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ((SIZE_PTR)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ-1)); pcmdpriv->rsp_allocated_buf = rtw_zmalloc(MAX_RSPSZ + 4); if (!pcmdpriv->rsp_allocated_buf) { - res = -ENOMEM; - goto exit; + kfree(pcmdpriv->cmd_allocated_buf); + pcmdpriv->cmd_allocated_buf = NULL; + return -ENOMEM; } pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((SIZE_PTR)(pcmdpriv->rsp_allocated_buf) & 3); @@ -196,8 +193,8 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->rsp_cnt = 0; mutex_init(&pcmdpriv->sctx_mutex); -exit: - return res; + + return 0; } static void c2h_wk_callback(struct work_struct *work); --