Skip to contentSkip to conversation

drivers/acpi/acpi_video: check return value of acpi_get_parent()

PATCH In review Li Zhong 2 participants 3 messages Sep 2, 2022 – Sep 17, 2022 ACPI

lore
Share & tools
lore

Li Zhong

author
#0 lore raw

PATCH 1/1 drivers/acpi/acpi_video: check return value of acpi_get_parent()

Check return status of acpi_get_parent() to confirm whether it fails.

---
 drivers/acpi/acpi_video.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +5 -3
index 5cbe2196176d..5fca9a39b1a4 100644
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
+	// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  *  video.c - ACPI Video Driver
  *
@@ -1753,6 +1753,7 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
 	int result;
 	static int count;
 	char *name;
+	acpi_status status;
 
 	result = acpi_video_init_brightness(device);
 	if (result)
@@ -1766,8 +1767,9 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
 		return;
 	count++;
 
-	acpi_get_parent(device->dev->handle, &acpi_parent);
-
+	status = acpi_get_parent(device->dev->handle, &acpi_parent);
+	if (ACPI_FAILURE(status))
+		return;
 	pdev = acpi_get_pci_dev(acpi_parent);
 	if (pdev) {
 		parent = &pdev->dev;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 13 lines · Li Zhong

Check return status of acpi_get_parent() to confirm whether it fails.

---
 drivers/acpi/acpi_video.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +0 -0
index 5cbe2196176d..5fca9a39b1a4 100644

drivers/acpi/acpi_video.c line 1

Quoted 2 lines
drivers/acpi/acpi_video.c +1 -1
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
+       // SPDX-License-Identifier: GPL-2.0-or-later

This change surely is not intended?

Quoted 12 lines
drivers/acpi/acpi_video.c +1 -0
 /*
  *  video.c - ACPI Video Driver
  *
@@ -1753,6 +1753,7 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
        int result;
        static int count;
        char *name;
+       acpi_status status;
 
        result = acpi_video_init_brightness(device);
        if (result)

drivers/acpi/acpi_video.c static void acpi_video_dev_register_backlight(struct acpi_video_device *device) · line 1772

Quoted 8 lines
drivers/acpi/acpi_video.c +3 -2
@@ -1766,8 +1767,9 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
                return;
        count++;
 
-       acpi_get_parent(device->dev->handle, &acpi_parent);
-
+       status = acpi_get_parent(device->dev->handle, &acpi_parent);
+       if (ACPI_FAILURE(status))
+               return;

But device->dev->handle is known to be valid, so the only case in which acpi_get_parent() above can fail is when the given namespace object has no parent, in which case acpi_parent will be NULL, so that should be caught my the check below, shouldn't it?

Quoted 4 lines
drivers/acpi/acpi_video.c +0 -1
        pdev = acpi_get_pci_dev(acpi_parent);
        if (pdev) {
                parent = &pdev->dev;
--
author
#2 lore raw
Quoted 35 lines · Rafael J. Wysocki
Quoted 13 lines · Li Zhong

Check return status of acpi_get_parent() to confirm whether it fails.

---
 drivers/acpi/acpi_video.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +0 -0
index 5cbe2196176d..5fca9a39b1a4 100644

drivers/acpi/acpi_video.c line 1

Quoted 2 lines
drivers/acpi/acpi_video.c +1 -1
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
+       // SPDX-License-Identifier: GPL-2.0-or-later

This change surely is not intended?

Quoted 15 lines
drivers/acpi/acpi_video.c +1 -0
 /*
  *  video.c - ACPI Video Driver
  *
@@ -1753,6 +1753,7 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
        int result;
        static int count;
        char *name;
+       acpi_status status;
 
        result = acpi_video_init_brightness(device);
        if (result)
@@ -1766,8 +1767,9 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
                return;
        count++;
 
Quoted 15 lines

drivers/acpi/acpi_video.c static void acpi_video_dev_register_backlight(struct acpi_video_device *device) · line 1772

Quoted 5 lines
drivers/acpi/acpi_video.c +3 -2
-       acpi_get_parent(device->dev->handle, &acpi_parent);
-
+       status = acpi_get_parent(device->dev->handle, &acpi_parent);
+       if (ACPI_FAILURE(status))
+               return;

But device->dev->handle is known to be valid, so the only case in which acpi_get_parent() above can fail is when the given namespace object has no parent, in which case acpi_parent will be NULL, so that should be caught my the check below, shouldn't it?

Quoted 4 lines
drivers/acpi/acpi_video.c +0 -1
        pdev = acpi_get_pci_dev(acpi_parent);
        if (pdev) {
                parent = &pdev->dev;
--

That makes sense. Thank you!