All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix typo for drmOpenByName
@ 2015-05-14  6:17 Guo Yejun
  2015-05-14 10:53 ` Daniel Kurtz
  2015-05-14 10:55 ` Emil Velikov
  0 siblings, 2 replies; 5+ messages in thread
From: Guo Yejun @ 2015-05-14  6:17 UTC (permalink / raw)
  To: dri-devel

Signed-off-by: Guo Yejun <yejun.guo@intel.com>
---
 xf86drm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index f7c45f8..5e7306e 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -635,9 +635,8 @@ static int drmOpenByName(const char *name, int type)
 		    drmFreeVersion(version);
 		    id = drmGetBusid(fd);
 		    drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL");
-		    if (!id || !*id) {
-			if (id)
-			    drmFreeBusid(id);
+		    if (id && *id) {
+			drmFreeBusid(id);
 			return fd;
 		    } else {
 			drmFreeBusid(id);
-- 
1.9.1

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

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

* Re: [PATCH] fix typo for drmOpenByName
  2015-05-14  6:17 [PATCH] fix typo for drmOpenByName Guo Yejun
@ 2015-05-14 10:53 ` Daniel Kurtz
  2015-05-14 12:38   ` Guo, Yejun
  2015-05-14 10:55 ` Emil Velikov
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel Kurtz @ 2015-05-14 10:53 UTC (permalink / raw)
  To: Guo Yejun; +Cc: dri-devel

NAK.  The original code is correct.

On Thu, May 14, 2015 at 2:17 PM, Guo Yejun <yejun.guo@intel.com> wrote:
> Signed-off-by: Guo Yejun <yejun.guo@intel.com>
> ---
>  xf86drm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index f7c45f8..5e7306e 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -635,9 +635,8 @@ static int drmOpenByName(const char *name, int type)
>                     drmFreeVersion(version);
>                     id = drmGetBusid(fd);
>                     drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL");
> -                   if (!id || !*id) {
> -                       if (id)
> -                           drmFreeBusid(id);

This code basically says:
If no string was returned (id == NULL), or an empty string (*id ==
NULL), aka "", then return fd and free id if it was an empty string.

> +                   if (id && *id) {
> +                       drmFreeBusid(id);
>                         return fd;
>                     } else {
>                         drmFreeBusid(id);
> --
> 1.9.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] fix typo for drmOpenByName
  2015-05-14  6:17 [PATCH] fix typo for drmOpenByName Guo Yejun
  2015-05-14 10:53 ` Daniel Kurtz
@ 2015-05-14 10:55 ` Emil Velikov
  1 sibling, 0 replies; 5+ messages in thread
From: Emil Velikov @ 2015-05-14 10:55 UTC (permalink / raw)
  To: Guo Yejun; +Cc: ML dri-devel

On 14 May 2015 at 07:17, Guo Yejun <yejun.guo@intel.com> wrote:
> Signed-off-by: Guo Yejun <yejun.guo@intel.com>
> ---
>  xf86drm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index f7c45f8..5e7306e 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -635,9 +635,8 @@ static int drmOpenByName(const char *name, int type)
>                     drmFreeVersion(version);
>                     id = drmGetBusid(fd);
>                     drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL");
> -                   if (!id || !*id) {
> -                       if (id)
> -                           drmFreeBusid(id);
> +                   if (id && *id) {
> +                       drmFreeBusid(id);
I believe that it's correct as is, at least according to the comment
just before the loop. What makes you think that it's a typo ?
Admittedly this function is not too pretty, but most of that is due to
it originating from the UMS era.

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

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

* RE: [PATCH] fix typo for drmOpenByName
  2015-05-14 10:53 ` Daniel Kurtz
@ 2015-05-14 12:38   ` Guo, Yejun
  2015-05-14 23:11     ` Emil Velikov
  0 siblings, 1 reply; 5+ messages in thread
From: Guo, Yejun @ 2015-05-14 12:38 UTC (permalink / raw)
  To: Daniel Kurtz; +Cc: dri-devel

Thanks  Daniel Kurtz  and Emil Velikov for the reply.

In general, drm APIs are invoked by user mode drivers, but, I want to mimic the behavior of driver in my unit test to create buffer objects. After do some searching, I wrote the following code in my unit test (user mode simple application based on libdrm). It does work in my old system (cannot go back to it and so do not know the exact version), but it failed when porting the unit test based on latest libdrm code. I stepped into function drmOpenByName and thought it is a typo.

    int fd = drmOpen("i915", NULL);
    drm_intel_bufmgr* bufmgr = drm_intel_bufmgr_gem_init(fd, 1024);
   drm_intel_bo * bo = drm_intel_bo_alloc(bufmgr,...);

After read the comment, looks like the above code is not used as expected. (I execute the utest together with X11 is running). 

Back to my original purpose, what's the correct way for me to create bo?   One possible way is to open("/dev/dri/renderDxxx"), but what should I do if the kernel version is too low to has this feature? 

Thanks.
Yejun

-----Original Message-----
From: djkurtz@google.com [mailto:djkurtz@google.com] On Behalf Of Daniel Kurtz
Sent: Thursday, May 14, 2015 6:53 PM
To: Guo, Yejun
Cc: dri-devel
Subject: Re: [PATCH] fix typo for drmOpenByName

NAK.  The original code is correct.

On Thu, May 14, 2015 at 2:17 PM, Guo Yejun <yejun.guo@intel.com> wrote:
> Signed-off-by: Guo Yejun <yejun.guo@intel.com>
> ---
>  xf86drm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index f7c45f8..5e7306e 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -635,9 +635,8 @@ static int drmOpenByName(const char *name, int type)
>                     drmFreeVersion(version);
>                     id = drmGetBusid(fd);
>                     drmMsg("drmGetBusid returned '%s'\n", id ? id : "NULL");
> -                   if (!id || !*id) {
> -                       if (id)
> -                           drmFreeBusid(id);

This code basically says:
If no string was returned (id == NULL), or an empty string (*id == NULL), aka "", then return fd and free id if it was an empty string.

> +                   if (id && *id) {
> +                       drmFreeBusid(id);
>                         return fd;
>                     } else {
>                         drmFreeBusid(id);
> --
> 1.9.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] fix typo for drmOpenByName
  2015-05-14 12:38   ` Guo, Yejun
@ 2015-05-14 23:11     ` Emil Velikov
  0 siblings, 0 replies; 5+ messages in thread
From: Emil Velikov @ 2015-05-14 23:11 UTC (permalink / raw)
  To: Guo, Yejun, Daniel Kurtz; +Cc: emil.l.velikov, dri-devel

On 14/05/15 12:38, Guo, Yejun wrote:
> Thanks  Daniel Kurtz  and Emil Velikov for the reply.
> 
> In general, drm APIs are invoked by user mode drivers, but, I want to mimic the behavior of driver in my unit test to create buffer objects. After do some searching, I wrote the following code in my unit test (user mode simple application based on libdrm). It does work in my old system (cannot go back to it and so do not know the exact version), but it failed when porting the unit test based on latest libdrm code. I stepped into function drmOpenByName and thought it is a typo.
> 
>     int fd = drmOpen("i915", NULL);
>     drm_intel_bufmgr* bufmgr = drm_intel_bufmgr_gem_init(fd, 1024);
>    drm_intel_bo * bo = drm_intel_bo_alloc(bufmgr,...);
> 
I honestly hope that your code has error checking and you've dropped
them here for simplicity.

> After read the comment, looks like the above code is not used as expected. (I execute the utest together with X11 is running). 
> 
> Back to my original purpose, what's the correct way for me to create bo?   One possible way is to open("/dev/dri/renderDxxx"), but what should I do if the kernel version is too low to has this feature? 
> 
Afaict there are a few solutions possible (listed in order of preference):
 1. Run your test without/outside X
 2. Opt for render nodes, but it again depends on exactly what your
program does*.
 3. Use open(...cardX...) directly, but you might need to set/drop
master depending your program.

Needless to say personally I would opt for 1 :)

-Emil

* You can confirm with the rest of the Intel crew if your program
requires master/root/auth from the drm and/or i915 module. Alternatively
you can check with the kernel

$ git grep "DRM_AUTH\|DRM_MASTER\|DRM_ROOT_ONLY" --
$(linux_top)/drivers/gpu/drm

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

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

end of thread, other threads:[~2015-05-14 22:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-14  6:17 [PATCH] fix typo for drmOpenByName Guo Yejun
2015-05-14 10:53 ` Daniel Kurtz
2015-05-14 12:38   ` Guo, Yejun
2015-05-14 23:11     ` Emil Velikov
2015-05-14 10:55 ` Emil Velikov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.