[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZJW4MdIvrWjbKtVy@alley>
Date: Fri, 23 Jun 2023 17:20:17 +0200
From: Petr Mladek <pmladek@...e.com>
To: Joel Granados <j.granados@...sung.com>
Cc: Jiri Slaby <jirislaby@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
mcgrof@...nel.org, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
Theodore Ts'o <tytso@....edu>,
"Jason A. Donenfeld" <Jason@...c4.com>,
Juergen Gross <jgross@...e.com>,
Stefano Stabellini <sstabellini@...nel.org>,
Benjamin LaHaise <bcrl@...ck.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>,
Jeff Layton <jlayton@...nel.org>,
Chuck Lever <chuck.lever@...cle.com>, Jan Kara <jack@...e.cz>,
Kees Cook <keescook@...omium.org>,
Iurii Zaikin <yzaikin@...gle.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Balbir Singh <bsingharora@...il.com>,
Eric Biederman <ebiederm@...ssion.com>,
"Naveen N. Rao" <naveen.n.rao@...ux.ibm.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@...el.com>,
"David S. Miller" <davem@...emloft.net>,
Masami Hiramatsu <mhiramat@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Will Deacon <will@...nel.org>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Steven Rostedt <rostedt@...dmis.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Mike Kravetz <mike.kravetz@...cle.com>,
Muchun Song <muchun.song@...ux.dev>,
Naoya Horiguchi <naoya.horiguchi@....com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
David Howells <dhowells@...hat.com>,
Jarkko Sakkinen <jarkko@...nel.org>,
Paul Moore <paul@...l-moore.com>,
James Morris <jmorris@...ei.org>,
"Serge E. Hallyn" <serge@...lyn.com>,
"H. Peter Anvin" <hpa@...or.com>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@...m.com>,
Amir Goldstein <amir73il@...il.com>,
John Fastabend <john.fastabend@...il.com>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...gle.com>,
Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
Waiman Long <longman@...hat.com>,
Boqun Feng <boqun.feng@...il.com>,
John Ogness <john.ogness@...utronix.de>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Ben Segall <bsegall@...gle.com>, Mel Gorman <mgorman@...e.de>,
Daniel Bristot de Oliveira <bristot@...hat.com>,
Valentin Schneider <vschneid@...hat.com>,
Andy Lutomirski <luto@...capital.net>,
Will Drewry <wad@...omium.org>,
Mark Rutland <mark.rutland@....com>,
Miaohe Lin <linmiaohe@...wei.com>,
linux-kernel@...r.kernel.org, xen-devel@...ts.xenproject.org,
linux-aio@...ck.org, linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org, bpf@...r.kernel.org, kexec@...ts.infradead.org,
linux-trace-kernel@...r.kernel.org, keyrings@...r.kernel.org,
linux-security-module@...r.kernel.org
Subject: Re: [PATCH 08/11] sysctl: Add size to register_sysctl_init
On Thu 2023-06-22 16:00:21, Joel Granados wrote:
> On Thu, Jun 22, 2023 at 06:21:48AM +0200, Jiri Slaby wrote:
> > On 21. 06. 23, 15:15, Joel Granados wrote:
> > > On Wed, Jun 21, 2023 at 12:47:58PM +0200, Greg Kroah-Hartman wrote:
> > > > On Wed, Jun 21, 2023 at 11:09:57AM +0200, Joel Granados wrote:
> > > > > static int __init random_sysctls_init(void)
> > > > > {
> > > > > - register_sysctl_init("kernel/random", random_table);
> > > > > + register_sysctl_init("kernel/random", random_table,
> > > > > + ARRAY_SIZE(random_table));
> > > >
> > > > As mentioned before, why not just do:
> > > >
> > > > #define register_sysctl_init(string, table) \
> > > > __register_sysctl_init(string, table, ARRAY_SIZE(table);
> > > Answered you in the original mail where you suggested it.
> >
> > I am curious what that was, do you have a link?
> of course. I think you will find it here https://lore.kernel.org/all/20230621123816.ufqbob6qthz4hujx@localhost/
Let me to copy the answer here:
<paste>
I considered this at the outset, but it will not work with callers that
use a pointer instead of the actual array.
Additionally, we would not avoid big commits as we would have to go
looking in all the files where register is called directly or indirectly
and make sure the logic is sound.
</paste>
For the callers using a pointer. A solution would be to create another
wrapper which would take the array size, e.g.
#define register_sysctl_init_limited(string, table, size) \
__register_sysctl_init(string, table, size);
And ARRAY_SIZE() is defined in include/linux/kernel.h as:
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
It will create a compiler error when either an array[] or *array is
passed.
When using this:
1. The compiler will tell us where the other wrapper is needed.
2. Some locations might need the @size parameter even when a static
array is passed. For example, neigh_sysctl_register() terminates
the array early.
But this will work when __register_sysctl_init() supports
both ways.I mean that it will stop either on @size or empty
element, as discussed in the other subthread.
This should be caught when the final "empty" is removed
from the particular caller.
Best Regards,
Petr
Powered by blists - more mailing lists