dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm 1/3] xf86drm: dedupe `#define`s
@ 2018-12-19 17:08 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
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Eric Engestrom @ 2018-12-19 17:08 UTC (permalink / raw)
  To: dri-devel

Adapted from a local patch carried by DragonFlyBSD:
https://github.com/DragonFlyBSD/DPorts/blob/bc056f88f7e4d468d8c9751f831a47b5ae1326e3/graphics/libdrm/files/patch-xf86drm.h

Patch is sadly uncredited (a bot authored the commit), so I can't credit
the author here either.

Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
---
 xf86drm.c | 10 ----------
 xf86drm.h | 16 ++++++++++------
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index 377ddf917d2cb902899a..07425b19897d00a19e8a 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -71,16 +71,6 @@
 
 #include "util_math.h"
 
-#ifdef __OpenBSD__
-#define DRM_PRIMARY_MINOR_NAME  "drm"
-#define DRM_CONTROL_MINOR_NAME  "drmC"
-#define DRM_RENDER_MINOR_NAME   "drmR"
-#else
-#define DRM_PRIMARY_MINOR_NAME  "card"
-#define DRM_CONTROL_MINOR_NAME  "controlD"
-#define DRM_RENDER_MINOR_NAME   "renderD"
-#endif
-
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 #define DRM_MAJOR 145
 #endif
diff --git a/xf86drm.h b/xf86drm.h
index 7773d71a803084e86920..18668ff3d40d7db55c95 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -78,17 +78,21 @@ extern "C" {
 
 #ifdef __OpenBSD__
 #define DRM_DIR_NAME  "/dev"
-#define DRM_DEV_NAME  "%s/drm%d"
-#define DRM_CONTROL_DEV_NAME  "%s/drmC%d"
-#define DRM_RENDER_DEV_NAME  "%s/drmR%d"
+#define DRM_PRIMARY_MINOR_NAME  "drm"
+#define DRM_CONTROL_MINOR_NAME  "drmC"
+#define DRM_RENDER_MINOR_NAME   "drmR"
 #else
 #define DRM_DIR_NAME  "/dev/dri"
-#define DRM_DEV_NAME  "%s/card%d"
-#define DRM_CONTROL_DEV_NAME  "%s/controlD%d"
-#define DRM_RENDER_DEV_NAME  "%s/renderD%d"
+#define DRM_PRIMARY_MINOR_NAME  "card"
+#define DRM_CONTROL_MINOR_NAME  "controlD"
+#define DRM_RENDER_MINOR_NAME   "renderD"
 #define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
 #endif
 
+#define DRM_DEV_NAME          "%s/" DRM_PRIMARY_MINOR_NAME "%d"
+#define DRM_CONTROL_DEV_NAME  "%s/" DRM_CONTROL_MINOR_NAME "%d"
+#define DRM_RENDER_DEV_NAME   "%s/" DRM_RENDER_MINOR_NAME  "%d"
+
 #define DRM_ERR_NO_DEVICE  (-1001)
 #define DRM_ERR_NO_ACCESS  (-1002)
 #define DRM_ERR_NOT_ROOT   (-1003)
-- 
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH libdrm 2/3] xf86drm: use max size of drm node name instead of arbitrary size
  2018-12-19 17:08 [PATCH libdrm 1/3] xf86drm: dedupe `#define`s Eric Engestrom
