From patchwork Wed Dec 19 17:08:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Engestrom X-Patchwork-Id: 10737797 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 EF2976C5 for ; Wed, 19 Dec 2018 17:09:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8171297EB for ; Wed, 19 Dec 2018 17:09:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC5E92B50A; Wed, 19 Dec 2018 17:09:32 +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 3D856297EB for ; Wed, 19 Dec 2018 17:09:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 601216F0E5; Wed, 19 Dec 2018 17:09:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id D72076F0E5 for ; Wed, 19 Dec 2018 17:09:22 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2018 09:09:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,373,1539673200"; d="scan'208";a="260775739" Received: from kszypryt-mobl.ger.corp.intel.com (HELO eengestr-dev.ger.corp.intel.com) ([10.251.83.167]) by orsmga004.jf.intel.com with ESMTP; 19 Dec 2018 09:09:21 -0800 From: Eric Engestrom To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 3/3] xf86drm: dedupe drmGetDeviceName() logic Date: Wed, 19 Dec 2018 17:08:03 +0000 Message-Id: <20181219170803.23452-3-eric.engestrom@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181219170803.23452-1-eric.engestrom@intel.com> References: <20181219170803.23452-1-eric.engestrom@intel.com> MIME-Version: 1.0 Organization: Intel Corp UK 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 Signed-off-by: Eric Engestrom --- xf86drm.c | 86 +++++++++++++++---------------------------------------- 1 file changed, 23 insertions(+), 63 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 95854e153ec7e9d264bc..f8e4d11b8c6886d6a6b8 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -300,6 +300,19 @@ static int chown_check_return(const char *path, uid_t owner, gid_t group) } #endif +static const char *drmGetDeviceName(int type) +{ + switch (type) { + case DRM_NODE_PRIMARY: + return DRM_DEV_NAME; + case DRM_NODE_CONTROL: + return DRM_CONTROL_DEV_NAME; + case DRM_NODE_RENDER: + return DRM_RENDER_DEV_NAME; + } + return NULL; +} + /** * Open the DRM device, creating it if necessary. * @@ -316,7 +329,7 @@ static int chown_check_return(const char *path, uid_t owner, gid_t group) static int drmOpenDevice(dev_t dev, int minor, int type) { stat_t st; - const char *dev_name; + const char *dev_name = drmGetDeviceName(type); char buf[DRM_NODE_NAME_MAX]; int fd; mode_t devmode = DRM_DEV_MODE, serv_mode; @@ -327,19 +340,8 @@ static int drmOpenDevice(dev_t dev, int minor, int type) gid_t group = DRM_DEV_GID; #endif - switch (type) { - case DRM_NODE_PRIMARY: - dev_name = DRM_DEV_NAME; - break; - case DRM_NODE_CONTROL: - dev_name = DRM_CONTROL_DEV_NAME; - break; - case DRM_NODE_RENDER: - dev_name = DRM_RENDER_DEV_NAME; - break; - default: + if (!dev_name) return -EINVAL; - }; sprintf(buf, dev_name, DRM_DIR_NAME, minor); drmMsg("drmOpenDevice: node name is %s\n", buf); @@ -446,24 +448,13 @@ static int drmOpenMinor(int minor, int create, int type) { int fd; char buf[DRM_NODE_NAME_MAX]; - const char *dev_name; + const char *dev_name = drmGetDeviceName(type); if (create) return drmOpenDevice(makedev(DRM_MAJOR, minor), minor, type); - switch (type) { - case DRM_NODE_PRIMARY: - dev_name = DRM_DEV_NAME; - break; - case DRM_NODE_CONTROL: - dev_name = DRM_CONTROL_DEV_NAME; - break; - case DRM_NODE_RENDER: - dev_name = DRM_RENDER_DEV_NAME; - break; - default: + if (!dev_name) return -EINVAL; - }; sprintf(buf, dev_name, DRM_DIR_NAME, minor); if ((fd = open(buf, O_RDWR | O_CLOEXEC, 0)) >= 0) @@ -2874,7 +2865,7 @@ static char *drmGetMinorNameForFD(int fd, int type) #else struct stat sbuf; char buf[PATH_MAX + 1]; - const char *dev_name; + const char *dev_name = drmGetDeviceName(type); unsigned int maj, min; int n, base; @@ -2887,19 +2878,8 @@ static char *drmGetMinorNameForFD(int fd, int type) if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return NULL; - switch (type) { - case DRM_NODE_PRIMARY: - dev_name = DRM_DEV_NAME; - break; - case DRM_NODE_CONTROL: - dev_name = DRM_CONTROL_DEV_NAME; - break; - case DRM_NODE_RENDER: - dev_name = DRM_RENDER_DEV_NAME; - break; - default: + if (!dev_name) return NULL; - }; base = drmGetMinorBase(type); if (base < 0) @@ -3856,19 +3836,9 @@ drm_public int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device) if (node_type == -1) return -ENODEV; - switch (node_type) { - case DRM_NODE_PRIMARY: - dev_name = DRM_DEV_NAME; - break; - case DRM_NODE_CONTROL: - dev_name = DRM_CONTROL_DEV_NAME; - break; - case DRM_NODE_RENDER: - dev_name = DRM_RENDER_DEV_NAME; - break; - default: + dev_name = drmGetDeviceName(node_type); + if (!dev_name) return -EINVAL; - }; base = drmGetMinorBase(node_type); if (base < 0) @@ -4109,19 +4079,9 @@ drm_public char *drmGetDeviceNameFromFd2(int fd) if (node_type == -1) return NULL; - switch (node_type) { - case DRM_NODE_PRIMARY: - dev_name = DRM_DEV_NAME; - break; - case DRM_NODE_CONTROL: - dev_name = DRM_CONTROL_DEV_NAME; - break; - case DRM_NODE_RENDER: - dev_name = DRM_RENDER_DEV_NAME; - break; - default: + dev_name = drmGetDeviceName(node_type); + if (!dev_name) return NULL; - }; base = drmGetMinorBase(node_type); if (base < 0)