public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	Hans de Goede <hansg@kernel.org>,
	platform-driver-x86@vger.kernel.org,
	Kenneth Chan <kenneth.t.chan@gmail.com>
Subject: [PATCH v2 1/4] platform/x86: panasonic-laptop: Fix rollback path in acpi_pcc_hotkey_add()
Date: Wed, 18 Mar 2026 20:37:20 +0100	[thread overview]
Message-ID: <5060610.GXAFRqVoOG@rafael.j.wysocki> (raw)
In-Reply-To: <5979471.DvuYhMxLoT@rafael.j.wysocki>

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

The rollback ordering in acpi_pcc_hotkey_add() is different from the
cleanup ordering in acpi_pcc_hotkey_remove().  Moreover, the latter
calls pcc_unregister_optd_notifier() unconditionally while the former
never calls it and the OPTD notifier is only registered if pcc->platform
is not NULL.

Address that by:
 * moving the pcc_register_optd_notifier() call after the device_create_file()
   return value check,
 * adding a new label to the acpi_pcc_hotkey_add() rollback code for
   pcc_register_optd_notifier() error handling,
 * moving the pcc_unregister_optd_notifier() call in acpi_pcc_hotkey_remove()
   before the removal of the cdpower sysfs attribute.

Also update pcc_register_optd_notifier() to return an error when
acpi_install_notify_handler() fails.

Fixes: d5a81d8e864b ("platform/x86: panasonic-laptop: Add support for optical driver power in Y and W series")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2: New patch

---
 drivers/platform/x86/panasonic-laptop.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index d923ddaa4849..debab5916782 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -897,15 +897,15 @@ static int pcc_register_optd_notifier(struct pcc_acpi *pcc, char *node)
 	acpi_handle handle;
 
 	status = acpi_get_handle(NULL, node, &handle);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
 
-	if (ACPI_SUCCESS(status)) {
-		status = acpi_install_notify_handler(handle,
-				ACPI_SYSTEM_NOTIFY,
-				pcc_optd_notify, pcc);
-		if (ACPI_FAILURE(status))
-			pr_err("Failed to register notify on %s\n", node);
-	} else
+	status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
+					     pcc_optd_notify, pcc);
+	if (ACPI_FAILURE(status)) {
+		pr_err("Failed to register notify on %s\n", node);
 		return -ENODEV;
+	}
 
 	return 0;
 }
@@ -1093,9 +1093,12 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
 		}
 		result = device_create_file(&pcc->platform->dev,
 			&dev_attr_cdpower);
-		pcc_register_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
 		if (result)
 			goto out_platform;
+
+		result = pcc_register_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
+		if (result)
+			goto out_cdpower;
 	} else {
 		pcc->platform = NULL;
 	}
@@ -1103,6 +1106,8 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
 	i8042_install_filter(panasonic_i8042_filter, NULL);
 	return 0;
 
+out_cdpower:
+	device_remove_file(&pcc->platform->dev, &dev_attr_cdpower);
 out_platform:
 	platform_device_unregister(pcc->platform);
 out_sysfs:
@@ -1129,10 +1134,10 @@ static void acpi_pcc_hotkey_remove(struct acpi_device *device)
 	i8042_remove_filter(panasonic_i8042_filter);
 
 	if (pcc->platform) {
+		pcc_unregister_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
 		device_remove_file(&pcc->platform->dev, &dev_attr_cdpower);
 		platform_device_unregister(pcc->platform);
 	}
-	pcc_unregister_optd_notifier(pcc, "\\_SB.PCI0.EHCI.ERHB.OPTD");
 
 	sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
 
-- 
2.51.0





  reply	other threads:[~2026-03-18 19:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 19:32 [PATCH v2 0/4] platform/x86: panasonic-laptop: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
2026-03-18 19:37 ` Rafael J. Wysocki [this message]
2026-03-18 19:38 ` [PATCH v2 2/4] platform/x86: panasonic-laptop: Remove redundant checks from 3 functions Rafael J. Wysocki
2026-03-18 19:40 ` [PATCH v2 3/4] platform/x86: panasonic-laptop: Register ACPI notify handler directly Rafael J. Wysocki
2026-03-18 19:41 ` [PATCH v2 4/4] platform/x86: panasonic-laptop: Convert ACPI driver to a platform one Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5060610.GXAFRqVoOG@rafael.j.wysocki \
    --to=rafael@kernel.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=kenneth.t.chan@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox