From: Eric Engestrom <eric.engestrom@intel.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH libdrm 3/3] xf86drm: dedupe drmGetDeviceName() logic
Date: Wed, 19 Dec 2018 17:08:03 +0000 [thread overview]
Message-ID: <20181219170803.23452-3-eric.engestrom@intel.com> (raw)
In-Reply-To: <20181219170803.23452-1-eric.engestrom@intel.com>
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
---
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)
--
Cheers,
Eric
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-12-19 17:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-19 17:08 [PATCH libdrm 1/3] xf86drm: dedupe `#define`s Eric Engestrom
2018-12-19 17:08 ` [PATCH libdrm 2/3] xf86drm: use max size of drm node name instead of arbitrary size Eric Engestrom
2018-12-19 17:08 ` Eric Engestrom [this message]
2019-02-18 17:10 ` [PATCH libdrm 1/3] xf86drm: dedupe `#define`s Eric Engestrom
2019-02-19 11:46 ` Emil Velikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181219170803.23452-3-eric.engestrom@intel.com \
--to=eric.engestrom@intel.com \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox