[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 08/11] sysctl: Add size to register_sysctl_init
- To: Joel Granados <j.granados@xxxxxxxxxxx>
- From: Petr Mladek <pmladek@xxxxxxxx>
- Date: Fri, 23 Jun 2023 17:20:17 +0200
- Cc: Jiri Slaby <jirislaby@xxxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, mcgrof@xxxxxxxxxx, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, x86@xxxxxxxxxx, Theodore Ts'o <tytso@xxxxxxx>, "Jason A. Donenfeld" <Jason@xxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Benjamin LaHaise <bcrl@xxxxxxxxx>, Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>, Christian Brauner <brauner@xxxxxxxxxx>, Jeff Layton <jlayton@xxxxxxxxxx>, Chuck Lever <chuck.lever@xxxxxxxxxx>, Jan Kara <jack@xxxxxxx>, Kees Cook <keescook@xxxxxxxxxxxx>, Iurii Zaikin <yzaikin@xxxxxxxxxx>, Alexei Starovoitov <ast@xxxxxxxxxx>, Daniel Borkmann <daniel@xxxxxxxxxxxxx>, Andrii Nakryiko <andrii@xxxxxxxxxx>, Balbir Singh <bsingharora@xxxxxxxxx>, Eric Biederman <ebiederm@xxxxxxxxxxxx>, "Naveen N. Rao" <naveen.n.rao@xxxxxxxxxxxxx>, Anil S Keshavamurthy <anil.s.keshavamurthy@xxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxxxxx>, Masami Hiramatsu <mhiramat@xxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>, Juri Lelli <juri.lelli@xxxxxxxxxx>, Vincent Guittot <vincent.guittot@xxxxxxxxxx>, Steven Rostedt <rostedt@xxxxxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Mike Kravetz <mike.kravetz@xxxxxxxxxx>, Muchun Song <muchun.song@xxxxxxxxx>, Naoya Horiguchi <naoya.horiguchi@xxxxxxx>, "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>, David Howells <dhowells@xxxxxxxxxx>, Jarkko Sakkinen <jarkko@xxxxxxxxxx>, Paul Moore <paul@xxxxxxxxxxxxxx>, James Morris <jmorris@xxxxxxxxx>, "Serge E. Hallyn" <serge@xxxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Amir Goldstein <amir73il@xxxxxxxxx>, John Fastabend <john.fastabend@xxxxxxxxx>, Martin KaFai Lau <martin.lau@xxxxxxxxx>, Song Liu <song@xxxxxxxxxx>, Yonghong Song <yhs@xxxxxx>, KP Singh <kpsingh@xxxxxxxxxx>, Stanislav Fomichev <sdf@xxxxxxxxxx>, Hao Luo <haoluo@xxxxxxxxxx>, Jiri Olsa <jolsa@xxxxxxxxxx>, Waiman Long <longman@xxxxxxxxxx>, Boqun Feng <boqun.feng@xxxxxxxxx>, John Ogness <john.ogness@xxxxxxxxxxxxx>, Dietmar Eggemann <dietmar.eggemann@xxxxxxx>, Ben Segall <bsegall@xxxxxxxxxx>, Mel Gorman <mgorman@xxxxxxx>, Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>, Valentin Schneider <vschneid@xxxxxxxxxx>, Andy Lutomirski <luto@xxxxxxxxxxxxxx>, Will Drewry <wad@xxxxxxxxxxxx>, Mark Rutland <mark.rutland@xxxxxxx>, Miaohe Lin <linmiaohe@xxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-aio@xxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx, bpf@xxxxxxxxxxxxxxx, kexec@xxxxxxxxxxxxxxxxxxx, linux-trace-kernel@xxxxxxxxxxxxxxx, keyrings@xxxxxxxxxxxxxxx, linux-security-module@xxxxxxxxxxxxxxx
- Delivery-date: Fri, 23 Jun 2023 15:20:49 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
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
|