From patchwork Sat Dec 17 05:09:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Gray X-Patchwork-Id: 9478863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4376B60760 for ; Sat, 17 Dec 2016 05:10:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 246BA28653 for ; Sat, 17 Dec 2016 05:10:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0581A28662; Sat, 17 Dec 2016 05:10:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 047EF28653 for ; Sat, 17 Dec 2016 05:10:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1AEC06E129; Sat, 17 Dec 2016 05:10:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lechuck.jsg.id.au (jsg.id.au [210.15.216.215]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE7A86E083 for ; Sat, 17 Dec 2016 05:09:57 +0000 (UTC) Received: from largo.jsg.id.au (largo.jsg.id.au [192.168.1.43]) by lechuck.jsg.id.au (OpenSMTPD) with ESMTP id 47a4b5fe; Sat, 17 Dec 2016 16:09:53 +1100 (AEDT) Received: from largo.jsg.id.au (localhost [127.0.0.1]) by largo.jsg.id.au (OpenSMTPD) with ESMTP id e07f9c48; Sat, 17 Dec 2016 16:09:53 +1100 (AEDT) From: Jonathan Gray To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm v2 1/3] xf86drm: adjust device node path for minor base Date: Sat, 17 Dec 2016 16:09:51 +1100 Message-Id: <20161217050953.4876-1-jsg@jsg.id.au> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20161210055222.43795-1-jsg@jsg.id.au> References: <20161210055222.43795-1-jsg@jsg.id.au> Cc: emil.l.velikov@gmail.com 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-Virus-Scanned: ClamAV using ClamSMTP When constructing a path to a device node the minor number retrieved from fstat needs to have the offset of the node type subtracted from it. Control and render node types have the same major as the primary node but each has their own block of minor types at fixed offsets. v2: remove min < base test as requested by Emil Signed-off-by: Jonathan Gray --- xf86drm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index b5eeeb09..f6850aa2 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2838,7 +2838,7 @@ out_close_dir: char buf[PATH_MAX + 1]; const char *dev_name; unsigned int maj, min; - int n; + int n, base; if (fstat(fd, &sbuf)) return NULL; @@ -2863,7 +2863,11 @@ out_close_dir: return NULL; }; - n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min); + base = drmGetMinorBase(type); + if (base < 0) + return NULL; + + n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min - base); if (n == -1 || n >= sizeof(buf)) return NULL; @@ -3262,7 +3266,7 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device) char node[PATH_MAX + 1]; const char *dev_name; int node_type, subsystem_type; - int maj, min, n, ret; + int maj, min, n, ret, base; if (fd == -1 || device == NULL) return -EINVAL; @@ -3294,7 +3298,11 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device) return -EINVAL; }; - n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min); + base = drmGetMinorBase(node_type); + if (base < 0) + return -EINVAL; + + n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base); if (n == -1 || n >= PATH_MAX) return -errno; if (stat(node, &sbuf))