public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 1/2] ACPI: scan: Rearrange memory allocation in acpi_device_add()
Date: Mon, 18 Jan 2021 17:32:18 +0200	[thread overview]
Message-ID: <20210118153218.GX4077@smile.fi.intel.com> (raw)
In-Reply-To: <CAJZ5v0hv2FX2wtuwu9Jd1zZiGut9kUzQvCH5vXLMyFpqvvYOkA@mail.gmail.com>

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() ?

> >                         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.

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2021-01-18 15:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-14 18:45 [PATCH v1 0/2] ACPI: scan: Janitorial changes in acpi_device_add() Rafael J. Wysocki
2021-01-14 18:46 ` [PATCH v1 1/2] ACPI: scan: Rearrange memory allocation " Rafael J. Wysocki
2021-01-16 12:35   ` Hans de Goede
2021-01-18 15:16     ` Rafael J. Wysocki
2021-01-18 15:26       ` Hans de Goede
2021-01-18 15:32       ` Andy Shevchenko [this message]
2021-01-18 15:34         ` Hans de Goede
2021-01-14 18:47 ` [PATCH v1 2/2] ACPI: scan: Adjust white space " Rafael J. Wysocki
2021-01-16 12:36   ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210118153218.GX4077@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox