lkundrak / rpms / kernel

Forked from rpms/kernel 4 years ago
Clone
51fdf98
Bugzilla: 1012674
51fdf98
Upstream-status: Queued for 3.16
51fdf98
51fdf98
From 5d9b5801af7cbeaab060fa07576ca6cd7dc3be89 Mon Sep 17 00:00:00 2001
51fdf98
From: Hans de Goede <hdegoede@redhat.com>
51fdf98
Date: Mon, 2 Jun 2014 17:41:03 +0200
51fdf98
Subject: [PATCH 06/14] acpi-video: Don't register acpi_video_resume notifier
51fdf98
 without backlight devices
51fdf98
51fdf98
If we're not going to be registering any backlight devices then
51fdf98
acpi_video_resume is always nop, so don't register it in that case.
51fdf98
51fdf98
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
51fdf98
51fdf98
--
51fdf98
51fdf98
Note to reviewers the changes to acpi_video_dev_register_backlight() only
51fdf98
remove the "if (!acpi_video_verify_backlight_support()) {" which surrounded
51fdf98
the entire body of the function, as that is checked earlier now.
51fdf98
---
51fdf98
 drivers/acpi/video.c | 139 +++++++++++++++++++++++++++------------------------
51fdf98
 1 file changed, 74 insertions(+), 65 deletions(-)
