Skip to contentSkip to conversation

acpi: don't free non-existant backlight in acpi video module

PATCH In review [email protected] 3 participants 4 messages Jul 12, 2009 – Jul 14, 2009 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 acpi: don't free non-existant backlight in acpi video module

From: Keith Packard <[email protected]>

acpi_video_put_one_device was attempting to remove sysfs entries and unregister a backlight device without first checking that said backlight device structure had been created.

---
 drivers/acpi/video.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/video.c +5 -2
index 8851315..60ea984 100644
@@ -2004,8 +2004,11 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
 	status = acpi_remove_notify_handler(device->dev->handle,
 					    ACPI_DEVICE_NOTIFY,
 					    acpi_video_device_notify);
-	sysfs_remove_link(&device->backlight->dev.kobj, "device");
-	backlight_device_unregister(device->backlight);
+	if (device->backlight) {
+		sysfs_remove_link(&device->backlight->dev.kobj, "device");
+		backlight_device_unregister(device->backlight);
+		device->backlight = NULL;
+	}
 	if (device->cdev) {
 		sysfs_remove_link(&device->dev->dev.kobj,
 				  "thermal_cooling");
Signature · 1 line
1.6.3.3
Acked-by on v1 1/2
#1 lore raw
Quoted 7 lines · On Sun, 2009-07-12 at 14:47 +0800, [email protected] wrote:

From: Keith Packard <[email protected]>

acpi_video_put_one_device was attempting to remove sysfs entries and unregister a backlight device without first checking that said backlight device structure had been created.

Quoted 22 lines
---
 drivers/acpi/video.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/video.c +5 -2
index 8851315..60ea984 100644
@@ -2004,8 +2004,11 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
 	status = acpi_remove_notify_handler(device->dev->handle,
 					    ACPI_DEVICE_NOTIFY,
 					    acpi_video_device_notify);
-	sysfs_remove_link(&device->backlight->dev.kobj, "device");
-	backlight_device_unregister(device->backlight);
+	if (device->backlight) {
+		sysfs_remove_link(&device->backlight->dev.kobj, "device");
+		backlight_device_unregister(device->backlight);
+		device->backlight = NULL;
+	}
 	if (device->cdev) {
 		sysfs_remove_link(&device->dev->dev.kobj,
 				  "thermal_cooling");
#2 lore raw
In reply to [email protected]
Quoted 2 lines

acpi: don't free non-existant backlight in acpi video module

"existent" :)

Quoted 19 lines · On Sat, 11 Jul 2009 23:47:31 -0700 [email protected] wrote:

From: Keith Packard <[email protected]>

acpi_video_put_one_device was attempting to remove sysfs entries and unregister a backlight device without first checking that said backlight device structure had been created.

---
 drivers/acpi/video.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/video.c +0 -0
index 8851315..60ea984 100644
@@ -2004,8 +2004,11 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
 	status = acpi_remove_notify_handler(device->dev->handle,
 					    ACPI_DEVICE_NOTIFY,
 					    acpi_video_device_notify);

drivers/acpi/video.c static int acpi_video_bus_put_one_device(struct acpi_video_device *device) · line 2014

Quoted 10 lines
drivers/acpi/video.c +5 -2
-	sysfs_remove_link(&device->backlight->dev.kobj, "device");
-	backlight_device_unregister(device->backlight);
+	if (device->backlight) {
+		sysfs_remove_link(&device->backlight->dev.kobj, "device");
+		backlight_device_unregister(device->backlight);
+		device->backlight = NULL;
+	}
 	if (device->cdev) {
 		sysfs_remove_link(&device->dev->dev.kobj,
 				  "thermal_cooling");

um, OK.

Under which circumstances was this observed?

For symmetry we could instead test acpi_video_backlight_support() here.

The patch assumes that someone initially zeroed device->backlight. Is that true and reliable? If so, is the

	memset(&device->cap, 0, sizeof(device->cap));

in acpi_video_device_find_cap() needed?

Where's [patch 2/2], btw?

#3 lore raw
Quoted 39 lines · Andrew Morton
Quoted 1 line

acpi: don't free non-existant backlight in acpi video module

"existent" :)

Quoted 19 lines · On Sat, 11 Jul 2009 23:47:31 -0700 [email protected] wrote:

From: Keith Packard <[email protected]>

acpi_video_put_one_device was attempting to remove sysfs entries and unregister a backlight device without first checking that said backlight device structure had been created.

---
 drivers/acpi/video.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/video.c +0 -0
index 8851315..60ea984 100644
@@ -2004,8 +2004,11 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
 	status = acpi_remove_notify_handler(device->dev->handle,
 					    ACPI_DEVICE_NOTIFY,
 					    acpi_video_device_notify);

drivers/acpi/video.c static int acpi_video_bus_put_one_device(struct acpi_video_device *device) · line 2014

Quoted 10 lines
drivers/acpi/video.c +5 -2
-	sysfs_remove_link(&device->backlight->dev.kobj, "device");
-	backlight_device_unregister(device->backlight);
+	if (device->backlight) {
+		sysfs_remove_link(&device->backlight->dev.kobj, "device");
+		backlight_device_unregister(device->backlight);
+		device->backlight = NULL;
+	}
 	if (device->cdev) {
 		sysfs_remove_link(&device->dev->dev.kobj,
 				  "thermal_cooling");

um, OK.

Quoted 2 lines

Under which circumstances was this observed?

Only part of the ACPI video devices support backlight switching. device->backlight is NULL for many ACPI video devices, like, CRT, TV, DVI, etc.

Quoted 2 lines

For symmetry we could instead test acpi_video_backlight_support() here.

No.
device->backlight is NULL for the devices that declare to support backlight control while provides INVALID ACPI backlight control methods.

Quoted 2 lines

The patch assumes that someone initially zeroed device->backlight. Is that true and reliable?

yes.

Quoted 6 lines

If so, is the

	memset(&device->cap, 0, sizeof(device->cap));

in acpi_video_device_find_cap() needed?

right. IMO, we can remove this.
patch attached.

thanks,
rui

device->cap and video->cap is zerod initially so we don't need to clear it again.

---
 drivers/acpi/video.c |    4 ----
 1 file changed, 4 deletions(-)
drivers/acpi/video.c +0 -4
Index: linux-2.6/drivers/acpi/video.c
===================================================================
@@ -934,9 +934,6 @@ static void acpi_video_device_find_cap(s
 {
 	acpi_handle h_dummy1;
 
-
-	memset(&device->cap, 0, sizeof(device->cap));
-
 	if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
 		device->cap._ADR = 1;
 	}
@@ -1039,7 +1036,6 @@ static void acpi_video_bus_find_cap(stru
 {
 	acpi_handle h_dummy1;
 
-	memset(&video->cap, 0, sizeof(video->cap));
 	if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
 		video->cap._DOS = 1;
 	}