All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Hans de Goede <hdegoede@redhat.com>
Subject: Re: [PATCH v1 1/1] Input: icn8505 - Utilize acpi_get_subsystem_id()
Date: Tue, 6 Sep 2022 12:01:37 -0700	[thread overview]
Message-ID: <YxeZEWAYUDWQbVQ8@google.com> (raw)
In-Reply-To: <YxdC7i9F1ayR5icS@smile.fi.intel.com>

On Tue, Sep 06, 2022 at 03:54:06PM +0300, Andy Shevchenko wrote:
> On Mon, Sep 05, 2022 at 12:35:42PM -0700, Dmitry Torokhov wrote:
> > On Mon, Sep 05, 2022 at 08:20:01PM +0300, Andy Shevchenko wrote:
> 
> ...
> 
> > > +	subsys = acpi_get_subsystem_id(ACPI_HANDLE(dev));
> > > +	if (IS_ERR(subsys) && PTR_ERR(subsys) != -ENODATA)
> > > +		return PTR_ERR(subsys);
> > > +
> > > +	if (IS_ERR(subsys) && PTR_ERR(subsys) == -ENODATA)
> > > +		subsys = kstrdup_const("unknown", GFP_KERNEL);
> > 
> > Do we really need kstrdup_const() here? This makes me wonder if we need
> > to also have error handling here, and if we going to tip some automated
> > tools by not having it. Why can't we simply assign the constant here
> > (and continue using kfree_const() below)?
> 
> Which makes code inconsistent. But okay, no big deal.

To me the *_const() APIs are needed when the code does not really know
if it deals with a const/read-only object or not. If we know for sure we
are dealing with a const/read-only object, we can skip allocation and
freeing, so I do not see any inconsistencies.

> 
> > I think this is the case where PTR_ERR_OR_ZERO() might help avoid
> > multiple IS_ERR/PTR_ERR:
> > 
> > 	subsys = acpi_get_subsystem_id(ACPI_HANDLE(dev));
> > 	error = PTR_ERR_OR_ZERO(subsys);
> > 	if (error == -ENODATA)
> > 		subsys = "unknown";
> > 	else if (error)
> > 		return error;
> 
> Would it matter? The generated code will be the same in both cases, no?

No, in the end I think the optimizer will reduce both variants to the
same thing. I do find mine a bit more compact and thus easier to read,
but I will not insist.

Thanks.

-- 
Dmitry

      reply	other threads:[~2022-09-06 19:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 17:20 [PATCH v1 1/1] Input: icn8505 - Utilize acpi_get_subsystem_id() Andy Shevchenko
2022-09-05 19:35 ` Dmitry Torokhov
2022-09-06 12:54   ` Andy Shevchenko
2022-09-06 19:01     ` Dmitry Torokhov [this message]

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=YxeZEWAYUDWQbVQ8@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.