51fdf98
51fdf98
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
51fdf98
index f8bc5a755dda..a68313720c9c 100644
51fdf98
--- a/drivers/acpi/video.c
51fdf98
+++ b/drivers/acpi/video.c
51fdf98
@@ -150,6 +150,7 @@ struct acpi_video_enumerated_device {
51fdf98
 
51fdf98
 struct acpi_video_bus {
51fdf98
 	struct acpi_device *device;
51fdf98
+	bool backlight_registered;
51fdf98
 	u8 dos_setting;
51fdf98
 	struct acpi_video_enumerated_device *attached_array;
51fdf98
 	u8 attached_count;
51fdf98
@@ -1658,88 +1659,89 @@ acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
51fdf98
 
51fdf98
 static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
51fdf98
 {
51fdf98
-	if (acpi_video_verify_backlight_support()) {
51fdf98
-		struct backlight_properties props;
51fdf98
-		struct pci_dev *pdev;
51fdf98
-		acpi_handle acpi_parent;
51fdf98
-		struct device *parent = NULL;
51fdf98
-		int result;
51fdf98
-		static int count;
51fdf98
-		char *name;
51fdf98
-
51fdf98
-		result = acpi_video_init_brightness(device);
51fdf98
-		if (result)
51fdf98
-			return;
51fdf98
-		name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
51fdf98
-		if (!name)
51fdf98
-			return;
51fdf98
-		count++;
51fdf98
+	struct backlight_properties props;
51fdf98
+	struct pci_dev *pdev;
51fdf98
+	acpi_handle acpi_parent;
51fdf98
+	struct device *parent = NULL;
51fdf98
+	int result;
51fdf98
+	static int count;
51fdf98
+	char *name;
51fdf98
 
51fdf98
-		acpi_get_parent(device->dev->handle, &acpi_parent);
51fdf98
+	result = acpi_video_init_brightness(device);
51fdf98
+	if (result)
51fdf98
+		return;
51fdf98
+	name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
51fdf98
+	if (!name)
51fdf98
+		return;
51fdf98
+	count++;
51fdf98
 
51fdf98
-		pdev = acpi_get_pci_dev(acpi_parent);
51fdf98
-		if (pdev) {
51fdf98
-			parent = &pdev->dev;
51fdf98
-			pci_dev_put(pdev);
51fdf98
-		}
51fdf98
+	acpi_get_parent(device->dev->handle, &acpi_parent);
51fdf98
 
51fdf98
-		memset(&props, 0, sizeof(struct backlight_properties));
51fdf98
-		props.type = BACKLIGHT_FIRMWARE;
51fdf98
-		props.max_brightness = device->brightness->count - 3;
51fdf98
-		device->backlight = backlight_device_register(name,
51fdf98
-							      parent,
51fdf98
-							      device,
51fdf98
-							      &acpi_backlight_ops,
51fdf98
-							      &props;;
51fdf98
-		kfree(name);
51fdf98
-		if (IS_ERR(device->backlight))
51fdf98
-			return;
51fdf98
+	pdev = acpi_get_pci_dev(acpi_parent);
51fdf98
+	if (pdev) {
51fdf98
+		parent = &pdev->dev;
51fdf98
+		pci_dev_put(pdev);
51fdf98
+	}
51fdf98
 
51fdf98
-		/*
51fdf98
-		 * Save current brightness level in case we have to restore it
51fdf98
-		 * before acpi_video_device_lcd_set_level() is called next time.
51fdf98
-		 */
51fdf98
-		device->backlight->props.brightness =
51fdf98
-				acpi_video_get_brightness(device->backlight);
51fdf98
+	memset(&props, 0, sizeof(struct backlight_properties));
51fdf98
+	props.type = BACKLIGHT_FIRMWARE;
51fdf98
+	props.max_brightness = device->brightness->count - 3;
51fdf98
+	device->backlight = backlight_device_register(name,
51fdf98
+						      parent,
51fdf98
+						      device,
51fdf98
+						      &acpi_backlight_ops,
51fdf98
+						      &props;;
51fdf98
+	kfree(name);
51fdf98
+	if (IS_ERR(device->backlight))
51fdf98
+		return;
51fdf98
 
51fdf98
-		device->cooling_dev = thermal_cooling_device_register("LCD",
51fdf98
-					device->dev, &video_cooling_ops);
51fdf98
-		if (IS_ERR(device->cooling_dev)) {
51fdf98
-			/*
51fdf98
-			 * Set cooling_dev to NULL so we don't crash trying to
51fdf98
-			 * free it.
51fdf98
-			 * Also, why the hell we are returning early and
51fdf98
-			 * not attempt to register video output if cooling
51fdf98
-			 * device registration failed?
51fdf98
-			 * -- dtor
51fdf98
-			 */
51fdf98
-			device->cooling_dev = NULL;
51fdf98
-			return;
51fdf98
-		}
51fdf98
+	/*
51fdf98
+	 * Save current brightness level in case we have to restore it
51fdf98
+	 * before acpi_video_device_lcd_set_level() is called next time.
51fdf98
+	 */
51fdf98
+	device->backlight->props.brightness =
51fdf98
+			acpi_video_get_brightness(device->backlight);
51fdf98
 
51fdf98
-		dev_info(&device->dev->dev, "registered as cooling_device%d\n",
51fdf98
-			 device->cooling_dev->id);
51fdf98
-		result = sysfs_create_link(&device->dev->dev.kobj,
51fdf98
-				&device->cooling_dev->device.kobj,
51fdf98
-				"thermal_cooling");
51fdf98
-		if (result)
51fdf98
-			printk(KERN_ERR PREFIX "Create sysfs link\n");
51fdf98
-		result = sysfs_create_link(&device->cooling_dev->device.kobj,
51fdf98
-				&device->dev->dev.kobj, "device");
51fdf98
-		if (result)
51fdf98
-			printk(KERN_ERR PREFIX "Create sysfs link\n");
51fdf98
+	device->cooling_dev = thermal_cooling_device_register("LCD",
51fdf98
+				device->dev, &video_cooling_ops);
51fdf98
+	if (IS_ERR(device->cooling_dev)) {
51fdf98
+		/*
51fdf98
+		 * Set cooling_dev to NULL so we don't crash trying to free it.
51fdf98
+		 * Also, why the hell we are returning early and not attempt to
51fdf98
+		 * register video output if cooling device registration failed?
51fdf98
+		 * -- dtor
51fdf98
+		 */
51fdf98
+		device->cooling_dev = NULL;
51fdf98
+		return;
51fdf98
 	}
51fdf98
+
51fdf98
+	dev_info(&device->dev->dev, "registered as cooling_device%d\n",
51fdf98
+		 device->cooling_dev->id);
51fdf98
+	result = sysfs_create_link(&device->dev->dev.kobj,
51fdf98
+			&device->cooling_dev->device.kobj,
51fdf98
+			"thermal_cooling");
51fdf98
+	if (result)
51fdf98
+		printk(KERN_ERR PREFIX "Create sysfs link\n");
51fdf98
+	result = sysfs_create_link(&device->cooling_dev->device.kobj,
51fdf98
+			&device->dev->dev.kobj, "device");
51fdf98
+	if (result)
51fdf98
+		printk(KERN_ERR PREFIX "Create sysfs link\n");
51fdf98
 }
51fdf98
 
51fdf98
 static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
51fdf98
 {
51fdf98
 	struct acpi_video_device *dev;
51fdf98
 
51fdf98
+	if (!acpi_video_verify_backlight_support())
51fdf98
+		return 0;
51fdf98
+
51fdf98
 	mutex_lock(&video->device_list_lock);
51fdf98
 	list_for_each_entry(dev, &video->video_device_list, entry)
51fdf98
 		acpi_video_dev_register_backlight(dev);
51fdf98
 	mutex_unlock(&video->device_list_lock);
51fdf98
 
51fdf98
+	video->backlight_registered = true;
51fdf98
+
51fdf98
 	video->pm_nb.notifier_call = acpi_video_resume;
51fdf98
 	video->pm_nb.priority = 0;
51fdf98
 	return register_pm_notifier(&video->pm_nb);
51fdf98
@@ -1767,13 +1769,20 @@ static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device
51fdf98
 static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video)
51fdf98
 {
51fdf98
 	struct acpi_video_device *dev;
51fdf98
-	int error = unregister_pm_notifier(&video->pm_nb);
51fdf98
+	int error;
51fdf98
+
51fdf98
+	if (!video->backlight_registered)
51fdf98
+		return 0;
51fdf98
+
51fdf98
+	error = unregister_pm_notifier(&video->pm_nb);
51fdf98
 
51fdf98
 	mutex_lock(&video->device_list_lock);
51fdf98
 	list_for_each_entry(dev, &video->video_device_list, entry)
51fdf98
 		acpi_video_dev_unregister_backlight(dev);
51fdf98
 	mutex_unlock(&video->device_list_lock);
51fdf98
 
51fdf98
+	video->backlight_registered = false;
51fdf98
+
51fdf98
 	return error;
51fdf98
 }
51fdf98
 
51fdf98
-- 
51fdf98
1.9.0
51fdf98