public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v1 1/1] treewide: Align match_string() with sysfs_match_string()
Date: Tue, 4 Jun 2024 19:36:22 +0300	[thread overview]
Message-ID: <Zl9ChheV8lS8_DUd@smile.fi.intel.com> (raw)
In-Reply-To: <20240604115235.044acfd6@gandalf.local.home>

On Tue, Jun 04, 2024 at 11:52:35AM -0400, Steven Rostedt wrote:
> On Tue, 04 Jun 2024 10:45:37 +0300
> Jani Nikula <jani.nikula@linux.intel.com> wrote:
> 
> > On Sun, 02 Jun 2024, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > > Make two APIs look similar. Hence convert match_string() to be
> > > a 2-argument macro. In order to avoid unneeded churn, convert
> > > all users as well. There is no functional change intended.  
> > 
> > Why do we think it's a good idea to increase and normalize the use of
> > double-underscore function names across the kernel, like
> > __match_string() in this case? It should mean "reserved for the
> > implementation, not to be called directly".
> > 
> > If it's to be used directly, it should be named accordingly, right?
> > 
> > Being in line with __sysfs_match_string() isn't a great argument alone,
> > because this adds three times the number of __match_string() calls than
> > there are __sysfs_match_string() calls. It's not a good model to follow.
> > Arguably both should be renamed.
> 
> Agreed. I want to get rid of any functions starting with an underscore
> except for those that are basically the same function used internally for
> convenience.
> 
> Perhaps "match_string_dynamic()"? Where it is used for dynamically
> allocated arrays without known size. Or, allow a third parameter for
> dynamic arrays.
> 
> #define match_string(_a, _s, ...)
> 	char _______STR[] = __stringify((__VA_ARGS__));	\
> 	if (sizeof(_______STR) > 3)			\
> 		__match_string(_a, _s, ##__VA_ARGS__);  \
> 	else						\
> 		__match_string(_a, _s, ARRAY_SIZE(_a));
> 
> What the above stringify((__VA_ARGS__)) does is to check the size of any
> args added to match_string(). if there isn't any, it will turn into:
> "()\0", which is of size 3. If you add an argument, it will be:
> "(<arg>)\0", which will have a size greater than three.

We have args.h for such tricks.

> (trace_printk() does this trick in include/linux/kernel.h).
> 
> This way, both:
> 
>  match_string(array, sting);
> 
> or
> 
>  match_string(array, string, size);
> 
> will work.

But Linus already gave a few good advice including the name. I don't wont to
switch to this magic for match_string() as it's fine to have a simple macro.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2024-06-04 16:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-02 15:57 [PATCH v1 1/1] treewide: Align match_string() with sysfs_match_string() Andy Shevchenko
2024-06-03 22:00 ` Bjorn Helgaas
2024-06-03 22:06 ` Linus Torvalds
2024-06-04  1:29 ` Damien Le Moal
2024-06-04  1:37 ` Zhihao Cheng
2024-06-04  6:42 ` Daniel Bristot de Oliveira
2024-06-04  7:25 ` Heiko Stübner
2024-06-04  7:45 ` Jani Nikula
2024-06-04 15:52   ` Steven Rostedt
2024-06-04 16:36     ` Andy Shevchenko [this message]
2024-06-10  8:08   ` Linus Walleij
2024-06-11 21:38     ` Yury Norov
2024-06-11 23:48       ` Linus Torvalds
2024-06-04  7:55 ` Vinod Koul
2024-06-04  7:55 ` Wolfram Sang
2024-06-04  8:23 ` Sakari Ailus
2024-06-04  8:28 ` Hans de Goede
2024-06-04 13:41 ` Andi Shyti
2024-06-04 18:25 ` Rodrigo Vivi
2024-06-04 18:42   ` Linus Torvalds
2024-06-05  4:28 ` Gautham R. Shenoy
2024-06-05 11:17 ` AngeloGioacchino Del Regno

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=Zl9ChheV8lS8_DUd@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox