Message ID | 2219830.iZASKD2KPV@kreacher |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2266408wru; Mon, 7 Nov 2022 12:07:24 -0800 (PST) X-Google-Smtp-Source: AMsMyM7e+XmzgndDLdZbGPPyZezXDKiQI2b4uKOokjlawAfBkFpgQINB/QEt1NchSWIr7gA7SIuQ X-Received: by 2002:a17:902:f691:b0:186:b250:9767 with SMTP id l17-20020a170902f69100b00186b2509767mr51009053plg.60.1667851644063; Mon, 07 Nov 2022 12:07:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667851644; cv=none; d=google.com; s=arc-20160816; b=Uub/21WRL0qoY9lCiW2VQqciqQLLhXIh1Z2kipkYpBizns9Dr56/UH4k+qa8MFetRx a9voRXX1PZJ4zS93c+uotNLetQUgz+u1Yy8b1Qp92h+ApcalZzpHE7qwv8ruUvEkFMQ5 Znr4xPQT2FVq/r9mXHGYZpOeo5LOzKymjG6OS1AKd4R2cc7WznBWokJd3H/6O808Jjzq DpazhDycKwHznTbjyVHYSUk/TnPhfRbdgJakElKSC2U23CVDKvckBce1NlczmDnKIcvu pzMIiHFg8kbbUs9RtOXBn3BNDoP6rsRTZ43ZtzzRhCuM/d4b+UmUWjrf0VZRjduMOjfq tYZw== 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; bh=EtnNqTGf2Mm0CrfG+JuOtksoNogiBh3br6ekabmEBR0=; b=X0qwVQrll1oNF8KK8gRDj9supJzqX0LykR72zj9jGQS3l/GYqcVzcGl81zYjEurDmB EwiJf2p+HwCvBFctAo8MnwERbh6L6NVkfYVoOZyDqGaurjBJy6TXTnnFO+oEJG5NJEBj taF32N9b95wSRxktD2orx7QdN3OgOGxc7qT7JTxAyw2QB7qDzAKaCmNBPASZqJi3LUw8 01/m2C77/nt5mV3vqa1fl4gf3xVIlP0AMckjiXSBKWpuRERMsvIBPmRc5Hi+3/qyHQLy tsdcaKr+HUIcxSF5a/LOAwzKqOHAOsksQrlBWbyA6MPNQ7cY5KKh4HhIQ8u+0tT6h03Z 3I6A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oe18-20020a17090b395200b00200435da17asi13619145pjb.128.2022.11.07.12.07.10; Mon, 07 Nov 2022 12:07:24 -0800 (PST) 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 S232760AbiKGUDj (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 15:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231398AbiKGUDh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Nov 2022 15:03:37 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F7F178BB; Mon, 7 Nov 2022 12:03:35 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.0.0) id 0badc597a4899159; Mon, 7 Nov 2022 21:03:31 +0100 Received: from kreacher.localnet (unknown [213.134.188.205]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id D8CB46682BE; Mon, 7 Nov 2022 21:03:30 +0100 (CET) Authentication-Results: v370.home.net.pl; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: v370.home.net.pl; spf=fail smtp.mailfrom=rjwysocki.net From: "Rafael J. Wysocki" <rjw@rjwysocki.net> To: Alexandre Belloni <alexandre.belloni@bootlin.com>, linux-rtc@vger.kernel.org Cc: Linux ACPI <linux-acpi@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>, Linux PM <linux-pm@vger.kernel.org>, Zhang Rui <rui.zhang@intel.com>, Alessandro Zummo <a.zummo@towertech.it>, Andy Shevchenko <andriy.shevchenko@linux.intel.com> Subject: [PATCH v1 5/5] rtc: rtc-cmos: Disable ACPI RTC event on removal Date: Mon, 07 Nov 2022 21:03:06 +0100 Message-ID: <2219830.iZASKD2KPV@kreacher> In-Reply-To: <2276401.ElGaqSPkdT@kreacher> References: <2276401.ElGaqSPkdT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.188.205 X-CLIENT-HOSTNAME: 213.134.188.205 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvgedrvdekgddufedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppedvudefrddufeegrddukeekrddvtdehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudekkedrvddthedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepkedprhgtphhtthhopegrlhgvgigrnhgurhgvrdgsvghllhhonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtoheplhhinhhugidqrhhttgesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgv lhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheprgdriihumhhmohesthhofigvrhhtvggthhdrihhtpdhrtghpthhtoheprghnughrihihrdhshhgvvhgthhgvnhhkoheslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748869205566456875?= X-GMAIL-MSGID: =?utf-8?q?1748869205566456875?= |
Series |
rtc: rtc-cmos: Assorted ACPI-related cleanups and fixes
|
|
Commit Message
Rafael J. Wysocki
Nov. 7, 2022, 8:03 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Make cmos_do_remove() drop the ACPI RTC fixed event handler so as to prevent it from operating on stale data in case the event triggers after driver removal. While at it, make cmos_do_remove() also clear the driver data pointer of the device and make cmos_acpi_wake_setup() do that in the error path too. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> --- drivers/rtc/rtc-cmos.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Comments
On Mon, Nov 07, 2022 at 09:03:06PM +0100, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Make cmos_do_remove() drop the ACPI RTC fixed event handler so as to > prevent it from operating on stale data in case the event triggers > after driver removal. > > While at it, make cmos_do_remove() also clear the driver data pointer > of the device and make cmos_acpi_wake_setup() do that in the error path > too. ... > + dev_set_drvdata(dev, NULL); > + dev_set_drvdata(dev, NULL); Maybe I'm missing something, but the cmos_do_remove() is called by ->remove() callback of the real drivers (pnp and platform) and device core is already doing this. So, don't know why you need these calls to be explicit.
On Mon, Nov 07, 2022 at 09:03:06PM +0100, Rafael J. Wysocki wrote: ... > +static inline void acpi_rtc_event_cleanup(void) > +{ > + if (!acpi_disabled) Btw, other functions look like using if (acpi_disabled) return; pattern. Maybe here the same for the sake of consistency? > + acpi_remove_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler); > +}
On Mon, Nov 7, 2022 at 10:21 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Mon, Nov 07, 2022 at 09:03:06PM +0100, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > Make cmos_do_remove() drop the ACPI RTC fixed event handler so as to > > prevent it from operating on stale data in case the event triggers > > after driver removal. > > > > While at it, make cmos_do_remove() also clear the driver data pointer > > of the device and make cmos_acpi_wake_setup() do that in the error path > > too. > > ... > > > + dev_set_drvdata(dev, NULL); > > > + dev_set_drvdata(dev, NULL); > > Maybe I'm missing something, but the cmos_do_remove() is called by ->remove() > callback of the real drivers (pnp and platform) and device core is already > doing this. So, don't know why you need these calls to be explicit. Good point, but then I guess I should move this patch to the front, because the issue fixed by it may trigger a use-after-free in rtc_handler() already.
On Mon, Nov 7, 2022 at 10:28 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Mon, Nov 07, 2022 at 09:03:06PM +0100, Rafael J. Wysocki wrote: > > ... > > > +static inline void acpi_rtc_event_cleanup(void) > > +{ > > + if (!acpi_disabled) > > Btw, other functions look like using > > if (acpi_disabled) > return; > > pattern. Maybe here the same for the sake of consistency? > > > + acpi_remove_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler); > > +} > Well, it is more lines of code, but whatever.
Index: linux-pm/drivers/rtc/rtc-cmos.c =================================================================== --- linux-pm.orig/drivers/rtc/rtc-cmos.c +++ linux-pm/drivers/rtc/rtc-cmos.c @@ -798,6 +798,12 @@ static inline void acpi_rtc_event_setup( acpi_disable_event(ACPI_EVENT_RTC, 0); } +static inline void acpi_rtc_event_cleanup(void) +{ + if (!acpi_disabled) + acpi_remove_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler); +} + static void rtc_wake_on(struct device *dev) { acpi_clear_event(ACPI_EVENT_RTC); @@ -884,6 +890,10 @@ static inline void acpi_rtc_event_setup( { } +static inline void acpi_rtc_event_cleanup(void) +{ +} + static inline void cmos_acpi_wake_setup(struct device *dev) { } @@ -1109,6 +1119,7 @@ cleanup2: free_irq(rtc_irq, cmos_rtc.rtc); cleanup1: cmos_rtc.dev = NULL; + dev_set_drvdata(dev, NULL); cleanup0: if (RTC_IOMAPPED) release_region(ports->start, resource_size(ports)); @@ -1138,6 +1149,9 @@ static void cmos_do_remove(struct device hpet_unregister_irq_handler(cmos_interrupt); } + if (!dev_get_platdata(dev)) + acpi_rtc_event_cleanup(); + cmos->rtc = NULL; ports = cmos->iomem; @@ -1148,6 +1162,7 @@ static void cmos_do_remove(struct device cmos->iomem = NULL; cmos->dev = NULL; + dev_set_drvdata(dev, NULL); } static int cmos_aie_poweroff(struct device *dev)