Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1546598iob; Thu, 19 May 2022 08:48:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqF4Z9hlfdZgobf2vhVFby35VCU6+e6rTvTPNn9rFFTZmk0tCeZSQ78PgWxg204u5VTnzx X-Received: by 2002:a63:f046:0:b0:3c6:a37b:1613 with SMTP id s6-20020a63f046000000b003c6a37b1613mr4538865pgj.168.1652975333866; Thu, 19 May 2022 08:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652975333; cv=none; d=google.com; s=arc-20160816; b=Ltov0FXkJ7fMCBAfUgEFmI1jG9RC7IAJ3DeL520KTW8sslutqoeQH3MQVGmHbtSDwM K51p8kZzqu99xHZc8pT3Do7YjttxfB3N/M8/9XgcBrbY7+hLrmyVmPG5GSnUnP1KpNou T+3XPvBOiv8rKC9flXdTF2Un3yKahK8xZmAmqVMIuHtxv6fX2lCXJs0jEmSEjTPyZSKq iWA2EbvxT/H52Itnoz+6KNRyYgSWFpd/FDrGBvGEYO6NryATAkeHf+HxO5QmxqBkAck0 jpncFtMG5D5cajTQhQUpJ5RdXdLUebwHl4K+iK8Q2UnC+1GpSdp8yZp8THccLW+BL12y uZWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=a5SclY404L/ZgpJVaIDFv3O4JyalsuU3U66lxu26HqY=; b=jMuSsNR2kaz11PxKZ5yg/O5FcOW7Oxe8zNI52knYqG0NL/ANrdP3LtW54vsg+4MuCC l328cq8lt7cYxDo3f6eWd4egBsCqmKvImr4mOHje/a8oHBFu/t8QD17HoQIY7EFeLsDv yIdGoL+quGM6HnA6Lteza5XggoSviC026tx71p5Y/xDnRI379HSQsEOIvLIULaKM3X+b id8qJlC0JFJF35pehlL/zgkHBzqz9RsoyX5ukbrs8uE+km30tap4XdPCBqkYyQTCJ83E SDmOaHtWpcKBw4TMMUmkfiq1tB0RKNnCiggGww2zGFI4cC7/M++lxDwLuftRvZLw23mT j73A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Uevjx3rY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a056a00115100b004fa687c28d4si8043348pfm.86.2022.05.19.08.48.41; Thu, 19 May 2022 08:48:53 -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=@collabora.com header.s=mail header.b=Uevjx3rY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231545AbiESLCz (ORCPT + 99 others); Thu, 19 May 2022 07:02:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237177AbiESLCv (ORCPT ); Thu, 19 May 2022 07:02:51 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1883D5DA5D for ; Thu, 19 May 2022 04:02:46 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id A1BE41F45A4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1652958165; bh=Z+gW0P5sGsUp4ykJPGmElehexTGF1kbDnbejPEKwZ9c=; h=From:To:Cc:Subject:Date:From; b=Uevjx3rYjqqSNuK62J8Fbi8xsTvoSJcJPJl2ZQlG7jjH4/zUyWJfKs6jXO21mZkm7 ffZiL8xfeFqsx7HmK5ldFXe6YdvanDGgOMevV6vzTgP+xR6B9NBfxQL42v6ig/x2wg VDvGRFlfWCwLh45yn8AwTZKtKUSSGcRBIHRqMJh2Nf/vOILLuIAxk1VtJp6RcQMx+9 0B3JAwxsBgVWxX0WaLWzmIGfoa+qiu3C09f6XzrgTsRLyzW6OJfuWHlxuLiE8Ia5ob EFCHEbIBqBsF0usM9p4P3C0X7s/UStj51gkA6nVIfLyWqKt2Vnik/wUnyeyIm5tZx3 OhIViF2Smtj6A== From: Dmitry Osipenko To: "Rafael J . Wysocki" , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Cc: linux-kernel@vger.kernel.org Subject: [PATCH v10] notifier: Add atomic_notifier_call_chain_is_empty() Date: Thu, 19 May 2022 14:02:32 +0300 Message-Id: <20220519110232.1198823-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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: X-Mailing-List: linux-kernel@vger.kernel.org Add atomic_notifier_call_chain_is_empty() that returns true if given atomic call chain is empty. The first user of this new notifier API function will be the kernel power-off core code that will support power-off call chains. The core code will need to check whether there is a power-off handler registered at all in order to decide whether to halt machine or power it off. Reviewed-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- Changelog: v10: - Corrected another doc-comment typo s/atomicnotifier/atomic_notifier/. v9: - Extended commit message with a usage example. - Corrected doc-comment with s/blocking/atomic/. include/linux/notifier.h | 2 ++ kernel/notifier.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/notifier.h b/include/linux/notifier.h index 87069b8459af..95e2440037de 100644 --- a/include/linux/notifier.h +++ b/include/linux/notifier.h @@ -173,6 +173,8 @@ extern int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh extern int raw_notifier_call_chain_robust(struct raw_notifier_head *nh, unsigned long val_up, unsigned long val_down, void *v); +extern bool atomic_notifier_call_chain_is_empty(struct atomic_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 ba005ebf4730..137b902c985b 100644 --- a/kernel/notifier.c +++ b/kernel/notifier.c @@ -204,6 +204,19 @@ int atomic_notifier_call_chain(struct atomic_notifier_head *nh, EXPORT_SYMBOL_GPL(atomic_notifier_call_chain); NOKPROBE_SYMBOL(atomic_notifier_call_chain); +/** + * atomic_notifier_call_chain_is_empty - Check whether notifier chain is empty + * @nh: Pointer to head of the atomic notifier chain + * + * Checks whether notifier chain is empty. + * + * Returns true is notifier chain is empty, false otherwise. + */ +bool atomic_notifier_call_chain_is_empty(struct atomic_notifier_head *nh) +{ + return !rcu_access_pointer(nh->head); +} + /* * Blocking notifier chain routines. All access to the chain is * synchronized by an rwsem. -- 2.35.3