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 D1BCDC4321E for ; Fri, 10 Dec 2021 18:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245184AbhLJSRw (ORCPT ); Fri, 10 Dec 2021 13:17:52 -0500 Received: from mail-ot1-f50.google.com ([209.85.210.50]:41580 "EHLO mail-ot1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245272AbhLJSRt (ORCPT ); Fri, 10 Dec 2021 13:17:49 -0500 Received: by mail-ot1-f50.google.com with SMTP id n17-20020a9d64d1000000b00579cf677301so10431064otl.8; Fri, 10 Dec 2021 10:14:13 -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; bh=RaOuCzlDrEGoU3kCCyjiPh5ZIczFbf2cAVp5IUpr62Q=; b=aYs7LMndxGQpF02d4DZkmc86npx27c98t9FUhb00GPqmlpfzrDoHJSQAdPtHMLb4ZT sBgEFGPVqlxMhz9CL8d6NEjNXDJ00/Dn+GVsVJQWoB6F3WnWtzX04Oc1yVZTCPjqFaDn pg7aBS6C5RgxjWnO3mqThntNTG0GPO/p6/NL9Gc+VpFmnYOCxJu+Kup89a7HZaI2mZPi pY3YahmWNV1qPpsWlk4sUc1PiBEAk3/QXfVxMNfiYxlFHiZyqqjebHVL+t4YaI2tG2+8 LZ/8XdpAAqs6XlO/Okhl+gqgoHLaz5SH2vBprAB4/uQhVPdD0zLNey6keZpW+EXJRU6x smpg== X-Gm-Message-State: AOAM532adB4yICiE7ElTW/1QWw2JxmvASw1hXzicLGSu5KzReFzRJSn1 +uwiJ1itRFIqsnUsofHij1+XUFlMjNykQavrK8w= X-Google-Smtp-Source: ABdhPJx5VEl25dlL8StyZ7/vR+sIp4uhzbZQ+4jxftcUhgC3Wucypp0Twl9yCOfT1qw70j5+PgOSc5gj4QOVrzsPiE4= X-Received: by 2002:a9d:4c10:: with SMTP id l16mr12483219otf.198.1639160053505; Fri, 10 Dec 2021 10:14:13 -0800 (PST) MIME-Version: 1.0 References: <20211126180101.27818-1-digetx@gmail.com> <20211126180101.27818-3-digetx@gmail.com> In-Reply-To: <20211126180101.27818-3-digetx@gmail.com> From: "Rafael J. Wysocki" Date: Fri, 10 Dec 2021 19:14:02 +0100 Message-ID: Subject: Re: [PATCH v4 02/25] notifier: Add blocking_notifier_call_chain_is_empty() To: Dmitry Osipenko Cc: Thierry Reding , Jonathan Hunter , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Geert Uytterhoeven , Greg Ungerer , Joshua Thompson , Thomas Bogendoerfer , Sebastian Reichel , Linus Walleij , Philipp Zabel , Greentime Hu , Vincent Chen , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Yoshinori Sato , Rich Felker , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "the arch/x86 maintainers" , "H. Peter Anvin" , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , "Rafael J. Wysocki" , Len Brown , Santosh Shilimkar , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Pavel Machek , Lee Jones , Andrew Morton , Guenter Roeck , Daniel Lezcano , Andy Shevchenko , Ulf Hansson , alankao@andestech.com, "K . C . Kuen-Chern Lin" , Linux ARM , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev , linux-riscv@lists.infradead.org, Linux-sh list , xen-devel@lists.xenproject.org, ACPI Devel Maling List , Linux PM , linux-tegra Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-csky@vger.kernel.org On Fri, Nov 26, 2021 at 7:01 PM Dmitry Osipenko wrote: > > Add blocking_notifier_call_chain_is_empty() that returns true if call > chain is empty. > > Signed-off-by: Dmitry Osipenko > --- > include/linux/notifier.h | 2 ++ > kernel/notifier.c | 14 ++++++++++++++ > 2 files changed, 16 insertions(+) > > diff --git a/include/linux/notifier.h b/include/linux/notifier.h > index 4b80a815b666..924c9d7c8e73 100644 > --- a/include/linux/notifier.h > +++ b/include/linux/notifier.h > @@ -173,6 +173,8 @@ int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh, > int raw_notifier_call_chain_robust(struct raw_notifier_head *nh, > unsigned long val_up, unsigned long val_down, void *v); > > +bool blocking_notifier_call_chain_is_empty(struct blocking_notifier_head *nh); > + > #define NOTIFY_DONE 0x0000 /* Don't care */ > #define NOTIFY_OK 0x0001 /* Suits me */ > #define NOTIFY_STOP_MASK 0x8000 /* Don't call further */ > diff --git a/kernel/notifier.c b/kernel/notifier.c > index b8251dc0bc0f..b20cb7b9b1f0 100644 > --- a/kernel/notifier.c > +++ b/kernel/notifier.c > @@ -322,6 +322,20 @@ int blocking_notifier_call_chain(struct blocking_notifier_head *nh, > } > EXPORT_SYMBOL_GPL(blocking_notifier_call_chain); > > +/** > + * blocking_notifier_call_chain_is_empty - Check whether notifier chain is empty > + * @nh: Pointer to head of the blocking notifier chain > + * > + * Checks whether notifier chain is empty. > + * > + * Returns true is notifier chain is empty, false otherwise. > + */ > +bool blocking_notifier_call_chain_is_empty(struct blocking_notifier_head *nh) > +{ > + return !rcu_access_pointer(nh->head); > +} > +EXPORT_SYMBOL_GPL(blocking_notifier_call_chain_is_empty); The check is not reliable (racy) without locking, so I wouldn't export anything like this to modules. At least IMO it should be added along with a user.