From patchwork Fri Nov 16 05:18:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Anholt X-Patchwork-Id: 10685553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FB6E14D6 for ; Fri, 16 Nov 2018 05:18:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 922B42D01E for ; Fri, 16 Nov 2018 05:18:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86D362D035; Fri, 16 Nov 2018 05:18:53 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 2B54E2D01E for ; Fri, 16 Nov 2018 05:18:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A257E6E70C; Fri, 16 Nov 2018 05:18:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from anholt.net (anholt.net [50.246.234.109]) by gabe.freedesktop.org (Postfix) with ESMTP id 92D9E6E70B for ; Fri, 16 Nov 2018 05:18:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by anholt.net (Postfix) with ESMTP id 5566810A135C; Thu, 15 Nov 2018 21:18:47 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at anholt.net Received: from anholt.net ([127.0.0.1]) by localhost (kingsolver.anholt.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id oN9a5qe2kR2U; Thu, 15 Nov 2018 21:18:44 -0800 (PST) Received: from eliezer.anholt.net (localhost [127.0.0.1]) by anholt.net (Postfix) with ESMTP id 59D6110A0F99; Thu, 15 Nov 2018 21:18:44 -0800 (PST) Received: by eliezer.anholt.net (Postfix, from userid 1000) id CC3092FE3700; Thu, 15 Nov 2018 21:18:43 -0800 (PST) From: Eric Anholt To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 1/2] Avoid hardcoded strlens in drmParseSubsystemType(). Date: Thu, 15 Nov 2018 21:18:42 -0800 Message-Id: <20181116051843.13569-1-eric@anholt.net> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Having people count characters is error-prone, when we could just have a computer do it. Reviewed-by: Eric Engestrom --- xf86drm.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 10df682b7870..60fbc49b3d35 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -59,6 +59,8 @@ #endif #include +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + /* Not all systems have MAP_FAILED defined */ #ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) @@ -2984,6 +2986,16 @@ static int drmParseSubsystemType(int maj, int min) char path[PATH_MAX + 1]; char link[PATH_MAX + 1] = ""; char *name; + struct { + const char *name; + int bus_type; + } bus_types[] = { + { "/pci", DRM_BUS_PCI }, + { "/usb", DRM_BUS_USB }, + { "/platform", DRM_BUS_PLATFORM }, + { "/host1x", DRM_BUS_HOST1X }, + { "/virtio", DRM_BUS_VIRTIO }, + }; snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/subsystem", maj, min); @@ -2995,20 +3007,10 @@ static int drmParseSubsystemType(int maj, int min) if (!name) return -EINVAL; - if (strncmp(name, "/pci", 4) == 0) - return DRM_BUS_PCI; - - if (strncmp(name, "/usb", 4) == 0) - return DRM_BUS_USB; - - if (strncmp(name, "/platform", 9) == 0) - return DRM_BUS_PLATFORM; - - if (strncmp(name, "/host1x", 7) == 0) - return DRM_BUS_HOST1X; - - if (strncmp(name, "/virtio", 7) == 0) - return DRM_BUS_VIRTIO; + for (unsigned i = 0; i < ARRAY_SIZE(bus_types); i++) { + if (strncmp(name, bus_types[i].name, strlen(bus_types[i].name)) == 0) + return bus_types[i].bus_type; + } return -EINVAL; #elif defined(__OpenBSD__) @@ -3149,7 +3151,6 @@ static int parse_separate_sysfs_files(int maj, int min, drmPciDeviceInfoPtr device, bool ignore_revision) { -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) static const char *attrs[] = { "revision", /* Older kernels are missing the file, so check for it first */ "vendor", From patchwork Fri Nov 16 05:18:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Anholt X-Patchwork-Id: 10685551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07D8A13BF for ; Fri, 16 Nov 2018 05:18:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E96F02D01E for ; Fri, 16 Nov 2018 05:18:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC1D92D035; Fri, 16 Nov 2018 05:18:51 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 6AC8E2D01E for ; Fri, 16 Nov 2018 05:18:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 36DC16E70B; Fri, 16 Nov 2018 05:18:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from anholt.net (anholt.net [50.246.234.109]) by gabe.freedesktop.org (Postfix) with ESMTP id B09766E70B for ; Fri, 16 Nov 2018 05:18:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by anholt.net (Postfix) with ESMTP id B939910A1376; Thu, 15 Nov 2018 21:18:45 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at anholt.net Received: from anholt.net ([127.0.0.1]) by localhost (kingsolver.anholt.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9sl8IErTUyhG; Thu, 15 Nov 2018 21:18:44 -0800 (PST) Received: from eliezer.anholt.net (localhost [127.0.0.1]) by anholt.net (Postfix) with ESMTP id 6E66C10A135C; Thu, 15 Nov 2018 21:18:44 -0800 (PST) Received: by eliezer.anholt.net (Postfix, from userid 1000) id CE8EE2FE36FF; Thu, 15 Nov 2018 21:18:43 -0800 (PST) From: Eric Anholt To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 2/2] drm: Attempt to parse SPI devices as platform bus devices. Date: Thu, 15 Nov 2018 21:18:43 -0800 Message-Id: <20181116051843.13569-2-eric@anholt.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116051843.13569-1-eric@anholt.net> References: <20181116051843.13569-1-eric@anholt.net> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP For ARM systems with tinydrm displays attached to SPI, the bus name is /spi but we have platform device info for the rest. Fixes eglInitialize() failures on hx8357d since the EGL_EXT_device_drm changes. Acked-by: Eric Engestrom --- xf86drm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xf86drm.c b/xf86drm.c index 60fbc49b3d35..71ad54baa5c8 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2993,6 +2993,7 @@ static int drmParseSubsystemType(int maj, int min) { "/pci", DRM_BUS_PCI }, { "/usb", DRM_BUS_USB }, { "/platform", DRM_BUS_PLATFORM }, + { "/spi", DRM_BUS_PLATFORM }, { "/host1x", DRM_BUS_HOST1X }, { "/virtio", DRM_BUS_VIRTIO }, };