dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libdrm] freedreno: zero is a valid fd number, treat it as such
@ 2015-07-13 13:39 Emil Velikov
  2015-07-13 13:52 ` Emil Velikov
  0 siblings, 1 reply; 4+ messages in thread
From: Emil Velikov @ 2015-07-13 13:39 UTC (permalink / raw)
  To: dri-devel; +Cc: freedreno, emil.l.velikov

Abeit quite unlikely to get hit by this bug here, let just fix it.

Cc: freedreno@lists.freedesktop.org
Cc: Rob Clark <robdclark@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 freedreno/freedreno_bo.c | 6 +++---
 freedreno/kgsl/kgsl_bo.c | 1 +
 freedreno/msm/msm_bo.c   | 1 +
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/freedreno/freedreno_bo.c b/freedreno/freedreno_bo.c
index 517a2f8..ffaef4c 100644
--- a/freedreno/freedreno_bo.c
+++ b/freedreno/freedreno_bo.c
@@ -285,9 +285,9 @@ void fd_bo_del(struct fd_bo *bo)
 	if (!atomic_dec_and_test(&bo->refcnt))
 		return;
 
-	if (bo->fd) {
+	if (bo->fd >= 0) {
 		close(bo->fd);
-		bo->fd = 0;
+		bo->fd = -1;
 	}
 
 	pthread_mutex_lock(&table_lock);
@@ -372,7 +372,7 @@ uint32_t fd_bo_handle(struct fd_bo *bo)
 
 int fd_bo_dmabuf(struct fd_bo *bo)
 {
-	if (!bo->fd) {
+	if (bo->fd >= 0) {
 		struct drm_prime_handle req = {
 				.handle = bo->handle,
 				.flags = DRM_CLOEXEC,
diff --git a/freedreno/kgsl/kgsl_bo.c b/freedreno/kgsl/kgsl_bo.c
index 15c3ff5..3407c76 100644
--- a/freedreno/kgsl/kgsl_bo.c
+++ b/freedreno/kgsl/kgsl_bo.c
@@ -168,6 +168,7 @@ drm_private struct fd_bo * kgsl_bo_from_handle(struct fd_device *dev,
 
 	bo = &kgsl_bo->base;
 	bo->funcs = &funcs;
+	bo->fd = -1;
 
 	for (i = 0; i < ARRAY_SIZE(kgsl_bo->list); i++)
 		list_inithead(&kgsl_bo->list[i]);
diff --git a/freedreno/msm/msm_bo.c b/freedreno/msm/msm_bo.c
index fbd82df..3f5b6d0 100644
--- a/freedreno/msm/msm_bo.c
+++ b/freedreno/msm/msm_bo.c
@@ -137,6 +137,7 @@ drm_private struct fd_bo * msm_bo_from_handle(struct fd_device *dev,
 
 	bo = &msm_bo->base;
 	bo->funcs = &funcs;
+	bo->fd = -1;
 
 	for (i = 0; i < ARRAY_SIZE(msm_bo->list); i++)
 		list_inithead(&msm_bo->list[i]);
-- 
2.4.5

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

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

* [PATCH libdrm] freedreno: zero is a valid fd number, treat it as such
  2015-07-13 13:39 [PATCH libdrm] freedreno: zero is a valid fd number, treat it as such Emil Velikov
@ 2015-07-13 13:52 ` Emil Velikov
  2015-07-14  8:14   ` Thierry Reding
  0 siblings, 1 reply; 4+ messages in thread
From: Emil Velikov @ 2015-07-13 13:52 UTC (permalink / raw)
  To: dri-devel; +Cc: freedreno, emil.l.velikov

Abeit quite unlikely to get hit by this bug here, let just fix it.

v2: Correct conditional (do not call ioctl(DRM_IOCTL_PRIME_HANDLE_TO_FD)
when we already have the fd).

Cc: freedreno@lists.freedesktop.org
Cc: Rob Clark <robdclark@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 freedreno/freedreno_bo.c | 6 +++---
 freedreno/kgsl/kgsl_bo.c | 1 +
 freedreno/msm/msm_bo.c   | 1 +
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/freedreno/freedreno_bo.c b/freedreno/freedreno_bo.c
index 517a2f8..eec218c 100644
--- a/freedreno/freedreno_bo.c
+++ b/freedreno/freedreno_bo.c
@@ -285,9 +285,9 @@ void fd_bo_del(struct fd_bo *bo)
 	if (!atomic_dec_and_test(&bo->refcnt))
 		return;
 
-	if (bo->fd) {
+	if (bo->fd >= 0) {
 		close(bo->fd);
-		bo->fd = 0;
+		bo->fd = -1;
 	}
 
 	pthread_mutex_lock(&table_lock);
@@ -372,7 +372,7 @@ uint32_t fd_bo_handle(struct fd_bo *bo)
 
 int fd_bo_dmabuf(struct fd_bo *bo)
 {
-	if (!bo->fd) {
+	if (bo->fd < 0) {
 		struct drm_prime_handle req = {
 				.handle = bo->handle,
 				.flags = DRM_CLOEXEC,
diff --git a/freedreno/kgsl/kgsl_bo.c b/freedreno/kgsl/kgsl_bo.c
index 15c3ff5..3407c76 100644
--- a/freedreno/kgsl/kgsl_bo.c
+++ b/freedreno/kgsl/kgsl_bo.c
@@ -168,6 +168,7 @@ drm_private struct fd_bo * kgsl_bo_from_handle(struct fd_device *dev,
 
 	bo = &kgsl_bo->base;
 	bo->funcs = &funcs;
+	bo->fd = -1;
 
 	for (i = 0; i < ARRAY_SIZE(kgsl_bo->list); i++)
 		list_inithead(&kgsl_bo->list[i]);
diff --git a/freedreno/msm/msm_bo.c b/freedreno/msm/msm_bo.c
index fbd82df..3f5b6d0 100644
--- a/freedreno/msm/msm_bo.c
+++ b/freedreno/msm/msm_bo.c
@@ -137,6 +137,7 @@ drm_private struct fd_bo * msm_bo_from_handle(struct fd_device *dev,
 
 	bo = &msm_bo->base;
 	bo->funcs = &funcs;
+	bo->fd = -1;
 
 	for (i = 0; i < ARRAY_SIZE(msm_bo->list); i++)
 		list_inithead(&msm_bo->list[i]);
-- 
2.4.5

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

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

* Re: [PATCH libdrm] freedreno: zero is a valid fd number, treat it as such
  2015-07-13 13:52 ` Emil Velikov
