Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2443078pxb; Sun, 17 Apr 2022 23:23:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV/+BO+dpGp7/DdrgyVJnaDTwWs9Qi6AV+8J5kjh2NAJMn5Wzm64YFlHGaIPljehTeXhbl X-Received: by 2002:a63:7888:0:b0:398:91:7b5e with SMTP id t130-20020a637888000000b0039800917b5emr8996332pgc.212.1650263032107; Sun, 17 Apr 2022 23:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650263032; cv=none; d=google.com; s=arc-20160816; b=UyKekYi5a+kMPqWA5Jo2mHn/lkUaQfXZ8GfyBbQQmD0nvMXNKfmm5nZ5mr7UqRtA1o 5DcpaIBDAttN8+szv60Trs0g62Gf144wfPzh6oOmzFzamWD3KEoP4Xb1qcV9ycZak1z0 3Z4LgKS2fmfLn4AaGqkjJnIteZBnVLP4TNkVxMg4J4yQcRSY8oaQyCHCUgyoJBC8GUDj fnu0VGPrr5xpYU5d1BUlkJcsdh2ba1KVP7xLucaw6OlGMgJJfKei/uTyRQEWz8SdWKkq 5JAOg2lcX+Hu0jq6fcYcre3ZAOqE7pYu9PxshigHUroqcchoPGXU2c+t1+zH9M4bmip6 CbTA== 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:message-id:date:subject:cc:to:from :dkim-signature; bh=HtwSwKHxvQg2zlm6kaPIkHmv4vJJ4TgMpLArTx9nMTk=; b=bnEEyR1lygXgRSig+tmD2iuJ+tslbkrcgL0QTp6H3aodWigq/ZsId9Dos2oqZr0PRA w7YtFUcg5xK05pXJjSNetEZHv68el9jfMWHQE87K7TE3x+dP+/qdF/VpLMO/sbzT9ExZ pZna5Z9y2RWv/B//2Hcz31DZdk71v393/9yPxpfMP0jyMtYiW5jZkByjsOC9rBwewvK4 kSx2IiKxuR3tGfH+FNRgWAKgsQnqCOodJv/WE3xgexjkDXIMTeTWv4qv+3Wea5TtyFjd hyPbTs2jirUiHpiUzYbXlF9rQsbCB2VxRfWT/dxH2xW+Of3I5+RHNqztFIG+ff/jgFu/ MUbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=N+ftmGGk; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a635449000000b0039da598e9b1si8134370pgm.66.2022.04.17.23.23.38; Sun, 17 Apr 2022 23:23:52 -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=@gmail.com header.s=20210112 header.b=N+ftmGGk; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235117AbiDQWDp (ORCPT + 99 others); Sun, 17 Apr 2022 18:03:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232635AbiDQWDm (ORCPT ); Sun, 17 Apr 2022 18:03:42 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B85A6634C for ; Sun, 17 Apr 2022 15:01:05 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id i27so24055252ejd.9 for ; Sun, 17 Apr 2022 15:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HtwSwKHxvQg2zlm6kaPIkHmv4vJJ4TgMpLArTx9nMTk=; b=N+ftmGGkeBsUXnMkxCA7AVVmpWQRA+37MSw9ui2XtKchj9xLlk9Ue/kT1eDK7IP+tn mOKzprMirSfavzuBIp7Tg0Whdnv5cD9R/O5k+XdmdMm50r4rfufypffv65bqiN9QkSt4 prXrbeNdBaHLDLFY8N3eHvHLh7fPSZ8jI2+AZvfAPr+ipEiQM8HVqjiX/FH9mbmzUIXr P1578CZhRcRELAmfZxxYAoz6T68uat1uVtDkLSF1bhRki1Z6IBns0FSbZa36KZf875k+ czM7S8qVbpyuUl7+e5fbHD4gZq3EsHbT6n0FMAXGYvEaslunVuWOBHNZIqUSEk/Pivp6 YJWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HtwSwKHxvQg2zlm6kaPIkHmv4vJJ4TgMpLArTx9nMTk=; b=t2o061ioTB0FohTorGr5oTJ1deD4PzaatxPdjEOTfsVSVcCG0i10vbH6IBASQ5ncy3 QetbWBosmVBmaOmG9cT75JRrA4tCZMip8VL9BSPkhRZB55h0cLOnleydMFfu7mnRXCQd np75bMWBHMMQ0FpWihquI9g/TJtITjc63gNOUWqKn6+q7/dXuW7MxzFpQpGa4FOjNZ6R +7Ut03JLIF1uSQkBQ9WZdoutFuiHNH3RGZPFG+wZUUzDC4nIWD/q8khyBmFjHUJxjmwe 2ywDMDDAVT8KIAj1XVuggwj7MHos1to3zOh1j1U3phDR3hzstjo17InGeD66n+q27tK/ MXGQ== X-Gm-Message-State: AOAM530dZRUAms2KxPDQUtws/L7xA4KT7c2qIRmNicIb3M4srmtbVa46 opvYWWdrsUJF9ThS5+O35A4= X-Received: by 2002:a17:906:974c:b0:6e8:9453:4209 with SMTP id o12-20020a170906974c00b006e894534209mr6993992ejy.755.1650232864313; Sun, 17 Apr 2022 15:01:04 -0700 (PDT) Received: from leap.localnet (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id k14-20020a170906128e00b006e4b67514a1sm3996407ejb.179.2022.04.17.15.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Apr 2022 15:01:02 -0700 (PDT) From: "Fabio M. De Francesco" To: Pavel Skripkin , Jaehee Park Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk, gregkh@linuxfoundation.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, outreachy@lists.linux.dev Subject: Re: [PATCH v2 1/6] staging: r8188eu: remove unused member free_bss_buf Date: Mon, 18 Apr 2022 00:01:00 +0200 Message-ID: <4396697.LvFx2qVVIh@leap> In-Reply-To: <3164900.aeNJFYEL58@leap> References: <20220417204200.GA236965@jaehee-ThinkPad-X1-Extreme> <3164900.aeNJFYEL58@leap> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 On domenica 17 aprile 2022 23:13:50 CEST Fabio M. De Francesco wrote: > On domenica 17 aprile 2022 22:42:00 CEST Jaehee Park wrote: > > On Sun, Apr 17, 2022 at 11:16:38PM +0300, Pavel Skripkin wrote: > > > Hi Jaehee, > > > > > > On 4/17/22 23:14, Jaehee Park wrote: > > > > My understanding of Pavel's response is the free_bss_buf member of > the > > > > pmlmepriv structure wasn't being used anywhere and that the > > > > rtw_free_mlme_riv_ie_data function frees the memory of the pmlmepriv > > > > structure so the second check is redundant. > > > > > > > > However, as Fabio said, the free_bss_buf member is being used and > pbuf > > > > memory is not being freed. > > > > So I'll revert the patch as it was originally (which was just > removing > > > > the {} around the single if statement). > > No, Jaehee. This is not what I said :) > > > > > > > > > > > Why just `pbuf` allocation can't be removed? This memory is just > unused, > > > isn't it? > > What Pavel said is what I said, but using a different argumentation. > > > > > > > > > > With regards, > > > Pavel Skripkin > > > > > > The free_bss_buf member is unused. > > Correct. > > > So it can just be removed right? > > No. > > > > I guess I'm confused by what Pablo is saying about causing a memory > > leak > > A memory leak is caused when you allocate some memory and then you lose any > reference to its address so that it cannot be freed. Right? > > > by getting rid of the pointer to the memory allocated by pbuf. > > No. > > > Sorry if I misunderstood. > > No problem. Let's rewind... > > "pbuf" is assigned with the address of some memory allocated with a call to > vzalloc(). Since "pbuf" is a local variable, you see that the above- > mentioned address is stored in free_bss_buf using the line "pmlmepriv- > >free_bss_buf = pbuf". Is it clear? > > Well, you decided to delete the line that calls vfree(pmlmepriv- > >free_bss_buf). At this point you have that memory leak. > > Pavel noted that pmlmepriv->free_bss_buf is unused, but it contains the > address of a region of memory that was allocated for no purpose. > > Therefore, a correct patch should also remove the allocation that was made > using kzalloc(). Sorry I made a typo: kzalloc() -> vzalloc(). > If you merely remove the line with vfree() you cause a > memory leak. > > Please don't revert your patch. Just fix it with a new version that also > delete the line where "pbuf" is assigned with the value returned by > kzalloc(). Same here: kzalloc() -> vzalloc(). > > I hope that now I've been clearer. Did you find out where is the line that calls vzalloc() and returns the address to the local variable called "ptr"? As, said before. You should delete it too, otherwise you lose that region of memory until the driver is un-linked by "modprobe -r " or the system is shutdown. Fabio