From patchwork Fri Apr 15 14:57:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Moreau X-Patchwork-Id: 8851741 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9AA6EBF29F for ; Fri, 15 Apr 2016 14:57:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B1AFE201F5 for ; Fri, 15 Apr 2016 14:57:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8F6402017E for ; Fri, 15 Apr 2016 14:57:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8B936EC75; Fri, 15 Apr 2016 14:57:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp3-g21.free.fr (smtp3-g21.free.fr [IPv6:2a01:e0c:1:1599::12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7F0696EC75; Fri, 15 Apr 2016 14:57:35 +0000 (UTC) Received: from Normandy.alltele.se (unknown [87.96.161.47]) (Authenticated sender: pierre.morrow) by smtp3-g21.free.fr (Postfix) with ESMTPSA id BAD2C13F89F; Fri, 15 Apr 2016 14:56:59 +0200 (CEST) From: Pierre Moreau To: nouveau@lists.freedesktop.org, skeggsb@gmail.com Subject: [PATCH 1/2] nouveau/bl: Assign different names to interfaces Date: Fri, 15 Apr 2016 16:57:21 +0200 Message-Id: <1460732242-4161-1-git-send-email-pierre.morrow@free.fr> X-Mailer: git-send-email 2.8.0 Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; +}