All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm] Export drmCompareDevices
@ 2017-05-04 16:39 Adam Jackson
  2017-05-04 17:15 ` Eric Anholt
  2017-05-04 17:44 ` Emil Velikov
  0 siblings, 2 replies; 3+ messages in thread
From: Adam Jackson @ 2017-05-04 16:39 UTC (permalink / raw)
  To: dri-devel

drmCompareBusInfo was almost this already, but it wasn't exported, its
name didn't match its functionality, and while it almost looks like it
was usable for sorting due to memcmp it wouldn't work if you had
multiple bus types. I don't really want to think about defining a
sensible sort order for bus types, so let's at least make it less of a
trap for the caller.

Invert its boolean sense to be 'true if equal', rename it to describe
the type it actually operates on, and export.

Signed-off-by: Adam Jackson <ajax@redhat.com>
---
 xf86drm.c | 18 +++++++++---------
 xf86drm.h |  2 ++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index 685cf69d..e584bdff 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3029,32 +3029,32 @@ static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info)
 #endif
 }
 
-static int drmCompareBusInfo(drmDevicePtr a, drmDevicePtr b)
+int drmCompareDevices(drmDevicePtr a, drmDevicePtr b)
 {
     if (a == NULL || b == NULL)
-        return -1;
+        return 0;
 
     if (a->bustype != b->bustype)
-        return -1;
+        return 0;
 
     switch (a->bustype) {
     case DRM_BUS_PCI:
-        return memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo));
+        return memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo)) == 0;
 
     case DRM_BUS_USB:
-        return memcmp(a->businfo.usb, b->businfo.usb, sizeof(drmUsbBusInfo));
+        return memcmp(a->businfo.usb, b->businfo.usb, sizeof(drmUsbBusInfo)) == 0;
 
     case DRM_BUS_PLATFORM:
-        return memcmp(a->businfo.platform, b->businfo.platform, sizeof(drmPlatformBusInfo));
+        return memcmp(a->businfo.platform, b->businfo.platform, sizeof(drmPlatformBusInfo)) == 0;
 
     case DRM_BUS_HOST1X:
-        return memcmp(a->businfo.host1x, b->businfo.host1x, sizeof(drmHost1xBusInfo));
+        return memcmp(a->businfo.host1x, b->businfo.host1x, sizeof(drmHost1xBusInfo)) == 0;
 
     default:
         break;
     }
 
-    return -1;
+    return 0;
 }
 
 static int drmGetNodeType(const char *name)
@@ -3669,7 +3669,7 @@ static void drmFoldDuplicatedDevices(drmDevicePtr local_devices[], int count)
 
     for (i = 0; i < count; i++) {
         for (j = i + 1; j < count; j++) {
-            if (drmCompareBusInfo(local_devices[i], local_devices[j]) == 0) {
+            if (drmCompareDevices(local_devices[i], local_devices[j])) {
                 local_devices[i]->available_nodes |= local_devices[j]->available_nodes;
                 node_type = log2(local_devices[j]->available_nodes);
                 memcpy(local_devices[i]->nodes[node_type],
diff --git a/xf86drm.h b/xf86drm.h
index d75ca8ce..14d2db73 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -851,6 +851,8 @@ extern void drmFreeDevices(drmDevicePtr devices[], int count);
 extern int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device);
 extern int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices);
 
+extern int drmCompareDevices(drmDevicePtr a, drmDevicePtr b);
+
 #if defined(__cplusplus)
 }
 #endif
-- 
2.12.2

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

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

* Re: [PATCH libdrm] Export drmCompareDevices
  2017-05-04 16:39 [PATCH libdrm] Export drmCompareDevices Adam Jackson
@ 2017-05-04 17:15 ` Eric Anholt
  2017-05-04 17:44 ` Emil Velikov
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Anholt @ 2017-05-04 17:15 UTC (permalink / raw)
  To: Adam Jackson, dri-devel


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

Adam Jackson <ajax@redhat.com> writes:

> drmCompareBusInfo was almost this already, but it wasn't exported, its
> name didn't match its functionality, and while it almost looks like it
> was usable for sorting due to memcmp it wouldn't work if you had
> multiple bus types. I don't really want to think about defining a
> sensible sort order for bus types, so let's at least make it less of a
> trap for the caller.
>
> Invert its boolean sense to be 'true if equal', rename it to describe
> the type it actually operates on, and export.

I love flipping the comparison, but my only request would be to name it
drmDevicesEqual() instead, as Compare sounds a bit like memcmp() to me.
With that changed,

Reviewed-by: Eric Anholt <eric@anholt.net>

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

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

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

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

* Re: [PATCH libdrm] Export drmCompareDevices
  2017-05-04 16:39 [PATCH libdrm] Export drmCompareDevices Adam Jackson
  2017-05-04 17:15 ` Eric Anholt
@ 2017-05-04 17:44 ` Emil Velikov
  1 sibling, 0 replies; 3+ messages in thread
From: Emil Velikov @ 2017-05-04 17:44 UTC (permalink / raw)
  To: Adam Jackson; +Cc: ML dri-devel

On 4 May 2017 at 17:39, Adam Jackson <ajax@redhat.com> wrote:
> drmCompareBusInfo was almost this already, but it wasn't exported, its
> name didn't match its functionality, and while it almost looks like it
> was usable for sorting due to memcmp it wouldn't work if you had
> multiple bus types. I don't really want to think about defining a
> sensible sort order for bus types, so let's at least make it less of a
> trap for the caller.
>
> Invert its boolean sense to be 'true if equal', rename it to describe
> the type it actually operates on, and export.
>
> Signed-off-by: Adam Jackson <ajax@redhat.com>
Makes sense.

Reviewed-by: Emil Velikov <emil.velilkov@collabora.com>

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

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

end of thread, other threads:[~2017-05-04 17:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-04 16:39 [PATCH libdrm] Export drmCompareDevices Adam Jackson
2017-05-04 17:15 ` Eric Anholt
2017-05-04 17:44 ` 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.