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 EFD7CC4332F for ; Wed, 12 Oct 2022 18:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbiJLSVB (ORCPT ); Wed, 12 Oct 2022 14:21:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbiJLSUg (ORCPT ); Wed, 12 Oct 2022 14:20:36 -0400 X-Greylist: delayed 559 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 12 Oct 2022 11:20:28 PDT Received: from outbound-smtp21.blacknight.com (outbound-smtp21.blacknight.com [81.17.249.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19EBB58087 for ; Wed, 12 Oct 2022 11:20:27 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp21.blacknight.com (Postfix) with ESMTPS id 7F28418E003 for ; Wed, 12 Oct 2022 19:11:07 +0100 (IST) Received: (qmail 8216 invoked from network); 12 Oct 2022 18:11:07 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 12 Oct 2022 18:11:07 -0000 Date: Wed, 12 Oct 2022 19:11:05 +0100 From: Mel Gorman To: "Rafael J. Wysocki" Cc: Alexandre Belloni , Alessandro Zummo , Mario Limonciello , linux-rtc@vger.kernel.org, Bjorn Helgaas , LKML , Linux ACPI , Linux PM Subject: Re: [PATCH] rtc: rtc-cmos: Fix event handler registration ordering issue Message-ID: <20221012181105.tskfwovexx44kff3@techsingularity.net> References: <5629262.DvuYhMxLoT@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <5629262.DvuYhMxLoT@kreacher> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On Wed, Oct 12, 2022 at 08:07:01PM +0200, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > Because acpi_install_fixed_event_handler() enables the event > automatically on success, it is incorrect to call it before the > handler routine passed to it is ready to handle events. > > Unfortunately, the rtc-cmos driver does exactly the incorrect thing > by calling cmos_wake_setup(), which passes rtc_handler() to > acpi_install_fixed_event_handler(), before cmos_do_probe(), because > rtc_handler() uses dev_get_drvdata() to get to the cmos object > pointer and the driver data pointer is only populated in > cmos_do_probe(). > > This leads to a NULL pointer dereference in rtc_handler() on boot > if the RTC fixed event happens to be active at the init time. > > To address this issue, change the initialization ordering of the > driver so that cmos_wake_setup() is always called after a successful > cmos_do_probe() call. > > While at it, change cmos_pnp_probe() to call cmos_do_probe() after > the initial if () statement used for computing the IRQ argument to > be passed to cmos_do_probe() which is cleaner than calling it in > each branch of that if () (local variable "irq" can be of type int, > because it is passed to that function as an argument of type int). > > Note that commit 6492fed7d8c9 ("rtc: rtc-cmos: Do not check > ACPI_FADT_LOW_POWER_S0") caused this issue to affect a larger number > of systems, because previously it only affected systems with > ACPI_FADT_LOW_POWER_S0 set, but it is present regardless of that > commit. > > Fixes: 6492fed7d8c9 ("rtc: rtc-cmos: Do not check ACPI_FADT_LOW_POWER_S0") > Fixes: a474aaedac99 ("rtc-cmos: move wake setup from ACPI glue into RTC driver") > Link: https://lore.kernel.org/linux-acpi/20221010141630.zfzi7mk7zvnmclzy@techsingularity.net/ > Reported-by: Mel Gorman > Signed-off-by: Rafael J. Wysocki Works for me so; Tested-by: Mel Gorman -- Mel Gorman SUSE Labs