dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] nouveau/bl: Assign different names to interfaces
@ 2016-04-15 14:57 Pierre Moreau
  2016-04-15 14:57 ` [PATCH 2/2] nouveau/bl: Do not register interface if Apple GMUX detected Pierre Moreau
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Pierre Moreau @ 2016-04-15 14:57 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	skeggsb-Re5JQEeQqe8AvxtiuMwx3w
  Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Currently, every backlight interface created by Nouveau uses the same name,
nv_backlight. This leads to a sysfs warning as it tries to create an already
existing folder. This patch adds a incremented number to the name, but keeps
the initial name as nv_backlight, to avoid possibly breaking userspace; the
second interface will be named nv_backlight1, and so on.

Fixes: fdo#86539
Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_backlight.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/drm/nouveau/nouveau_backlight.c b/drm/nouveau/nouveau_backlight.c
index 89eb460..914e2cb 100644
--- a/drm/nouveau/nouveau_backlight.c
+++ b/drm/nouveau/nouveau_backlight.c
@@ -36,6 +36,10 @@
 #include "nouveau_reg.h"
 #include "nouveau_encoder.h"
 
+static atomic_t bl_interfaces_nb = { 0 };
+
+static char* nouveau_get_backlight_name(void);
+
 static int
 nv40_get_intensity(struct backlight_device *bd)
 {
@@ -74,6 +78,7 @@ nv40_backlight_init(struct drm_connector *connector)
 	struct nvif_object *device = &drm->device.object;
 	struct backlight_properties props;
 	struct backlight_device *bd;
+	char* backlight_name = NULL;
 
 	if (!(nvif_rd32(device, NV40_PMC_BACKLIGHT) & NV40_PMC_BACKLIGHT_MASK))
 		return 0;
@@ -81,8 +86,14 @@ nv40_backlight_init(struct drm_connector *connector)
 	memset(&props, 0, sizeof(struct backlight_properties));
 	props.type = BACKLIGHT_RAW;
 	props.max_brightness = 31;
-	bd = backlight_device_register("nv_backlight", connector->kdev, drm,
+	backlight_name = nouveau_get_backlight_name();
+	bd = backlight_device_register(backlight_name , connector->kdev, drm,
 				       &nv40_bl_ops, &props);
+
+	// backlight_device_register() makes a copy
+	kfree(backlight_name);
+	backlight_name = NULL;
+
 	if (IS_ERR(bd))
 		return PTR_ERR(bd);
 	drm->backlight = bd;
@@ -182,6 +193,7 @@ nv50_backlight_init(struct drm_connector *connector)
 	struct backlight_properties props;
 	struct backlight_device *bd;
 	const struct backlight_ops *ops;
+	char* backlight_name = NULL;
 
 	nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
 	if (!nv_encoder) {
@@ -203,8 +215,14 @@ nv50_backlight_init(struct drm_connector *connector)
 	memset(&props, 0, sizeof(struct backlight_properties));
 	props.type = BACKLIGHT_RAW;
 	props.max_brightness = 100;
-	bd = backlight_device_register("nv_backlight", connector->kdev,
+	backlight_name = nouveau_get_backlight_name();
+	bd = backlight_device_register(backlight_name, connector->kdev,
 				       nv_encoder, ops, &props);
+
+	// backlight_device_register() makes a copy
+	kfree(backlight_name);
+	backlight_name = NULL;
+
 	if (IS_ERR(bd))
 		return PTR_ERR(bd);
 
@@ -252,3 +270,16 @@ nouveau_backlight_exit(struct drm_device *dev)
 		drm->backlight = NULL;
 	}
 }
+
+static char*
+nouveau_get_backlight_name(void)
+{
+	// 12 chars for "nv_backlight" + 2 for two digits number + 1 for '\0'
+	char* backlight_name = (char*)kmalloc(sizeof(char[15]), GFP_KERNEL);
+	const int nb = atomic_inc_return(&bl_interfaces_nb) - 1;
+	if (nb > 0 && nb < 100)
+		sprintf(backlight_name, "nv_backlight%d", nb);
+	else
+		sprintf(backlight_name, "nv_backlight");
+	return backlight_name;
+}
-- 
2.8.0

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2016-12-08  6:05 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-15 14:57 [PATCH 1/2] nouveau/bl: Assign different names to interfaces Pierre Moreau
2016-04-15 14:57 ` [PATCH 2/2] nouveau/bl: Do not register interface if Apple GMUX detected Pierre Moreau
2016-04-15 15:06 ` [Nouveau] [PATCH 1/2] nouveau/bl: Assign different names to interfaces Ilia Mirkin
     [not found]   ` <CAKb7Uvg3OxWuooJ=otSb1N_yRr1VcVgvH4K0DDy1zzDs9js4CA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-15 15:22     ` Pierre Moreau
     [not found]       ` <20160415152212.GA1697-Klvq+9u5igPhiM2yCknSfMugMpMbD5Xr@public.gmane.org>
2016-04-15 15:25         ` Ilia Mirkin
     [not found]           ` <CAKb7UviwNACmbjk-TpMzUKhvFO8ES+7fqn6UBvzJA_S-WYb96Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-15 18:40             ` Nick Tenney
2016-04-16 17:05               ` Pierre Moreau
2016-04-17  8:18   ` [Nouveau] " Pierre Moreau
2016-11-13 19:57 ` [PATCH v3 " Pierre Moreau
2016-11-13 19:57   ` [PATCH REBASED 2/2] Do not register interface if Apple GMUX detected Pierre Moreau
     [not found]     ` <20161113195707.4113-2-dev-WLoDKDh+7sdAfugRpC6u6w@public.gmane.org>
2016-11-14 10:19       ` Lukas Wunner
     [not found]   ` <20161113195707.4113-1-dev-WLoDKDh+7sdAfugRpC6u6w@public.gmane.org>
2016-11-14 10:17     ` [PATCH v3 1/2] nouveau/bl: Assign different names to interfaces Lukas Wunner
     [not found]       ` <20161114101740.GA9829-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2016-11-14 12:05         ` Pierre Moreau
     [not found] ` <1460732242-4161-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2016-04-17 19:57   ` [PATCH v2 " Pierre Moreau
     [not found]   ` <1460923062-10849-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2016-04-17 19:57     ` [PATCH REBASED 2/2] nouveau/bl: Do not register interface if Apple GMUX detected Pierre Moreau
2016-04-17 21:20       ` [Nouveau] " Lukas Wunner
     [not found]       ` <1460923062-10849-2-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2016-05-01 12:32         ` [PATCH v2 " Pierre Moreau
     [not found]           ` <1462105927-4328-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2016-05-01 12:35             ` Pierre Moreau
2016-12-07 23:57   ` [PATCH v4 1/2] nouveau/bl: Assign different names to interfaces Pierre Moreau
     [not found]     ` <20161207235709.3914-1-pierre.morrow-GANU6spQydw@public.gmane.org>
2016-12-07 23:57       ` [PATCH v3 2/2] Do not register interface if Apple GMUX detected Pierre Moreau
     [not found]         ` <20161207235709.3914-2-pierre.morrow-GANU6spQydw@public.gmane.org>
2016-12-08  6:05           ` Lukas Wunner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).