@ 2015-07-14  8:14   ` Thierry Reding
  2015-07-14 13:50     ` Emil Velikov
  0 siblings, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2015-07-14  8:14 UTC (permalink / raw)
  To: Emil Velikov; +Cc: freedreno, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 1058 bytes --]

On Mon, Jul 13, 2015 at 02:52:09PM +0100, Emil Velikov wrote:
> Abeit quite unlikely to get hit by this bug here, let just fix it.
> 
> v2: Correct conditional (do not call ioctl(DRM_IOCTL_PRIME_HANDLE_TO_FD)
> when we already have the fd).
> 
> Cc: freedreno@lists.freedesktop.org
> Cc: Rob Clark <robdclark@gmail.com>
> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
> ---
>  freedreno/freedreno_bo.c | 6 +++---
>  freedreno/kgsl/kgsl_bo.c | 1 +
>  freedreno/msm/msm_bo.c   | 1 +
>  3 files changed, 5 insertions(+), 3 deletions(-)

I think there's another one in kgsl_pipe_destroy(). With that fixed,
this is:

Reviewed-by: Thierry Reding <treding@nvidia.com>

There are also a couple more like this in omap_drm.c (I suspect Rob
copied from that =) that we may want to fix at the same time (in the
same patch or a separate one).

There's also a few places where an fd is compared to -1 directly, which
should be okay, but might be worth making consistent. I can send a patch
if you're not pedantic enough. =)

Thierry

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

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

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

* Re: [PATCH libdrm] freedreno: zero is a valid fd number, treat it as such
  2015-07-14  8:14   ` Thierry Reding
@ 2015-07-14 13:50     ` Emil Velikov
  0 siblings, 0 replies; 4+ messages in thread
From: Emil Velikov @ 2015-07-14 13:50 UTC (permalink / raw)
  To: Thierry Reding; +Cc: freedreno, ML dri-devel

On 14 July 2015 at 09:14, Thierry Reding <thierry.reding@gmail.com> wrote:
> On Mon, Jul 13, 2015 at 02:52:09PM +0100, Emil Velikov wrote:
>> Abeit quite unlikely to get hit by this bug here, let just fix it.
>>
>> v2: Correct conditional (do not call ioctl(DRM_IOCTL_PRIME_HANDLE_TO_FD)
>> when we already have the fd).
>>
>> Cc: freedreno@lists.freedesktop.org
>> Cc: Rob Clark <robdclark@gmail.com>
>> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
>> ---
>>  freedreno/freedreno_bo.c | 6 +++---
>>  freedreno/kgsl/kgsl_bo.c | 1 +
>>  freedreno/msm/msm_bo.c   | 1 +
>>  3 files changed, 5 insertions(+), 3 deletions(-)
>
> I think there's another one in kgsl_pipe_destroy(). With that fixed,
> this is:
>
I was aiming at msm and anything kgsl related was an added bonus. But
sure will fix that.

> Reviewed-by: Thierry Reding <treding@nvidia.com>
>
> There are also a couple more like this in omap_drm.c (I suspect Rob
> copied from that =) that we may want to fix at the same time (in the
> same patch or a separate one).
>
Ack will do.

> There's also a few places where an fd is compared to -1 directly, which
> should be okay, but might be worth making consistent. I can send a patch
> if you're not pedantic enough. =)
>
Sure I'll do that. Personally I don't might if we go the opposite way
- always check against -1, as long as it's not fd == 0 :-)
Upon closer look something buggy showed up in drmOpenOnceWithType

    if (fd <= 0 || nr_fds == DRM_MAX_FDS)
       return fd;

Surely that cannot be right ?

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

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

end of thread, other threads:[~2015-07-14 13:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-13 13:39 [PATCH libdrm] freedreno: zero is a valid fd number, treat it as such Emil Velikov
2015-07-13 13:52 ` Emil Velikov
2015-07-14  8:14   ` Thierry Reding
2015-07-14 13:50     ` Emil Velikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).