[PATCH 1/2] libbacklight: Fix backlight detection on recent kernels

Armin Krezović krezovic.armin at gmail.com
Wed Feb 8 12:55:25 UTC 2017


I don't know when it started happening, but recent kernels
give different names for pci_device and backlight parent.

pci_device is tied to the GPU PCI ID, while backlight parent
is tied to the connector, rather than the GPU itself.

On my system, I get the following (paths taken from actual
strings that were parsed):

pci_device: 0000:00:02.0
parent: card0-eDP-1

Obtained by commands equivalent to system calls used:

$ basename $(readlink /sys/devices/pci0000\:00/0000\:00\:02.0/drm/card0/device)
$ basename $(readlink /sys/class/backlight/intel_backlight/device)

This also fixes safe_strtoint usage, so it doesn't choke
on newline character.

Signed-off-by: Armin Krezović <krezovic.armin at gmail.com>
---
 libweston/libbacklight.c | 46 +++-------------------------------------------
 1 file changed, 3 insertions(+), 43 deletions(-)

diff --git a/libweston/libbacklight.c b/libweston/libbacklight.c
index 4bbc6db4..d814b583 100644
--- a/libweston/libbacklight.c
+++ b/libweston/libbacklight.c
@@ -67,6 +67,9 @@ static long backlight_get(struct backlight *backlight, char *node)
 		goto out;
 	}
 
+	if (buffer[ret - 1] == '\n')
+		buffer[ret - 1] = '\0';
+
 	if (!safe_strtoint(buffer, &value)) {
 		ret = -1;
 		goto out;
@@ -153,8 +156,6 @@ void backlight_destroy(struct backlight *backlight)
 struct backlight *backlight_init(struct udev_device *drm_device,
 				 uint32_t connector_type)
 {
-	const char *syspath = NULL;
-	char *pci_name = NULL;
 	char *chosen_path = NULL;
 	char *path = NULL;
 	DIR *backlights = NULL;
@@ -164,24 +165,6 @@ struct backlight *backlight_init(struct udev_device *drm_device,
 	struct backlight *backlight = NULL;
 	int ret;
 
-	if (!drm_device)
-		return NULL;
-
-	syspath = udev_device_get_syspath(drm_device);
-	if (!syspath)
-		return NULL;
-
-	if (asprintf(&path, "%s/%s", syspath, "device") < 0)
-		return NULL;
-
-	ret = readlink(path, buffer, sizeof(buffer) - 1);
-	free(path);
-	if (ret < 0)
-		return NULL;
-
-	buffer[ret] = '\0';
-	pci_name = basename(buffer);
-
 	if (connector_type <= 0)
 		return NULL;
 
@@ -207,7 +190,6 @@ struct backlight *backlight_init(struct udev_device *drm_device,
 
 	while ((entry = readdir(backlights))) {
 		char *backlight_path;
-		char *parent;
 		enum backlight_type entry_type;
 		int fd;
 
@@ -253,28 +235,6 @@ struct backlight *backlight_init(struct udev_device *drm_device,
 				goto out;
 		}
 
-		free (path);
-
-		if (asprintf(&path, "%s/%s", backlight_path, "device") < 0)
-			goto err;
-
-		ret = readlink(path, buffer, sizeof(buffer) - 1);
-
-		if (ret < 0)
-			goto out;
-
-		buffer[ret] = '\0';
-
-		parent = basename(buffer);
-
-		/* Perform matching for raw and firmware backlights -
-		   platform backlights have to be assumed to match */
-		if (entry_type == BACKLIGHT_RAW ||
-		    entry_type == BACKLIGHT_FIRMWARE) {
-			if (!(pci_name && !strcmp(pci_name, parent)))
-				goto out;
-		}
-
 		if (entry_type < type)
 			goto out;
 
-- 
2.11.1



More information about the wayland-devel mailing list