summaryrefslogtreecommitdiff
path: root/xf86drm.c
diff options
context:
space:
mode:
authorPaul Gofman <pgofman@codeweavers.com>2020-10-26 16:11:20 +0300
committerDave Airlie <airlied@redhat.com>2020-10-28 09:18:47 +1000
commitad7cf9d75cfa6aee3e634e5fd177b52d015fa603 (patch)
tree00186e28b96fa3b2540a6d425dc54fafc3f8aa85 /xf86drm.c
parent3e9f2113038ed92a66a9fbda6ba5c6eec998b312 (diff)
downloaddrm-ad7cf9d75cfa6aee3e634e5fd177b52d015fa603.tar.gz
xf86drm.c: Use integer logarithm.
log() is affected by FP control word and can provide inaccurate result. Fixes Killer Instinct under Wine not being able to find AMD vulkan device. Reviewed-by: Dave Airlie <airlied@redhat.com> Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/xf86drm.c b/xf86drm.c
index 50a6f092..dbb7c14b 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -124,6 +124,22 @@ static drmServerInfoPtr drm_server_info;
static bool drmNodeIsDRM(int maj, int min);
static char *drmGetMinorNameForFD(int fd, int type);
+static unsigned log2_int(unsigned x)
+{
+ unsigned l;
+
+ if (x < 2) {
+ return 0;
+ }
+ for (l = 2; ; l++) {
+ if ((unsigned)(1 << l) > x) {
+ return l - 1;
+ }
+ }
+ return 0;
+}
+
+
drm_public void drmSetServerInfo(drmServerInfoPtr info)
{
drm_server_info = info;
@@ -4001,7 +4017,7 @@ static void drmFoldDuplicatedDevices(drmDevicePtr local_devices[], int count)
for (j = i + 1; j < count; j++) {
if (drmDevicesEqual(local_devices[i], local_devices[j])) {
local_devices[i]->available_nodes |= local_devices[j]->available_nodes;
- node_type = log2(local_devices[j]->available_nodes);
+ node_type = log2_int(local_devices[j]->available_nodes);
memcpy(local_devices[i]->nodes[node_type],
local_devices[j]->nodes[node_type], drmGetMaxNodeName());
drmFreeDevice(&local_devices[j]);