lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zl9ChheV8lS8_DUd@smile.fi.intel.com>
Date: Tue, 4 Jun 2024 19:36:22 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: Jani Nikula <jani.nikula@...ux.intel.com>, linux-kernel@...r.kernel.org,
	Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: [PATCH v1 1/1] treewide: Align match_string() with
 sysfs_match_string()

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@...ux.intel.com> wrote:
> 
> > On Sun, 02 Jun 2024, Andy Shevchenko <andriy.shevchenko@...ux.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



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