@ 2018-12-19 17:08 ` Eric Engestrom
  2018-12-19 17:08 ` [PATCH libdrm 3/3] xf86drm: dedupe drmGetDeviceName() logic Eric Engestrom
  2019-02-18 17:10 ` [PATCH libdrm 1/3] xf86drm: dedupe `#define`s Eric Engestrom
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Engestrom @ 2018-12-19 17:08 UTC (permalink / raw)
  To: dri-devel

Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
---
 xf86drm.c | 4 ++--
 xf86drm.h | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index 07425b19897d00a19e8a..95854e153ec7e9d264bc 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -317,7 +317,7 @@ static int drmOpenDevice(dev_t dev, int minor, int type)
 {
     stat_t          st;
     const char      *dev_name;
-    char            buf[64];
+    char            buf[DRM_NODE_NAME_MAX];
     int             fd;
     mode_t          devmode = DRM_DEV_MODE, serv_mode;
     gid_t           serv_group;
@@ -445,7 +445,7 @@ static int drmOpenDevice(dev_t dev, int minor, int type)
 static int drmOpenMinor(int minor, int create, int type)
 {
     int  fd;
-    char buf[64];
+    char buf[DRM_NODE_NAME_MAX];
     const char *dev_name;
 
     if (create)
diff --git a/xf86drm.h b/xf86drm.h
index 18668ff3d40d7db55c95..00fbdb35a9a8fb5e9f27 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -93,6 +93,14 @@ extern "C" {
 #define DRM_CONTROL_DEV_NAME  "%s/" DRM_CONTROL_MINOR_NAME "%d"
 #define DRM_RENDER_DEV_NAME   "%s/" DRM_RENDER_MINOR_NAME  "%d"
 
+#define DRM_NODE_NAME_MAX \
+    (sizeof(DRM_DIR_NAME) + 1 /* slash */ \
+     + MAX3(sizeof(DRM_PRIMARY_MINOR_NAME), \
+            sizeof(DRM_CONTROL_MINOR_NAME), \
+            sizeof(DRM_RENDER_MINOR_NAME)) \
+     + sizeof("64") /* highest possible node number */ \
+     + 1) /* NULL-terminator */
+
 #define DRM_ERR_NO_DEVICE  (-1001)
 #define DRM_ERR_NO_ACCESS  (-1002)
 #define DRM_ERR_NOT_ROOT   (-1003)
-- 
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH libdrm 3/3] xf86drm: dedupe drmGetDeviceName() logic
  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
  2019-02-18 17:10 ` [PATCH libdrm 1/3] xf86drm: dedupe `#define`s Eric Engestrom
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Engestrom @ 2018-12-19 17:08 UTC (permalink / raw)
  To: dri-devel

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH libdrm 1/3] xf86drm: dedupe `#define`s
  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 ` [PATCH libdrm 3/3] xf86drm: dedupe drmGetDeviceName() logic Eric Engestrom
@ 2019-02-18 17:10 ` Eric Engestrom
  2019-02-19 11:46   ` Emil Velikov
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Engestrom @ 2019-02-18 17:10 UTC (permalink / raw)
  To: dri-devel; +Cc: Emil Velikov

On Wednesday, 2018-12-19 17:08:01 +0000, Eric Engestrom wrote:
> Adapted from a local patch carried by DragonFlyBSD:
> https://github.com/DragonFlyBSD/DPorts/blob/bc056f88f7e4d468d8c9751f831a47b5ae1326e3/graphics/libdrm/files/patch-xf86drm.h
> 
> Patch is sadly uncredited (a bot authored the commit), so I can't credit
> the author here either.
> 
> Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>

Ping? :)

> ---
>  xf86drm.c | 10 ----------
>  xf86drm.h | 16 ++++++++++------
>  2 files changed, 10 insertions(+), 16 deletions(-)
> 
> diff --git a/xf86drm.c b/xf86drm.c
> index 377ddf917d2cb902899a..07425b19897d00a19e8a 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -71,16 +71,6 @@
>  
>  #include "util_math.h"
>  
> -#ifdef __OpenBSD__
> -#define DRM_PRIMARY_MINOR_NAME  "drm"
> -#define DRM_CONTROL_MINOR_NAME  "drmC"
> -#define DRM_RENDER_MINOR_NAME   "drmR"
> -#else
> -#define DRM_PRIMARY_MINOR_NAME  "card"
> -#define DRM_CONTROL_MINOR_NAME  "controlD"
> -#define DRM_RENDER_MINOR_NAME   "renderD"
> -#endif
> -
>  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
>  #define DRM_MAJOR 145
>  #endif
> diff --git a/xf86drm.h b/xf86drm.h
> index 7773d71a803084e86920..18668ff3d40d7db55c95 100644
> --- a/xf86drm.h
> +++ b/xf86drm.h
> @@ -78,17 +78,21 @@ extern "C" {
>  
>  #ifdef __OpenBSD__
>  #define DRM_DIR_NAME  "/dev"
> -#define DRM_DEV_NAME  "%s/drm%d"
> -#define DRM_CONTROL_DEV_NAME  "%s/drmC%d"
> -#define DRM_RENDER_DEV_NAME  "%s/drmR%d"
> +#define DRM_PRIMARY_MINOR_NAME  "drm"
> +#define DRM_CONTROL_MINOR_NAME  "drmC"
> +#define DRM_RENDER_MINOR_NAME   "drmR"
>  #else
>  #define DRM_DIR_NAME  "/dev/dri"
> -#define DRM_DEV_NAME  "%s/card%d"
> -#define DRM_CONTROL_DEV_NAME  "%s/controlD%d"
> -#define DRM_RENDER_DEV_NAME  "%s/renderD%d"
> +#define DRM_PRIMARY_MINOR_NAME  "card"
> +#define DRM_CONTROL_MINOR_NAME  "controlD"
> +#define DRM_RENDER_MINOR_NAME   "renderD"
>  #define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
>  #endif
>  
> +#define DRM_DEV_NAME          "%s/" DRM_PRIMARY_MINOR_NAME "%d"
> +#define DRM_CONTROL_DEV_NAME  "%s/" DRM_CONTROL_MINOR_NAME "%d"
> +#define DRM_RENDER_DEV_NAME   "%s/" DRM_RENDER_MINOR_NAME  "%d"
> +
>  #define DRM_ERR_NO_DEVICE  (-1001)
>  #define DRM_ERR_NO_ACCESS  (-1002)
>  #define DRM_ERR_NOT_ROOT   (-1003)
> -- 
> Cheers,
>   Eric
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH libdrm 1/3] xf86drm: dedupe `#define`s
  2019-02-18 17:10 ` [PATCH libdrm 1/3] xf86drm: dedupe `#define`s Eric Engestrom
@ 2019-02-19 11:46   ` Emil Velikov
  0 siblings, 0 replies; 5+ messages in thread
From: Emil Velikov @ 2019-02-19 11:46 UTC (permalink / raw)
  To: Eric Engestrom; +Cc: ML dri-devel

On Mon, 18 Feb 2019 at 17:10, Eric Engestrom <eric.engestrom@intel.com> wrote:
>
> On Wednesday, 2018-12-19 17:08:01 +0000, Eric Engestrom wrote:
> > Adapted from a local patch carried by DragonFlyBSD:
> > https://github.com/DragonFlyBSD/DPorts/blob/bc056f88f7e4d468d8c9751f831a47b5ae1326e3/graphics/libdrm/files/patch-xf86drm.h
> >
> > Patch is sadly uncredited (a bot authored the commit), so I can't credit
> > the author here either.
> >
> > Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
>
> Ping? :)
>
Thanks - saw this before but if fell through the cracks.

> > ---
> >  xf86drm.c | 10 ----------
> >  xf86drm.h | 16 ++++++++++------
> >  2 files changed, 10 insertions(+), 16 deletions(-)
> >
This adds more API for not so obvious reasons. I've got a series that
resolves this by folding the duplicated code into a few trivial
helpers.
Let me see if I can pull then out from the larger series and send them out.

Emil
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-19 11:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH libdrm 3/3] xf86drm: dedupe drmGetDeviceName() logic Eric Engestrom
2019-02-18 17:10 ` [PATCH libdrm 1/3] xf86drm: dedupe `#define`s Eric Engestrom
2019-02-19 11:46   ` Emil Velikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox