summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense
diff options
context:
space:
mode:
authorKarol Herbst <nouveau@karolherbst.de>2016-03-28 15:24:30 +0300
committerBen Skeggs <bskeggs@redhat.com>2016-05-20 07:43:04 +0300
commit92224e751f97847195b8e90a033b3e7b30ff0bd3 (patch)
tree126020ccd9653be9f63e398886a5199334371c50 /drivers/gpu/drm/nouveau/nvkm/subdev/iccsense
parentd03e0f2748a7da3911fd54af16eb07f325ce830f (diff)
downloadlinux-92224e751f97847195b8e90a033b3e7b30ff0bd3.tar.xz
drm/nouveau/iccsense: convert to linked list
v2: add list_del calls Signed-off-by: Karol Herbst <nouveau@karolherbst.de> Reviewed-by: Martin Peres <martin.peres@free.fr> Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/iccsense')
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c34
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/priv.h1
2 files changed, 17 insertions, 18 deletions
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c
index bf1b94ec6ed4..f2a210ad0cab 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/base.c
@@ -98,25 +98,21 @@ nvkm_iccsense_ina3221_read(struct nvkm_iccsense *iccsense,
int
nvkm_iccsense_read_all(struct nvkm_iccsense *iccsense)
{
- int result = 0, i;
+ int result = 0;
+ struct nvkm_iccsense_rail *rail;
if (!iccsense)
return -EINVAL;
- if (iccsense->rail_count == 0)
- return -ENODEV;
-
- for (i = 0; i < iccsense->rail_count; ++i) {
+ list_for_each_entry(rail, &iccsense->rails, head) {
int res;
- struct nvkm_iccsense_rail *rail = &iccsense->rails[i];
if (!rail->read)
return -ENODEV;
res = rail->read(iccsense, rail);
- if (res >= 0)
- result += res;
- else
+ if (res < 0)
return res;
+ result += res;
}
return result;
}
@@ -125,9 +121,12 @@ static void *
nvkm_iccsense_dtor(struct nvkm_subdev *subdev)
{
struct nvkm_iccsense *iccsense = nvkm_iccsense(subdev);
+ struct nvkm_iccsense_rail *rail, *tmp;
- if (iccsense->rails)
- kfree(iccsense->rails);
+ list_for_each_entry_safe(rail, tmp, &iccsense->rails, head) {
+ list_del(&rail->head);
+ kfree(rail);
+ }
return iccsense;
}
@@ -145,11 +144,6 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev)
|| !stbl.nr_entry)
return 0;
- iccsense->rails = kmalloc(sizeof(*iccsense->rails) * stbl.nr_entry,
- GFP_KERNEL);
- if (!iccsense->rails)
- return -ENOMEM;
-
iccsense->data_valid = true;
for (i = 0; i < stbl.nr_entry; ++i) {
struct pwr_rail_t *r = &stbl.rail[i];
@@ -184,7 +178,10 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev)
continue;
}
- rail = &iccsense->rails[iccsense->rail_count];
+ rail = kmalloc(sizeof(*rail), GFP_KERNEL);
+ if (!rail)
+ return -ENOMEM;
+
switch (extdev.type) {
case NVBIOS_EXTDEV_INA209:
rail->read = nvkm_iccsense_ina209_read;
@@ -201,7 +198,7 @@ nvkm_iccsense_oneinit(struct nvkm_subdev *subdev)
rail->rail = r->rail;
rail->mohm = r->resistor_mohm;
rail->i2c = &i2c_bus->i2c;
- ++iccsense->rail_count;
+ list_add_tail(&rail->head, &iccsense->rails);
}
return 0;
}
@@ -224,6 +221,7 @@ nvkm_iccsense_new_(struct nvkm_device *device, int index,
{
if (!(*iccsense = kzalloc(sizeof(**iccsense), GFP_KERNEL)))
return -ENOMEM;
+ INIT_LIST_HEAD(&(*iccsense)->rails);
nvkm_iccsense_ctor(device, index, *iccsense);
return 0;
}
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/priv.h
index ed398b81e86e..e479128f0459 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/priv.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/iccsense/priv.h
@@ -4,6 +4,7 @@
#include <subdev/iccsense.h>
struct nvkm_iccsense_rail {
+ struct list_head head;
int (*read)(struct nvkm_iccsense *, struct nvkm_iccsense_rail *);
struct i2c_adapter *i2c;
u8 addr;