Re: [PATCH] init/main.c: silence some -Wunused-parameter warnings

From: Rasmus Villemoes
Date: Fri May 21 2021 - 03:34:52 EST


On 20/05/2021 15.03, Andrew Halaney wrote:
> On Wed, May 19, 2021 at 09:37:31PM -0700, Andrew Morton wrote:
>> On Wed, 19 May 2021 11:23:41 -0500 Andrew Halaney <ahalaney@xxxxxxxxxx> wrote:
>>

> If we decide we don't care about such warnings then feel free to ignore
> this patch, but since I was playing around here anyways I thought I'd
> clean it up a little. My preference would be to care, but the output is
> so loud it is easy to make the argument that it is too late to start
> caring.

Those always-unused annotations are quite verbose. Could we instead
allow both int (*)(char *) and int (*)(void) functions via some macro
magic, say extending __setup_param to something like (entirely untested)

#define __setup_param(str, unique_id, fn, early) \
static const char __setup_str_##unique_id[] __initconst \
__aligned(1) = str; \
+ static_assert(same_type(&fn, int (*)(char *)) || same_type(&fn,
int (*)(void)));
static struct obs_kernel_param __setup_##unique_id \
__used __section(".init.setup") \
__aligned(__alignof__(struct obs_kernel_param)) \
- = { __setup_str_##unique_id, fn, early }
+ = { __setup_str_##unique_id, (int (*)(char *)fn, early }

That would still require modifying each callback, but then it would be
to the more plain-C

int foo(void) // yeah, this doesn't use any parameters

I checked, the transparent_union trick doesn't work for static
initialization.

But really, the compiler should have some heuristic that said "hm, ok,
the address of this function was taken so it probably has that prototype
because it has to be that way". I bet that would remove 90% of the
Wunused-parameter noise.

Rasmus