Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4219669rwi; Wed, 12 Oct 2022 12:22:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ZmhGjIBtPd+ETWWc+ZN7KjU80yv5BR3oaC6w63/kgT2vsFxfqFCHCcIf5wg+JMwFsDv6Q X-Received: by 2002:a17:906:65c6:b0:73c:8897:65b0 with SMTP id z6-20020a17090665c600b0073c889765b0mr23730203ejn.322.1665602567816; Wed, 12 Oct 2022 12:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665602567; cv=none; d=google.com; s=arc-20160816; b=Rz6f1jrP3i8XXwOgPgeQHElLYy1PRI9K0c8oURZj5+VNlyQWSN/Kk1ZfAPgCaYbpLO SXbFuhk27qwIh7w93lGnLHZeEyROLDyVUc2nbBTkiafJfrkOfc0xWhV82ebjXNrGzWQv sg7h5TAJJiPEbRGXPQItoRUbknFKwhVJJPrGBeiKmDIMVJTOo+v2y9s++PKmjrLzEjg8 bIrW5VAJ0EQqt/3coKQsB7vwd6RQSJYr6w0d17CeHc43MtBR/oQGRhlpN3pY1+vQ/5fl XkHbrNkHyhQYojsCWrzjc9kerId/uVPdU42MEphn9WiSppBDEm6KA2Slr/oY2kPJAnts sTFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=DyX+xr0ZmydagiwbGJEK8a9CNZ+qJhiPSp39i7R037M=; b=o9m8KoafvHn63jgdXRGPisj6VXIfeQFhlCRXXnMoislZ8YjIH/JzGuE4Sh9hhDkSk5 gndxZi5PN6RzLJWG5s8QaB3NQPhsA7rHknG4c9NTNeSPK0eDCYKJtAK9dXetAbA+QRxS hEXP/+QWs+aLT8NllNr9cFQrx+gjxUma+topbVv52ae+hZ220eowb91NohUxB0crXZUu Jah4RPOtOkl06e6G2PrJ1uThpNNnQPZEGH6/NFe5f0GWgGOxytcwFGdIrCFdxyk3JH1t mcqUtbpUSzPGbQAIHYFzFi66p5Zcc3cXon7fCgwenq0Xb5ugPFJ2LRtCooU/TvepZLnV mSnQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd35-20020a17090796a300b00781599eb7e4si18973239ejc.753.2022.10.12.12.22.21; Wed, 12 Oct 2022 12:22:47 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbiJLSLO (ORCPT + 99 others); Wed, 12 Oct 2022 14:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbiJLSLL (ORCPT ); Wed, 12 Oct 2022 14:11:11 -0400 Received: from outbound-smtp06.blacknight.com (outbound-smtp06.blacknight.com [81.17.249.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D45D25BE for ; Wed, 12 Oct 2022 11:11:09 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp06.blacknight.com (Postfix) with ESMTPS id 8174AC2B6E 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> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 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