[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f7441bb4-c2c9-4eee-9fed-ad8b28de4788@intel.com>
Date: Fri, 13 Oct 2023 19:00:37 +0200
From: "Wilczynski, Michal" <michal.wilczynski@...el.com>
To: Dan Williams <dan.j.williams@...el.com>, <nvdimm@...ts.linux.dev>,
<linux-acpi@...r.kernel.org>
CC: <rafael@...nel.org>, <vishal.l.verma@...el.com>, <lenb@...nel.org>,
<dave.jiang@...el.com>, <ira.weiny@...el.com>,
<linux-kernel@...r.kernel.org>,
Andy Shevchenko <andy.shevchenko@...il.com>
Subject: Re: [PATCH v2] ACPI: NFIT: Fix local use of devm_*()
On 10/13/2023 6:38 PM, Dan Williams wrote:
> Michal Wilczynski wrote:
>> devm_*() family of functions purpose is managing memory attached to a
>> device. So in general it should only be used for allocations that should
>> last for the whole lifecycle of the device.
> No, this assertion is not accurate, if it were strictly true then
> devm_kfree() should be deleted. This patch is only a cleanup to switch
> the automatic cleanup pattern from devm to the new cleanup.h helpers.
The memory in question is only used locally in a function, so there is no reason
to use devm_*() family of functions. I think devm_kfree() is more for special
cases where the memory is meant to be used for the whole lifecycle of device,
but some special case occurs and it's not and it needs to be freed.
This is an incorrect API usage. Would you propose to change all memory
allocations currently being done to devm_*() family simply because devm_kfree()
exists ? Why introduce extra overhead if you don't have to ?
>
> I am all for modernizing code over time, but patches that make
> assertions of "memory leaks" and "incorrect API usage" in code that has
> been untouched for almost a decade demand more scrutiny than what
> transpired here.
I understand that it's not necessarily a big problem, and the code works
perfectly, I can change the phrasing if you don't like it, but still the
cleanup.h helpers don't really care that much what functions they call
to allocate/free. They are meant to care about the scope - like constructor
destructor in C++ - you can call anything there.
So this commit changes 2 things:
- change family of function to allocate from
devm_kcalloc() to kcalloc()
- use scope based mechanism to call those functions
Thanks a lot for your review !
Michał
Powered by blists - more mailing lists