Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6221018rwi; Tue, 18 Oct 2022 09:31:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PafgKn7ZAeHoPf+rUXnqR9r7jPWEjhgJ09aEQ5Ir45zUc0meHzrJLQ0XcIOJHw2jfdYLd X-Received: by 2002:a05:6402:847:b0:453:943b:bf4 with SMTP id b7-20020a056402084700b00453943b0bf4mr3371630edz.301.1666110662149; Tue, 18 Oct 2022 09:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666110662; cv=none; d=google.com; s=arc-20160816; b=bZpwY0Ip5OujuSkUop/cF6zgsA58R0vvQqhmOCXumcFUdDJ7UjgRrSaB0iNfWFKy93 lhFotZRbkJlab46+D1y4oUzsGrnXsty9bYwOD0/sdgmv6VfBkZeqNqUcYHhyf934DY5W EthWM9mVVoqInfeSJmpm1cYxLo+4/7pBhFx6U68wAF55sAs7651/3/w1NPJEJOaivKEJ iBAhNJQbBIgZpJqWl8vroz2MlRRInKqCNf6OOBTLlfAXjUVGL/V8PHWeyX976j3blZqu hjTkyffqhfvhdTIaAZVJRCmm98iFmm1zxWQVVn/+pyvRn0T3gstEvGugDI6LPZUkZU1M DO7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=1oLs+QsOzkmiNlMjR8fuZzVNUhlaSm8kh1JoS+Jw7L0=; b=izNPY8hCiarHnUSJMIu8pBG8VRt/sLQvdza33JzMY0eNmo2CQEFaKa1eVXtifLE3xE XOfWcDlKf8C7Dx1+h5AotBnA+v05d3fp4rFpNVCrCCnThA6+eiC5ZNJicuHBGvM/0Uk+ 7hvTX3zrkk1mpyqdBU/bQr0v0zHy/JVAiWIJXIRTKcsDb+MTj9GVFhXrr1BcLS+rRsUC OJbkutdyr1u0OhXrt9XmufzI6hxgAOaOQqhcmlBliqbxKCOYRI2+hDG9bC2BvjgjHQ8b GLJUztuyRfBIO7DtCqHgve2XX+0VfDViexBIz5DgAz8YfgQx22z03/hygy6CcB9Y2WXG WXjQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m10-20020a50cc0a000000b00458d94f1a45si10652088edi.413.2022.10.18.09.30.35; Tue, 18 Oct 2022 09:31:02 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbiJRQM2 (ORCPT + 99 others); Tue, 18 Oct 2022 12:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbiJRQMZ (ORCPT ); Tue, 18 Oct 2022 12:12:25 -0400 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20F858260F; Tue, 18 Oct 2022 09:12:24 -0700 (PDT) Received: by mail-qk1-f169.google.com with SMTP id z30so8930261qkz.13; Tue, 18 Oct 2022 09:12:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1oLs+QsOzkmiNlMjR8fuZzVNUhlaSm8kh1JoS+Jw7L0=; b=En6H/sEZeP8ZMdVNTiDOG4c8212B/Kh1vih33Ec/XVJA9m0JoCBnhgrA3ylwSzEmgW JnC5cqnpYdzRTP+ckyJUgCdfmllSwBo4ltIskJvTWir/4WsW4+Bz7OXC1z8Pp6b+4CRp q1knc0hYuZbxZoCiDcw204hpQdEBqcW33gIsCKyvMX3D45jMBIScOkv+LJtp0XzZ+LAO nHeGniLAGt59KnfQ+EUAI+K0uNsjSUg55QjXhd5JF6TmY54OcFDihKqaBiLyvT8D09r6 KBA0Akjaeoesk/yaMk6VFCdAtTw9QeprweSw0ofFOjg/WoupLrodDN3jUAsgYnpJmhZ/ CdgQ== X-Gm-Message-State: ACrzQf1pyicaeFp7EBLN6HM73ZpaoArck+IY4cujMlqTQZ6oqFb3UGnH akImCtUoDmp7FJQY0eIuFm9Xvl/NLT5Xrj61A0E= X-Received: by 2002:a05:620a:4687:b0:6ee:e69c:e3f1 with SMTP id bq7-20020a05620a468700b006eee69ce3f1mr2288665qkb.285.1666109543177; Tue, 18 Oct 2022 09:12:23 -0700 (PDT) MIME-Version: 1.0 References: <5629262.DvuYhMxLoT@kreacher> <20221012205757.GA3118709@bhelgaas> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 18 Oct 2022 18:12:12 +0200 Message-ID: Subject: Re: [PATCH] rtc: rtc-cmos: Fix event handler registration ordering issue To: Alexandre Belloni Cc: "Rafael J. Wysocki" , Bjorn Helgaas , "Rafael J. Wysocki" , Alessandro Zummo , Mario Limonciello , linux-rtc@vger.kernel.org, LKML , Linux ACPI , Linux PM , Mel Gorman Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Thu, Oct 13, 2022 at 11:34 PM Alexandre Belloni wrote: > > On 13/10/2022 13:38:31+0200, Rafael J. Wysocki wrote: > > On Wed, Oct 12, 2022 at 11:00 PM Bjorn Helgaas wrote: > > > > > > 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 > > > > > > Reviewed-by: Bjorn Helgaas > > > > > > Yep, I blew it with a474aaedac99, sorry about that. > > > > > > Possibly could call cmos_wake_setup() from cmos_do_probe() instead of > > > from cmos_pnp_probe() and cmos_platform_probe()? > > > > Sounds good. > > > > I would prefer to send a separate patch for this on top of the > > $subject one, unless Alexandre wants me to do it all in one go. > > > > Alexandre, what's your preference here? Or would you prefer if I > > pushed this forward? > > > > I applied your patch, feel free to improve on top of that ;) Thank you! Unfortunately, I broke the wake alarm with this change and a fix has just been posted: https://lore.kernel.org/linux-acpi/5887691.lOV4Wx5bFT@kreacher/