Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5545965iob; Mon, 9 May 2022 20:12:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsp3DPu0cav3nDxLkDLJo8CoLomH+RtBZIe/inc4LVUb0Biq95Hce0PExe4aIpemOSI6lL X-Received: by 2002:a63:5041:0:b0:3c2:1938:3925 with SMTP id q1-20020a635041000000b003c219383925mr15090970pgl.555.1652152328419; Mon, 09 May 2022 20:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652152328; cv=none; d=google.com; s=arc-20160816; b=j3ddRSImZmG7RiOo1Ji2bPalSaQYxoGVyUR7YIrClvC1gMgeIS3BC1WDbFVP+AOc05 hzhxsvpx2DIfD3yr4SyCQveJv79nUjoMb87kfeos3xVmrEurzbK47NB3N5tJ8obbI9xv 0Rxs7YgWpc6Mqui11+A1WVV3d4bYYJVOKkn19rfjT/ryUwCi7/YFVdVp3w0mcXcaXuEO rOV4uY2e25WGaUALY8c1GfWd1PEuSNN+r7TQtbhQwR2jE4U/kr26pyK8gXhpFs4Q1/7N hoZZ1tqklp/3/wEpZL3APSrHYXj3pPcvodbHtJ1YbXKbUPY0Ihdzm7vNeSnReS/hMOds 9o/g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CCikoygDMAu1gNVV1trDVWyMZyH2Pt7LJ4RXEYC8m9A=; b=NgLf8H6E9VXbx71bZqYQZqdw+TqQJiAkuGh0MgK2B5eUnfUQP1PjcC4UCbuJKrBEPG L3N9JUfiE3gRF35PHKBkM8aFKJjHopHgji9Czj2mVtxnswY4BRAZiiEbQrHIU/AQNMqu iNN7WkL9dnWyHLDdw5c3mQQJPFtbCPmB+A4c38HguluRbFXp2zkake4BHH0Ps4qr0hTx 54sTIBzuvWUraIL4zbChSn9H5BVrdcBR1AWRw2VMH2pXt8GEsX9rOKCCZ2ZJgpGVL2BG cbAf8Upih5Pr3t6DxxIDlQ+s/+QfMS3EHLGL2Ay/gYZ+PIL3mds/lL7rwMh6vu20YOyg rF/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=WX2wLAoF; 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 d9-20020a63fd09000000b0039d9d404482si15796864pgh.570.2022.05.09.20.11.53; Mon, 09 May 2022 20:12:08 -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=WX2wLAoF; 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 S230219AbiEIXju (ORCPT + 99 others); Mon, 9 May 2022 19:39:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232705AbiEIXhz (ORCPT ); Mon, 9 May 2022 19:37:55 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0553A24BB30; Mon, 9 May 2022 16:33:31 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id DDF821F430B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1652139210; bh=YK0F6fR8XWeV2rG0cbTxAWJjHbs9t/ROkX6NXAfeuRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WX2wLAoFqw2NcqFA+1BgEi+pnSqQ/OT0ntArBclZh3rRdgYWFpNobAvm6ZwR47f5O UVB/nJt08DF0z35eem1y5e29iS6TGa3FlqumDo8Gztlg9RTEy3yXgoM/PdqWZ72qjH BBXHhpZMhXXq1gmyrAUnf9JuPFEL0VuxOWgpl0g7gErLQMCAr8EBR7mlBfM7b/CzpF rbbVZCAv5Su19JHE0dZAYAwszfCQR2CPfwc4wUkYqtr+WKd4w8pxs2RFEPFv5Qa681 /mjY+RYiodQ7Rz1Y3p36rejWNrVlI8LiNaH4VL6v6O9rIPyvlE8v1d9uqae+R0n5sB mZdrZdLthuUpw== From: Dmitry Osipenko To: 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 , x86@kernel.org, "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 , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Cc: linux-kernel@vger.kernel.org, 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, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, xen-devel@lists.xenproject.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v8 07/27] kernel/reboot: Add kernel_can_power_off() Date: Tue, 10 May 2022 02:32:15 +0300 Message-Id: <20220509233235.995021-8-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220509233235.995021-1-dmitry.osipenko@collabora.com> References: <20220509233235.995021-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 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=unavailable 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 kernel_can_power_off() helper that replaces open-coded checks of the global pm_power_off variable. This is a necessary step towards supporting chained power-off handlers. Signed-off-by: Dmitry Osipenko --- include/linux/reboot.h | 1 + kernel/reboot.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/reboot.h b/include/linux/reboot.h index 6b951d68c0c7..c52f77ee4ddd 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -149,6 +149,7 @@ extern void kernel_restart_prepare(char *cmd); extern void kernel_restart(char *cmd); extern void kernel_halt(void); extern void kernel_power_off(void); +extern bool kernel_can_power_off(void); void ctrl_alt_del(void); diff --git a/kernel/reboot.c b/kernel/reboot.c index eaede35f45e2..982e58c11ce8 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -523,6 +523,18 @@ void do_kernel_power_off(void) atomic_notifier_call_chain(&power_off_handler_list, 0, NULL); } +/** + * kernel_can_power_off - check whether system can be powered off + * + * Returns true if power-off handler is registered and system can be + * powered off, false otherwise. + */ +bool kernel_can_power_off(void) +{ + return !atomic_notifier_call_chain_is_empty(&power_off_handler_list); +} +EXPORT_SYMBOL_GPL(kernel_can_power_off); + /** * kernel_power_off - power_off the system * @@ -581,7 +593,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, /* Instead of trying to make the power_off code look like * halt when pm_power_off is not set do it the easy way. */ - if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off) + if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !kernel_can_power_off()) cmd = LINUX_REBOOT_CMD_HALT; mutex_lock(&system_transition_mutex); -- 2.35.1