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 X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A933C4338F for ; Tue, 27 Jul 2021 20:22:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1058260F23 for ; Tue, 27 Jul 2021 20:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231211AbhG0UWg (ORCPT ); Tue, 27 Jul 2021 16:22:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbhG0UWf (ORCPT ); Tue, 27 Jul 2021 16:22:35 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D992FC061757 for ; Tue, 27 Jul 2021 13:22:34 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id jg2so863954ejc.0 for ; Tue, 27 Jul 2021 13:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LMG+Pjc0zpd0uNpV6YIb/P6RindR203i0ZHENXhfOys=; b=psO33K89BrKYXY3cfhB61uJ9PSC6boj7ts9dzDfwkRBsY+I+iAqJvIsTF2cEOaMZDq Yl8d0/COiae8Tn4tOjVWqkjqoprtkt6X5lgXVU3RcgUCQsSfw2tJFDxnHwdjsa2E/PJw bg7w8HqVGwHPZDxdwTW6q4iT6ekOSAMXmWbbftMAUvRlGXnUyDN3fP0qV5IiBgq0jp/3 yjqQ2LGlkBxbRdhdWKU0ykbIvpIMNIQSGSMVW5glAdYWYw89I5+bxPuXIleBUdnXCLPl f1Hwqd8BWmiRV702XVCMANy22y92QF+EXd0byD1tBFpGg/D07DuhxPR3F6Wchj2GYjVw 2u5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LMG+Pjc0zpd0uNpV6YIb/P6RindR203i0ZHENXhfOys=; b=GHbgRksMxoAKAI17pmhJRYHQ1dOkX0bfT5iaXAV7DDImafxNLqwWsy1z1llSCXWwyD fNoSGglTDi0+0g+x5cUGBQcl5CddS+0BHOIAD1XzcHc7Fi69RlXxPvBJq+UBpn0zg12T NGndoS3+iKpYktoAwUJyyb2vjyO24xlvbzSJSvlUZWst5naZn6CWJhlZ11GxPPCJlsks kM1J0c5K4rTNkf0sbuKzJyxGdL+QGE7HIYHOlRJ80mzOPBFBoP/2rcboeskAwzlgzTlN TyNP7ZznwxqTqTHsqWO34+GkUjFtJSUSTg4s4DbiQgk/sDJJrRwlSWJiCVt54IgcDaPg NZig== X-Gm-Message-State: AOAM5300OQzGguZxphgV5IZLXkB8KHgSf6Pnzc0cG2GzL25rQG2eMayp BXUCj8nFQKVjVECseDNLa080Zo5IkcOddt+V068e X-Google-Smtp-Source: ABdhPJwdyb/0U2z31KCqdXFX0sF7Ajhn8CxOWsoX2cWizw1jC3Tc+NEqM9tWzDOGNvG08fByi6anvoeDDlImZ5AYlJg= X-Received: by 2002:a17:906:7951:: with SMTP id l17mr23806775ejo.529.1627417353173; Tue, 27 Jul 2021 13:22:33 -0700 (PDT) MIME-Version: 1.0 References: <20210714091747.2814370-1-morbo@google.com> <20210726201924.3202278-1-morbo@google.com> <20210726201924.3202278-2-morbo@google.com> <20210727201328.GY1583@gate.crashing.org> In-Reply-To: <20210727201328.GY1583@gate.crashing.org> From: Bill Wendling Date: Tue, 27 Jul 2021 13:22:21 -0700 Message-ID: Subject: Re: [PATCH v2 1/3] base: mark 'no_warn' as unused To: Segher Boessenkool Cc: Greg Kroah-Hartman , Nick Desaulniers , Nathan Chancellor , "Rafael J. Wysocki" , clang-built-linux , LKML , linux-toolchains@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Tue, Jul 27, 2021 at 1:17 PM Segher Boessenkool wrote: > > On Tue, Jul 27, 2021 at 07:59:24PM +0200, Greg Kroah-Hartman wrote: > > On Tue, Jul 27, 2021 at 10:39:49AM -0700, Nick Desaulniers wrote: > > > I think warn_unused_result should only really be used for functions > > > where the return value should be used 100% of the time. > > > > I too want a shiny new pony. > > > > But here in the real world, sometimes you have functions that for 99% of > > the users, you do want them to check the return value, but when you use > > them in core code or startup code, you "know" you are safe to ignore the > > return value. > > > > That is the case here. We have other fun examples of where people have > > tried to add error handling to code that runs at boot that have actually > > introduced security errors and they justify it with "but you have to > > check error values!" > > > > > If there are > > > cases where it's ok to not check the return value, consider not using > > > warn_unused_result on function declarations. > > > > Ok, so what do you do when you have a function like this where 99.9% of > > the users need to check this? Do I really need to write a wrapper > > function just for it so that I can use it "safely" in the core code > > instead? > > > > Something like: > > > > void do_safe_thing_and_ignore_the_world(...) > > { > > __unused int error; > > > > error = do_thing(...); > > } > > > > Or something else to get the compiler to be quiet about error being set > > and never used? > > The simplest is to write > if (do_thing()) { > /* Nothing here, we can safely ignore the return value > * here, because of X and Y and I don't know, I have no > * idea actually why we can in this example. Hopefully > * in real code people do have a good reason :-) > */ > } > > which should work in *any* compiler, doesn't need any extension, is > quite elegant, and encourages documenting why we ignore the return > value here. > Or better still, use sysfs_create_link_nowarn() instead of sysfs_create_link(). We'll just have to take the "__must_check" attribute off the sysfs_create_link_nowarn() declaration. -bw