Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp103590rdf; Mon, 20 Nov 2023 18:13:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVO2x8mhV0TGByWpN4vPQLU0c33NrnXnOgOMQHf0dHLgpPWuhmWm8eCiEa7SjV91HbKZ3m X-Received: by 2002:a05:6830:922:b0:6cd:a9d:bc57 with SMTP id v34-20020a056830092200b006cd0a9dbc57mr4359106ott.32.1700532782236; Mon, 20 Nov 2023 18:13:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700532782; cv=none; d=google.com; s=arc-20160816; b=Wh5pFyqjjqTSzuVULC7HNL0Qbyxa7IY8YyI0wxprJxbFf1jdSmZjAkEUD35YpoCRMP iyo9r+1yx5pRA5OwedOsb6uWK0HO+3gKcEwydb15c1WHUpM7dKD0Nur8McfKYdm0UK4x dEUsWmyj1Cp7G/KM2wpYEP5K3efcrfgr0/dDcmdaFYMKr5YB9LU6cu7Vd2UjJ7TSwbqI cMPS/GiOqiebRv0/vfhlBVYBw2QPc5/GODUsIoyKZhjiOjJCfMDRVTnTbcdD5RI9dmMV UPst7mDUPfvftOs60xlcsk5kwJqX1D86/TW4TZ8JoHdnjZ1QygBoNdtAkWLxP0fbqgOg JmCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=MgaxRt5/Fd8h/gnYZ64saadyA1lnkhMgwSSIrobY3ms=; fh=cOMsov2h/UE6XcTpm32BKIwR1PM/mYm6owF+PHemhXA=; b=E9xFDn7+O2TpoNPr75v14MT4U5apZ92MQLJufZPhz6JXcLHlpwruMzR5FSyx/EggVg M8/y7733TNMyYGxUjS0zCAJF606SN6mJP02pTwPw+CqMZF5b4DRzr5rddiQ+0pDCbKN1 qUAxQY/uIOrW7jkkmoiIQ63i8Q4CAu1HFphVuQq+9zezser0FFcA/5rkB1kYyyeHEzY1 aytKtsLTaT10KFl6lmg0x9xN9h7vPR6n81VIoT+uhiza4kWZdfGnl4fsxFXyfXIuFwsX 5UY8OWMyBIX+PKd2HfZgf5XRacb7kXQh5c2uLAcVes2yZmW9XeYU/HihABYakiM1YyF2 fmxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id o5-20020a656145000000b00577475ee5f6si8803526pgv.618.2023.11.20.18.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 18:13:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9D1F88041FCE; Mon, 20 Nov 2023 18:12:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229522AbjKUCMn (ORCPT + 99 others); Mon, 20 Nov 2023 21:12:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbjKUCMk (ORCPT ); Mon, 20 Nov 2023 21:12:40 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 633D2C3; Mon, 20 Nov 2023 18:12:34 -0800 (PST) X-UUID: fc53191120304ffab81e76ce8ee56509-20231121 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:1fcb15c5-4542-451d-85f9-59e249b4c6fa,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:1 X-CID-INFO: VERSION:1.1.32,REQID:1fcb15c5-4542-451d-85f9-59e249b4c6fa,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-9,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:1 X-CID-META: VersionHash:5f78ec9,CLOUDID:f5919e95-10ce-4e4b-85c2-c9b5229ff92b,B ulkID:231119230408XYBZ5UP2,BulkQuantity:8,Recheck:0,SF:66|24|17|19|43|74|6 4|102,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:40,QS:nil,BEC:nil, COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: fc53191120304ffab81e76ce8ee56509-20231121 X-User: chentao@kylinos.cn Received: from [172.21.13.26] [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 467459029; Tue, 21 Nov 2023 10:12:19 +0800 Message-ID: <55b77a28-a680-4465-bb57-2a5cb20ce06a@kylinos.cn> Date: Tue, 21 Nov 2023 10:12:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH iwl-next] i40e: Use correct buffer size Content-Language: en-US To: Alexander Lobakin Cc: horms@kernel.org, anthony.l.nguyen@intel.com, davem@davemloft.net, edumazet@google.com, intel-wired-lan@lists.osuosl.org, jeffrey.t.kirsher@intel.com, jesse.brandeburg@intel.com, kuba@kernel.org, kunwu.chan@hotmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, shannon.nelson@amd.com References: <20231113093112.GL705326@kernel.org> <20231115031444.33381-1-chentao@kylinos.cn> <55e07c56-da57-41aa-bc96-e446fad24276@intel.com> <4b551600-f1a3-4efe-b3e9-99cb4536f487@kylinos.cn> <2c61c232-1bbb-4cae-bb7f-92a7f2298e97@intel.com> From: Kunwu Chan In-Reply-To: <2c61c232-1bbb-4cae-bb7f-92a7f2298e97@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 18:12:59 -0800 (PST) Thanks for your reply. I understand what you mean, i.e. the caller of 'kasprintf' is responsible for calling 'kfree' to free up memory. My concern is that in many scenarios, the requested memory will be released after a period of use. Has anyone else forgotten to free up the requested memory when using 'kasprintf'? e.g. 'dam_heap_init' calls 'dma_heap_devnode' to allocate memory: dam_heap_init -> dma_heap_devnode -> kasprintf ->kvasprintf ->kmalloc_node_track_caller -> __kmalloc_node_track_caller -> __do_kmalloc_node -> kasan_kmalloc There is no function like 'dam_heap_exit' to free the memmory allocated by dma_heap_devnode. Another case is 'cpuid_devnode'. Will this cause a memory leak, and is there a better way to avoid the memory leak in this case? Or is there a uniform place in the memory management module to free up this memory? Thanks, Kunwu On 2023/11/20 19:41, Alexander Lobakin wrote: > From: Kunwu Chan > Date: Sun, 19 Nov 2023 23:12:09 +0800 > >> Hi Alexander, >> Thank you so much for your reply, I looked at the modification you >> mentioned, it's really cool. I'll definitely try it next time. >> >> But when using it, will it be easy to forget to free up memory? > > You have a kfree() at the end of the function. > > Generally speaking, 'ka' stands for "[kernel] allocate" and you also > need to pass GPF_ as the second argument. Enough hints that you need to > free the pointer after using it I would say. > >> Although 'kmalloc_track_caller' is used, according to my understanding, >> it is also necessary to release the memory at the end of use. >> >> On 2023/11/15 23:39, Alexander Lobakin wrote: >>> From: Kunwu Chan >>> Date: Wed, 15 Nov 2023 11:14:44 +0800 >>> >>>> The size of "i40e_dbg_command_buf" is 256, the size of "name" >>>> depends on "IFNAMSIZ", plus a null character and format size, >>>> the total size is more than 256, fix it. >>>> >>>> Signed-off-by: Kunwu Chan >>>> Suggested-by: Simon Horman >>>> --- >>>>   drivers/net/ethernet/intel/i40e/i40e_debugfs.c | 2 +- >>>>   1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c >>>> b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c >>>> index 999c9708def5..e3b939c67cfe 100644 >>>> --- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c >>>> +++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c >>>> @@ -72,7 +72,7 @@ static ssize_t i40e_dbg_command_read(struct file >>>> *filp, char __user *buffer, >>>>   { >>>>       struct i40e_pf *pf = filp->private_data; >>>>       int bytes_not_copied; >>>> -    int buf_size = 256; >>>> +    int buf_size = IFNAMSIZ + sizeof(i40e_dbg_command_buf) + 4; >>> >>> Reverse Christmas Tree style? Should be the first one in the declaration >>> list. >>> >>>>       char *buf; >>>>       int len; >>> >>> You can fix it in a different way. Given that there's a kzalloc() either >>> way, why not allocate the precise required amount of bytes by using >>> kasprintf() instead of kzalloc() + snprintf()? You wouldn't need to >>> calculate any buffer sizes etc. this way. >>> >>> Thanks, >>> Olek > > Thanks, > Olek