summaryrefslogtreecommitdiff
path: root/nvkm
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2014-12-05 11:26:23 +1000
committerBen Skeggs <bskeggs@redhat.com>2015-01-10 23:57:07 +1000
commit933e1b6723ea968dfb5e93ae14f292abb2c5e91c (patch)
tree053a270b999e07586f614a29af3d1f66fa48ae37 /nvkm
parent77aaee78e26f4b174e44f9547792e10b61666176 (diff)
downloadnouveau-933e1b6723ea968dfb5e93ae14f292abb2c5e91c.tar.gz
core: fix subdev/engine/device lookup to not require engine pointer
It's about to not be valid for objects that aren't in the client object tree. Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'nvkm')
-rw-r--r--nvkm/core/engine.c8
-rw-r--r--nvkm/core/subdev.c11
-rw-r--r--nvkm/engine/device/base.c22
3 files changed, 20 insertions, 21 deletions
diff --git a/nvkm/core/engine.c b/nvkm/core/engine.c
index 4835056b0..85bf4b3d1 100644
--- a/nvkm/core/engine.c
+++ b/nvkm/core/engine.c
@@ -27,11 +27,11 @@
#include <core/option.h>
struct nouveau_engine *
-nouveau_engine(void *obj, int sub)
+nouveau_engine(void *obj, int idx)
{
- struct nouveau_subdev *subdev = nouveau_subdev(obj, sub);
- if (subdev && nv_iclass(subdev, NV_ENGINE_CLASS))
- return nv_engine(subdev);
+ obj = nouveau_subdev(obj, idx);
+ if (obj && nv_iclass(obj, NV_ENGINE_CLASS))
+ return nv_engine(obj);
return NULL;
}
diff --git a/nvkm/core/subdev.c b/nvkm/core/subdev.c
index edae53540..69ba1482c 100644
--- a/nvkm/core/subdev.c
+++ b/nvkm/core/subdev.c
@@ -28,11 +28,14 @@
#include <core/option.h>
struct nouveau_subdev *
-nouveau_subdev(void *obj, int sub)
+nouveau_subdev(void *obj, int idx)
{
- if (nv_device(obj)->subdev[sub])
- return nv_subdev(nv_device(obj)->subdev[sub]);
- return NULL;
+ struct nouveau_object *object = nv_object(obj);
+ while (object && !nv_iclass(object, NV_SUBDEV_CLASS))
+ object = object->parent;
+ if (object == NULL || nv_subidx(object) != idx)
+ object = nv_device(obj)->subdev[idx];
+ return object ? nv_subdev(object) : NULL;
}
void
diff --git a/nvkm/engine/device/base.c b/nvkm/engine/device/base.c
index e2da1d402..7c0cbcde7 100644
--- a/nvkm/engine/device/base.c
+++ b/nvkm/engine/device/base.c
@@ -511,22 +511,18 @@ nouveau_devobj_ofuncs = {
struct nouveau_device *
nv_device(void *obj)
{
- struct nouveau_object *object = nv_object(obj);
- struct nouveau_object *device = object;
-
- if (device->engine)
- device = device->engine;
- if (device->parent)
+ struct nouveau_object *device = nv_object(obj);
+ while (device && device->parent)
device = device->parent;
-
-#if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
- if (unlikely(!nv_iclass(device, NV_SUBDEV_CLASS) ||
- (nv_hclass(device) & 0xff) != NVDEV_ENGINE_DEVICE)) {
- nv_assert("BAD CAST -> NvDevice, 0x%08x 0x%08x",
- nv_hclass(object), nv_hclass(device));
+ if (!nv_iclass(device, NV_ENGINE_CLASS)) {
+ device = nv_object(obj)->engine;
+ if (device && device->parent)
+ device = device->parent;
}
+#if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
+ if (unlikely(!device))
+ nv_assert("BAD CAST -> NvDevice, 0x%08x\n", nv_hclass(obj));
#endif
-
return (void *)device;
}