From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Cezary Rojewski <cezary.rojewski@intel.com>
Cc: rafael@kernel.org, linux-acpi@vger.kernel.org,
robert.moore@intel.com, pierre-louis.bossart@linux.intel.com,
amadeuszx.slawinski@linux.intel.com
Subject: Re: [PATCH 4/4] ACPI: NHLT: Add query functions
Date: Mon, 17 Jul 2023 12:47:58 +0300 [thread overview]
Message-ID: <ZLUOTiLGE4NFAdnD@smile.fi.intel.com> (raw)
In-Reply-To: <3544e8dd-874e-4b26-cb37-04aad2a8332a@intel.com>
On Mon, Jul 17, 2023 at 10:29:17AM +0200, Cezary Rojewski wrote:
> On 2023-07-12 5:48 PM, Andy Shevchenko wrote:
> > On Wed, Jul 12, 2023 at 11:10:48AM +0200, Cezary Rojewski wrote:
...
> > > + return ep &&
> > > + (link_type < 0 || ep->link_type == link_type) &&
> > > + (dev_type < 0 || ep->device_type == dev_type) &&
> > > + (dir < 0 || ep->direction == dir) &&
> > > + (bus_id < 0 || ep->virtual_bus_id == bus_id);
> >
> > I think you can split these for better reading.
> >
> > if (!ep)
> > return false;
> >
> > if (link_type >= 0 && ep->link_type != link_type)
> > return false;
> >
> > if (dev_type >= 0 && ep->device_type != dev_type)
> > return false;
> >
> > if (dir >= 0 && ep->direction != dir)
> > return false;
> >
> > if (bus_id >= 0 && ep->virtual_bus_id != bus_id)
> > return false;
> >
> > return true;
> >
> > Yes, much more lines, but readability is better in my opinion.
> > I also believe that code generation on x86_64 will be the same.
>
> While I favor readability over less lines of code, I do not think splitting
> the conditions makes it easier in this case. Perhaps reverse-christmas-tree?
> Pivoted around '<'.
>
> return ep &&
> (link_type < 0 || ep->link_type == link_type) &&
> (dev_type < 0 || ep->device_type == dev_type) &&
> (bus_id < 0 || ep->virtual_bus_id == bus_id) &&
> (dir < 0 || ep->direction == dir);
This one definitely better.
> In general I'd like to distinguish between conditions that one _has to_ read
> and understand and those which reader _may_ pass by. Here, we are checking
> description of an endpoint for equality. Nothing more, nothing less.
...
> > > +struct acpi_nhlt_endpoint *
> > > +acpi_nhlt_find_endpoint(const struct acpi_table_nhlt *tb,
> > > + int link_type, int dev_type, int dir, int bus_id)
> > > +{
> > > + struct acpi_nhlt_endpoint *ep;
> >
> > > + if (!tb)
> > > + return ERR_PTR(-EINVAL);
> >
> > Just wondering how often we will have a caller that supplies NULL for tb.
>
> Depends on kernel's philosophy on public API. In general, public API should
> defend themselves from harmful and illegal callers. However, in low level
> areas 'illegal' is sometimes mistaken with illogical. In such cases double
> safety can be dropped.
What do you put under "public"? ABI? Or just internally available API?
If the latter, we don't do defensive programming there, we usually just
add NULL(invalid data)-awareness to the free()-like functions.
> Or, perhaps you were discussing return value here and ERR_PTR(-EINVAL) could
> be replaced by something else or even NULL.
I prefer to get rid of those.
> > > + for_each_nhlt_endpoint(tb, ep)
> > > + if (acpi_nhlt_endpoint_match(ep, link_type, dev_type, dir, bus_id))
> > > + return ep;
> > > + return NULL;
> > > +}
...
> > > + if (wav->channel_count == ch &&
> > > + wav->valid_bits_per_sample == vbps &&
> > > + wav->bits_per_sample == bps &&
> > > + wav->samples_per_sec == rate)
> >
> > Also can be split, but this one readable in the original form.
>
> As order does not really matter here, perhaps reverse-christmas-tree to
> improve readability?
>
> if (wav->valid_bits_per_sample == vpbs &&
> wav->samples_per_sec == rate &&
> wav->bits_per_sample == bps &&
> wav->channel_count == ch)
OK!
> > > + return fmt;
...
> > > + default:
> >
> > > + pr_warn("undefined mic array type: %#x\n", devcfg->array_type);
> >
> > Is this function can ever be called without backing device? If not,
> > I would supply (ACPI?) device pointer and use dev_warn() instead.
> >
> > But I'm not sure about this. Up to you, folks.
>
> Given what's our there in the market I wouldn't say it's impossible to
> encounter such scenario. Could you elaborate on what you meant by "supply
> device pointer"?
In the caller (assuming it has ACPI device):
ret = acpi_nhlt_endpoint_dmic_count(adev, ep);
if (ret < 0)
...
> > > + return max_ch;
> > > + }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-07-17 9:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-12 9:10 [PATCH 0/4] ACPI: NHLT: Access and query helpers Cezary Rojewski
2023-07-12 9:10 ` [PATCH 1/4] ACPI: NHLT: Device configuration access interface Cezary Rojewski
2023-07-12 9:10 ` [PATCH 2/4] ACPI: NHLT: Introduce acpi_gbl_NHLT Cezary Rojewski
2023-07-12 9:10 ` [PATCH 3/4] ACPI: NHLT: Table manipulation helpers Cezary Rojewski
2023-07-12 15:36 ` Andy Shevchenko
2023-07-17 8:08 ` Cezary Rojewski
2023-07-12 9:10 ` [PATCH 4/4] ACPI: NHLT: Add query functions Cezary Rojewski
2023-07-12 15:48 ` Andy Shevchenko
2023-07-17 8:29 ` Cezary Rojewski
2023-07-17 9:47 ` Andy Shevchenko [this message]
2023-07-17 11:25 ` Cezary Rojewski
2023-07-18 11:11 ` Cezary Rojewski
2023-07-18 14:17 ` Andy Shevchenko
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=ZLUOTiLGE4NFAdnD@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=cezary.rojewski@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=rafael@kernel.org \
--cc=robert.moore@intel.com \
/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