From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E15A9C001DF for ; Tue, 1 Aug 2023 10:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231666AbjHAKVt (ORCPT ); Tue, 1 Aug 2023 06:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232788AbjHAKVW (ORCPT ); Tue, 1 Aug 2023 06:21:22 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77ED05276; Tue, 1 Aug 2023 03:18:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1690885059; bh=mKkcfY5zqpLKFBoScbc+V2BRmzXnuf03ZpIGPeD6uB8=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=gkpHN0vgZPP+Bm7wa32u0lXIRovoBU79/16NvzMf77oQ/cOvUDBVEdYDHlfj/2bkX Juql0hjSf1j3hqbpTnhu1sfJHloPN2BDmmnGRErWgzXMwfjaX8WY+peLolVN6poUGm VnEvuEwbkEXIujjDmLYcCMMXzF9tun1kN8rucCDU= Date: Tue, 1 Aug 2023 12:17:33 +0200 (GMT+02:00) From: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh_?= To: Zhangjin Wu Cc: linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org, tanyuan@tinylab.org, w@1wt.eu Message-ID: <9c47fc05-ba20-4d90-9d11-840f77c35aaa@t-8ch.de> In-Reply-To: <20230801101508.75571-1-falcon@tinylab.org> References: <6d67a8ed-8cb6-4ab7-8db0-68269981f8df@t-8ch.de> <20230801101508.75571-1-falcon@tinylab.org> Subject: Re: [PATCH v2 07/10] selftests/nolibc: avoid unused arguments warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Correlation-ID: <9c47fc05-ba20-4d90-9d11-840f77c35aaa@t-8ch.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Aug 1, 2023 12:15:27 Zhangjin Wu : > Hi, Thomas > >> On 2023-08-01 10:07:28+0200, Willy Tarreau wrote: >>> On Tue, Aug 01, 2023 at 07:30:14AM +0200, Thomas Wei=C3=9Fschuh wrote: >>>> This warnings will be enabled later so avoid triggering it. >>>> >>>> Signed-off-by: Thomas Wei=C3=9Fschuh >>>> --- >>>> tools/testing/selftests/nolibc/nolibc-test.c | 3 ++- >>>> 1 file changed, 2 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/test= ing/selftests/nolibc/nolibc-test.c >>>> index 53a3773c7790..cb17cccd0bc7 100644 >>>> --- a/tools/testing/selftests/nolibc/nolibc-test.c >>>> +++ b/tools/testing/selftests/nolibc/nolibc-test.c >>>> @@ -1089,7 +1089,8 @@ static int smash_stack(void) >>>> =C2=A0=C2=A0=C2=A0 return 1; >>>> } >>>> >>>> -static int run_protection(int min, int max) >>>> +static int run_protection(int __attribute__((unused)) min, >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 int __attribute__((unused)) max) >>> >>> This one is used to silence -Wunused-parameter I guess. >> >> Yep. >> >>> It's one of >>> the rare warnings that I find totally useless in field, because it's >>> simply against the principle of using function pointers with different >>> functions having the same interface but different implementations. As >>> your code evolves you end up with unused on absolutely *all* of the >>> arguments of *all* such functions, which makes them a real pain to add >>> and tends to encourage poor practices such as excessive code reuse just >>> by laziness or boredom. BTW it's one of those that are already disabled >>> in the kernel and we could very well do the same here. >> >> It's indeed unfortunate. >> >> As long as we don't have too many of them I would prefer to keep the >> explicit annotations. While they are ugly we then can still reap the >> positive aspects of the warning. >> >> This is where -std=3Dc89 bites us. With extensions (or C2X) we could als= o >> just leave off the argument name to mark it as unused: >> =C2=A0=C2=A0=C2=A0 run_protection(int, int) > > what about further simply ignore the arguments like we did for main(void)= ? That doesn't work because it is stored as a function pointer in the testcas= es array. And these members all take the two parameters.