[PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance

Rafael J. Wysocki posted 1 patch 3 days, 5 hours ago
drivers/acpi/hed.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
[PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance
Posted by Rafael J. Wysocki 3 days, 5 hours ago
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

There can be only one ACPI hardware event device (HED) in use at a time,
so acpi_hed_probe() uses static variable hed_handle for guarding against
adding a second HED instance, but there is no reason for that variable
to hold an ACPI handle, so change it to a bool one.

While at it also set that variable at the end of acpi_hed_probe() to
avouid the need to clear it when installing the ACPI notify handler
fails.

Note that ACPI devices are enumerated sequentially, so there's no need
for additional locking around the accesses to that variable.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/hed.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/hed.c b/drivers/acpi/hed.c
index 060e8d670f5d..4b5dc95922ea 100644
--- a/drivers/acpi/hed.c
+++ b/drivers/acpi/hed.c
@@ -22,7 +22,7 @@ static const struct acpi_device_id acpi_hed_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, acpi_hed_ids);
 
-static acpi_handle hed_handle;
+static bool hed_present;
 
 static BLOCKING_NOTIFIER_HEAD(acpi_hed_notify_list);
 
@@ -58,25 +58,25 @@ static int acpi_hed_probe(struct platform_device *pdev)
 		return -ENODEV;
 
 	/* Only one hardware error device */
-	if (hed_handle)
+	if (hed_present)
 		return -EINVAL;
-	hed_handle = device->handle;
 
 	err = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
 					      acpi_hed_notify, device);
 	if (err)
-		hed_handle = NULL;
+		return err;
 
-	return err;
+	hed_present = true;
+	return 0;
 }
 
 static void acpi_hed_remove(struct platform_device *pdev)
 {
 	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 
+	hed_present = false;
 	acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
 				       acpi_hed_notify);
-	hed_handle = NULL;
 }
 
 static struct platform_driver acpi_hed_driver = {
-- 
2.51.0