From a79811f15925281dc7fe1797430e51063707c72d Mon Sep 17 00:00:00 2001
From: Ben Skeggs <bskeggs@redhat.com>
Date: Tue, 14 Jan 2014 14:56:22 +1000
Subject: [PATCH] fix null ptr dereferences on some boards
Regression from "device: populate master subdev pointer only when fully
constructed"
Reported-by: Bob Gleitsmann <rjgleits@bellsouth.net>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
---
nvkm/include/subdev/instmem.h | 7 +++++++
nvkm/subdev/therm/ic.c | 3 ++-
2 files changed, 9 insertions(+), 1 deletion(-)
@@ -35,6 +35,13 @@ struct nouveau_instmem {
static inline struct nouveau_instmem *
nouveau_instmem(void *obj)
{
+ /* nv04/nv40 impls need to create objects in their constructor,
+ * which is before the subdev pointer is valid
+ */
+ if (nv_iclass(obj, NV_SUBDEV_CLASS) &&
+ nv_subidx(obj) == NVDEV_SUBDEV_INSTMEM)
+ return obj;
+
return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_INSTMEM];
}
@@ -31,7 +31,8 @@ static bool
probe_monitoring_device(struct nouveau_i2c_port *i2c,
struct i2c_board_info *info)
{
- struct nouveau_therm_priv *priv = (void *)nouveau_therm(i2c);
+ struct nouveau_therm_priv *priv =
+ (void *)nv_pclass(i2c, NV_SUBDEV_CLASS);
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
struct i2c_client *client;
--
1.8.5.2