drm/i915/display: avoid warnings when registering dual panel backlight
authorjsg <jsg@openbsd.org>
Fri, 9 Sep 2022 04:36:03 +0000 (04:36 +0000)
committerjsg <jsg@openbsd.org>
Fri, 9 Sep 2022 04:36:03 +0000 (04:36 +0000)
From Arun R Murthy
7828b5d0080a4621973ab5c680c4df0bc6d96437 in linux 5.15.y/5.15.66
868e8e5156a1f8d92ca83fdbac6fd52798650792 in mainline linux

sys/dev/pci/drm/i915/display/intel_backlight.c

index 7d9415f..26e3889 100644 (file)
@@ -979,26 +979,26 @@ int intel_backlight_device_register(struct intel_connector *connector)
        if (!name)
                return -ENOMEM;
 
-       bd = backlight_device_register(name, connector->base.kdev, connector,
-                                      &intel_backlight_device_ops, &props);
-
-       /*
-        * Using the same name independent of the drm device or connector
-        * prevents registration of multiple backlight devices in the
-        * driver. However, we need to use the default name for backward
-        * compatibility. Use unique names for subsequent backlight devices as a
-        * fallback when the default name already exists.
-        */
-       if (IS_ERR(bd) && PTR_ERR(bd) == -EEXIST) {
+       bd = backlight_device_get_by_name(name);
+       if (bd) {
+#ifdef __linux__
+               put_device(&bd->dev);
+#endif
+               /*
+                * Using the same name independent of the drm device or connector
+                * prevents registration of multiple backlight devices in the
+                * driver. However, we need to use the default name for backward
+                * compatibility. Use unique names for subsequent backlight devices as a
+                * fallback when the default name already exists.
+                */
                kfree(name);
                name = kasprintf(GFP_KERNEL, "card%d-%s-backlight",
                                 i915->drm.primary->index, connector->base.name);
                if (!name)
                        return -ENOMEM;
-
-               bd = backlight_device_register(name, connector->base.kdev, connector,
-                                              &intel_backlight_device_ops, &props);
        }
+       bd = backlight_device_register(name, connector->base.kdev, connector,
+                                      &intel_backlight_device_ops, &props);
 
        if (IS_ERR(bd)) {
                drm_err(&i915->drm,