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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9232AC433FE for ; Mon, 8 Nov 2021 14:07:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E0EA610E9 for ; Mon, 8 Nov 2021 14:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240274AbhKHOKI convert rfc822-to-8bit (ORCPT ); Mon, 8 Nov 2021 09:10:08 -0500 Received: from mail-ua1-f54.google.com ([209.85.222.54]:34507 "EHLO mail-ua1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240246AbhKHOKC (ORCPT ); Mon, 8 Nov 2021 09:10:02 -0500 Received: by mail-ua1-f54.google.com with SMTP id b3so31739471uam.1; Mon, 08 Nov 2021 06:07:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=srssYsTsVb5ivMDmTAt6Y7lXgP/lHHGiJX97jzZpFII=; b=lT7Q627YXwAYYti9TyWmhNrAwxF37ER+DnnHvi8ZOaxozyOw/rwlQ66wlApkNuyNN0 l/36WyzNYJX7UwsJU1aMV3bW5Sz7j/IP33Z/kZbh3aJA6GtHX+o7tNp9p+l7GF4QkKIB sjbbINID3WCsCkZrFWfMUwfrp9PjYh6onoNzXUnoEQ/95F5HYU5n5UHmTstBfe0urn4h 1SE5gPNj3Pc2mvjTTyE8StQTFs4/Z7quYn3ZeZl33bFkXJAPxUlQqv23fQ05cU4PyTMU am1ot2b90FgHRA4kFfiBdu8fFSdh6YxyoBpITiqz4ORJJJdFb9hLqYTU1fxm5MWEErbR 0b5Q== X-Gm-Message-State: AOAM531VcfMwSWKNLwI/Nir0vc2ScGiGBGnffpEeKxm2KOJGi6tJeJ4f ZdyVgO2KwEjymrO3gMZbXCXik2FZgi7ZJAl7 X-Google-Smtp-Source: ABdhPJx9G54VGw4oc23XJRelgp9dkMEtXydk+uvqLajllgER83nLii76Q7zBboH+kgBjAPFdw36B5A== X-Received: by 2002:ab0:3e3:: with SMTP id 90mr185644uau.102.1636380435783; Mon, 08 Nov 2021 06:07:15 -0800 (PST) Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com. [209.85.221.171]) by smtp.gmail.com with ESMTPSA id c11sm3226781vsh.22.2021.11.08.06.07.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Nov 2021 06:07:14 -0800 (PST) Received: by mail-vk1-f171.google.com with SMTP id a129so8254621vkb.8; Mon, 08 Nov 2021 06:07:14 -0800 (PST) X-Received: by 2002:a05:6122:1350:: with SMTP id f16mr21288847vkp.26.1636380434409; Mon, 08 Nov 2021 06:07:14 -0800 (PST) MIME-Version: 1.0 References: <20211108101157.15189-1-bp@alien8.de> <20211108101157.15189-43-bp@alien8.de> In-Reply-To: <20211108101157.15189-43-bp@alien8.de> From: Geert Uytterhoeven Date: Mon, 8 Nov 2021 15:07:03 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v0 42/42] notifier: Return an error when callback is already registered To: Borislav Petkov Cc: LKML , Thomas Gleixner , Arnd Bergmann , Ayush Sawal , Greg Kroah-Hartman , Rohit Maheshwari , Steven Rostedt , Vinay Kumar Yadav , ALSA Development Mailing List , bcm-kernel-feedback-list , Intel Graphics Development , intel-gvt-dev@lists.freedesktop.org, alpha , Linux ARM , linux-clk , Linux Crypto Mailing List , linux-edac@vger.kernel.org, Linux Fbdev development list , linux-hyperv@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds , "open list:BROADCOM NVRAM DRIVER" , Parisc List , Linux PM list , linuxppc-dev , "open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM" , Linux-Renesas , linux-s390 , scsi , Linux-sh list , linux-staging@lists.linux.dev, linux-tegra , linux-um , USB list , "open list:TENSILICA XTENSA PORT (xtensa)" , netdev , openipmi-developer@lists.sourceforge.net, rcu@vger.kernel.org, sparclinux , "the arch/x86 maintainers" , xen-devel@lists.xenproject.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Borislav, On Mon, Nov 8, 2021 at 11:13 AM Borislav Petkov wrote: > From: Borislav Petkov > > The notifier registration routine doesn't return a proper error value > when a callback has already been registered, leading people to track > whether that registration has happened at the call site: > > https://lore.kernel.org/amd-gfx/20210512013058.6827-1-mukul.joshi@amd.com/ > > Which is unnecessary. > > Return -EEXIST to signal that case so that callers can act accordingly. > Enforce callers to check the return value, leading to loud screaming > during build: > > arch/x86/kernel/cpu/mce/core.c: In function ‘mce_register_decode_chain’: > arch/x86/kernel/cpu/mce/core.c:167:2: error: ignoring return value of \ > ‘blocking_notifier_chain_register’, declared with attribute warn_unused_result [-Werror=unused-result] > blocking_notifier_chain_register(&x86_mce_decoder_chain, nb); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Drop the WARN too, while at it. > > Suggested-by: Thomas Gleixner > Signed-off-by: Borislav Petkov Thanks for your patch! > --- a/include/linux/notifier.h > +++ b/include/linux/notifier.h > @@ -141,13 +141,13 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh); > > #ifdef __KERNEL__ > > -extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh, > +extern int __must_check atomic_notifier_chain_register(struct atomic_notifier_head *nh, > struct notifier_block *nb); > -extern int blocking_notifier_chain_register(struct blocking_notifier_head *nh, > +extern int __must_check blocking_notifier_chain_register(struct blocking_notifier_head *nh, > struct notifier_block *nb); > -extern int raw_notifier_chain_register(struct raw_notifier_head *nh, > +extern int __must_check raw_notifier_chain_register(struct raw_notifier_head *nh, > struct notifier_block *nb); > -extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh, > +extern int __must_check srcu_notifier_chain_register(struct srcu_notifier_head *nh, > struct notifier_block *nb); I think the addition of __must_check is overkill, leading to the addition of useless error checks and message printing. Many callers call this where it cannot fail, and where nothing can be done in the very unlikely event that the call would ever start to fail. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds