From patchwork Wed Sep 9 17:21:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 7147641 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 11CA7BF036 for ; Wed, 9 Sep 2015 17:17:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 34EA720A13 for ; Wed, 9 Sep 2015 17:17:32 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2263620567 for ; Wed, 9 Sep 2015 17:17:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A76E6EC86; Wed, 9 Sep 2015 10:17:30 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by gabe.freedesktop.org (Postfix) with ESMTPS id D074D6EC86 for ; Wed, 9 Sep 2015 10:17:26 -0700 (PDT) Received: by wicfx3 with SMTP id fx3so165061924wic.1 for ; Wed, 09 Sep 2015 10:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2yOBq+IfraDxsTTVsm4GgwjqwgSmJCzRrn/6q1mtNF8=; b=RHmXfUmRdVcItR0vylHl+GlCj/p8zXtT9NlGgISPblP3/3y34gN8nHQvi11l/9/OAy WjsEUuNbxKcxIWTRGXYnCDfWvDj5QMGqvy8Rl2pD3yZZkuhXgyWZLA1BinqvThNvnA3M h/0KFEw2f0UTUik7L1Qux0/pn8+ygAT1DVeRIdSGJDauVChzdOow1gDtLSlQjNeDJrCD 7neqS4awsVMZldGeWTJXR5yy9IKwD9HCvz1xSYOyJj3TPSg0opHV7HHTi206NgXiR4ex obDKQVhF4r4dux8/MPhwYtpLTxUYj/+poAGPwpOIfsxa9L3xewA4hirgS0QpMlmlqBTM hBhw== X-Received: by 10.194.204.163 with SMTP id kz3mr59913619wjc.28.1441819045494; Wed, 09 Sep 2015 10:17:25 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by smtp.gmail.com with ESMTPSA id j7sm11257042wjz.11.2015.09.09.10.17.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Sep 2015 10:17:24 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 04/12] xf86drm: move the final linux specific bits out of drmGetDevices Date: Wed, 9 Sep 2015 18:21:25 +0100 Message-Id: <1441819293-25567-5-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> References: <1441819293-25567-1-git-send-email-emil.l.velikov@gmail.com> 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 Third and final piece of making drmGetDevices less crazy/ugly. Signed-off-by: Emil Velikov --- xf86drm.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 1174a64..dc1782d 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2835,21 +2835,23 @@ char *drmGetRenderDeviceNameFromFd(int fd) } #ifdef __linux__ -static int drmParseSubsystemType(const char *str) +static int drmParseSubsystemType(int maj, int min) { + char path[PATH_MAX + 1]; char link[PATH_MAX + 1] = ""; char *name; - if (readlink(str, link, PATH_MAX) < 0) - return -EINVAL; + snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem", + maj, min); + + if (readlink(path, link, PATH_MAX) < 0) + return -errno; name = strrchr(link, '/'); if (!name) return -EINVAL; - name++; - - if (strncmp(name, "pci", 3) == 0) + if (strncmp(name, "/pci", 4) == 0) return DRM_BUS_PCI; return -EINVAL; @@ -3001,7 +3003,6 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) struct dirent *dent = NULL; struct stat sbuf = {0}; char node[PATH_MAX + 1] = ""; - char path[PATH_MAX + 1] = ""; int node_type, subsystem_type; int maj, min; int ret, i = 0, j, node_count, device_count = 0; @@ -3033,9 +3034,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) continue; - snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem", - maj, min); - subsystem_type = drmParseSubsystemType(path); + subsystem_type = drmParseSubsystemType(maj, min); if (subsystem_type < 0) continue;