Message ID | 20230801-nolibc-warnings-v2-7-1ba5ca57bd9b@weissschuh.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2469516vqg; Mon, 31 Jul 2023 23:09:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlFL/pqCUGRdvP83uSD1DXiOLDu5jSP3oMD90FoM+ulItCnSA1+It6hSy64Yz8Itjl2XinV2 X-Received: by 2002:a05:6a20:1441:b0:126:81e0:49dd with SMTP id a1-20020a056a20144100b0012681e049ddmr12709749pzi.14.1690870182339; Mon, 31 Jul 2023 23:09:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690870182; cv=none; d=google.com; s=arc-20160816; b=KoAU1odiAXOooXZA0NMx7PCRxNdCO0uvqewMRymhM5Vvzp2H/dKFBbhTha0nPIVPLh TpHhhHrsu5KsqKo6kUKx6G0Zvi4L0jKOtk7yg+pS1CC8ze5o6dYekUBX4Fztre3XamgW AEYlHJM4hOTAvEDNeXfgO65eAoTAz309dqo2CvmdBwnS1oN2VXLnY7fI9zDMCx3B52Xh UhrT5sRhSe4QOup2s8lAqOZejl1Vprui5iUOZUW1mvkLvUfBpuTfmGAcn2AqBD7jD150 ZoEuEi1spYsi6L8iyHzeI96oZw3VazwwH7PNSxERy7VYW0L0zXexXgaCRu6883qwgldB NMIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=6q5AdNvfImQCiNqQZDZ02tz/FiVJy2/x4UlfOhZGGcg=; fh=UZfhiU2pgwvZdBOe9fFEhnfTQX0/6KsvXKQubWsfhik=; b=uF3KPK7HXN5UisPIsnFUqkmCdAkClBdptlBAQ2z8w3287lmQnaMa4jBywttbOP/p2O dbeU9XIJ4vGLLSx95Qo9i8ACpTO+qSNyzv6ukheZBaj0ytuBU2LWw9PVGt/PaqS+YcR5 xvDlSnjeetPoeA0WDIGP5EnR93DZoj/sswNptdrBjyyDhgVjkrLBMPRc/sNgePytLKEJ Ql1BZugugNd5vr2fRwvrO+IZ95E6Ag83zV20w3PZgL+5drBNeVX/o+VqeR6HM+oINig4 keUbG9+xU+U8wgvzSV8bAboDu0sXgZEgfqeHkXIdtJUfnA8wlyqQ//ehFKH1lNJCrNt1 /gyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=OJi9b8qP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o14-20020a056a0015ce00b006872be161c1si3970697pfu.159.2023.07.31.23.09.21; Mon, 31 Jul 2023 23:09:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=OJi9b8qP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbjHAFai (ORCPT <rfc822;maxi.paulin@gmail.com> + 99 others); Tue, 1 Aug 2023 01:30:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230181AbjHAFaX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 1 Aug 2023 01:30:23 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 820CD1FC0; Mon, 31 Jul 2023 22:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1690867813; bh=68cbroggSXK5AuaobFuJ+Z2zDm6urN4gJ+66FGT1Uuk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OJi9b8qPlP1oIS+wo7uoBxGWfGJcbh5IH4vppHDXWwPpKJsZw7NyxC6xLZU+Xk0oH tIov+5UfdtYKbAxEZddRhL47R234mYUatJQN4OHVQdeZytCx5GsSXKFSduVJzXGnSE 6/SsgtJF0xwSu7wGnx5L4il/XP7F6N6IF/Uv5XeM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> Date: Tue, 01 Aug 2023 07:30:14 +0200 Subject: [PATCH v2 07/10] selftests/nolibc: avoid unused arguments warnings MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20230801-nolibc-warnings-v2-7-1ba5ca57bd9b@weissschuh.net> References: <20230801-nolibc-warnings-v2-0-1ba5ca57bd9b@weissschuh.net> In-Reply-To: <20230801-nolibc-warnings-v2-0-1ba5ca57bd9b@weissschuh.net> To: Willy Tarreau <w@1wt.eu>, Shuah Khan <shuah@kernel.org> Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Yuan Tan <tanyuan@tinylab.org>, Zhangjin Wu <falcon@tinylab.org>, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1690867811; l=759; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=68cbroggSXK5AuaobFuJ+Z2zDm6urN4gJ+66FGT1Uuk=; b=f5FFo8CzKRA1WOhf9Y0SVYApgArlbh3IMK9g/aVCZ2I4Rv1TeOJ6Pd9a0RsBt5Ad1uInWMaDR 8Bqy2lWFtwIBMYMbPj7r7MHO6dN+SCk4XG7J1tu4l/zoBeJY4ZuykSv X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_PASS,T_SCC_BODY_TEXT_LINE, T_SPF_HELO_TEMPERROR,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773005892034741130 X-GMAIL-MSGID: 1773005892034741130 |
Series |
tools/nolibc: enable compiler warnings
|
|
Commit Message
Thomas Weißschuh
Aug. 1, 2023, 5:30 a.m. UTC
This warnings will be enabled later so avoid triggering it.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/testing/selftests/nolibc/nolibc-test.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Tue, Aug 01, 2023 at 07:30:14AM +0200, Thomas Weißschuh wrote: > This warnings will be enabled later so avoid triggering it. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > 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/testing/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) > return 1; > } > > -static int run_protection(int min, int max) > +static int run_protection(int __attribute__((unused)) min, > + int __attribute__((unused)) max) This one is used to silence -Wunused-parameter I guess. 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. Willy
On 2023-08-01 10:07:28+0200, Willy Tarreau wrote: > On Tue, Aug 01, 2023 at 07:30:14AM +0200, Thomas Weißschuh wrote: > > This warnings will be enabled later so avoid triggering it. > > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > > --- > > 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/testing/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) > > return 1; > > } > > > > -static int run_protection(int min, int max) > > +static int run_protection(int __attribute__((unused)) min, > > + 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=c89 bites us. With extensions (or C2X) we could also just leave off the argument name to mark it as unused: run_protection(int, int)
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ßschuh wrote: > > > This warnings will be enabled later so avoid triggering it. > > > > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > > > --- > > > 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/testing/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) > > > return 1; > > > } > > > > > > -static int run_protection(int min, int max) > > > +static int run_protection(int __attribute__((unused)) min, > > > + 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=c89 bites us. With extensions (or C2X) we could also > just leave off the argument name to mark it as unused: > run_protection(int, int) what about further simply ignore the arguments like we did for main(void)? Thanks, Zhangjin
Aug 1, 2023 12:15:27 Zhangjin Wu <falcon@tinylab.org>: > 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ßschuh wrote: >>>> This warnings will be enabled later so avoid triggering it. >>>> >>>> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> >>>> --- >>>> 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/testing/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) >>>> return 1; >>>> } >>>> >>>> -static int run_protection(int min, int max) >>>> +static int run_protection(int __attribute__((unused)) min, >>>> + 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=c89 bites us. With extensions (or C2X) we could also >> just leave off the argument name to mark it as unused: >> 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 testcases array. And these members all take the two parameters.
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/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) return 1; } -static int run_protection(int min, int max) +static int run_protection(int __attribute__((unused)) min, + int __attribute__((unused)) max) { pid_t pid; int llen = 0, status;