lkml.org 
[lkml]   [2021]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v1 1/2] ACPI: scan: Rearrange memory allocation in acpi_device_add()
From
Date
Hi,

On 1/18/21 4:32 PM, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 04:16:16PM +0100, Rafael J. Wysocki wrote:
>> On Sat, Jan 16, 2021 at 1:37 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>> On 1/14/21 7:46 PM, Rafael J. Wysocki wrote:
>
> ...
>
>>> When I have cases like this, where 2 mallocs are necessary I typically do it like this:
>>>
>>> const char *bus_id;
>>>
>>> ...
>>>
>>> } else {
>>> acpi_device_bus_id = kzalloc(sizeof(*acpi_device_bus_id),
>>> GFP_KERNEL);
>>> bus_id = kstrdup_const(acpi_device_hid(device), GFP_KERNEL);
>>> if (!acpi_device_bus_id || !bus_id) {
>>> kfree(acpi_device_bus_id);
>
>
>>> kfree(bus_id);
>
> Just to be sure, shouldn't it be kfree_const() ?

Yes I beleive it should, my bad.

Regards,

Hans


>
>>> result = -ENOMEM;
>>> goto err_unlock;
>>> }
>>> acpi_device_bus_id->bus_id = bus_id;
>>> list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
>>> }
>>>
>>> ...
>>>
>>> So that there is only one if / 1 error-handling path for both mallocs.
>>> I personally find this a bit cleaner.
>

\
 
 \ /
  Last update: 2021-01-18 16:41    [W:1.354 / U:0.248 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site