Commit 490d595f authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/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: default avatarBen Skeggs <bskeggs@redhat.com>
parent a38f37a7
...@@ -27,11 +27,11 @@ ...@@ -27,11 +27,11 @@
#include <core/option.h> #include <core/option.h>
struct nouveau_engine * struct nouveau_engine *
nouveau_engine(void *obj, int sub) nouveau_engine(void *obj, int idx)
{ {
struct nouveau_subdev *subdev = nouveau_subdev(obj, sub); obj = nouveau_subdev(obj, idx);
if (subdev && nv_iclass(subdev, NV_ENGINE_CLASS)) if (obj && nv_iclass(obj, NV_ENGINE_CLASS))
return nv_engine(subdev); return nv_engine(obj);
return NULL; return NULL;
} }
......
...@@ -28,11 +28,14 @@ ...@@ -28,11 +28,14 @@
#include <core/option.h> #include <core/option.h>
struct nouveau_subdev * struct nouveau_subdev *
nouveau_subdev(void *obj, int sub) nouveau_subdev(void *obj, int idx)
{ {
if (nv_device(obj)->subdev[sub]) struct nouveau_object *object = nv_object(obj);
return nv_subdev(nv_device(obj)->subdev[sub]); while (object && !nv_iclass(object, NV_SUBDEV_CLASS))
return NULL; object = object->parent;
if (object == NULL || nv_subidx(object) != idx)
object = nv_device(obj)->subdev[idx];
return object ? nv_subdev(object) : NULL;
} }
void void
......
...@@ -511,22 +511,18 @@ nouveau_devobj_ofuncs = { ...@@ -511,22 +511,18 @@ nouveau_devobj_ofuncs = {
struct nouveau_device * struct nouveau_device *
nv_device(void *obj) nv_device(void *obj)
{ {
struct nouveau_object *object = nv_object(obj); struct nouveau_object *device = nv_object(obj);
struct nouveau_object *device = object; while (device && device->parent)
device = device->parent;
if (device->engine) if (!nv_iclass(device, NV_ENGINE_CLASS)) {
device = device->engine; device = nv_object(obj)->engine;
if (device->parent) if (device && device->parent)
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 CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
if (unlikely(!device))
nv_assert("BAD CAST -> NvDevice, 0x%08x\n", nv_hclass(obj));
#endif #endif
return (void *)device; return (void *)device;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment