From 72b0f38edc370598c270a83d587dc771de788a85 Mon Sep 17 00:00:00 2001 From: Shilpasri G Bhat Date: Tue, 11 Apr 2017 11:50:57 +0530 Subject: sensor: Fixup reading DT entries Signed-off-by: Shilpasri G Bhat --- sensor.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/sensor.c b/sensor.c index 731969f..efe1e2b 100644 --- a/sensor.c +++ b/sensor.c @@ -207,6 +207,29 @@ static int init_chip(void) struct device_node *sensor_node, *node; int rc = 0; + sensor_node = of_find_node_by_path("/occ_sensors"); + if (!sensor_node) { + pr_info("Node occ_sensors not found\n"); + return -EINVAL; + } + + if (of_property_read_u32(sensor_node, "nr_system_sensors", + &nr_system_sensors)) { + pr_info("nr_system_sensors not found\n"); + rc = -EINVAL; + } + + if (of_property_read_u32(sensor_node, "nr_chip_sensors", + &nr_chip_sensors)) { + pr_info("nr_chip_sensors not found\n"); + return -EINVAL; + } + if (of_property_read_u32(sensor_node, "nr_core_sensors", + &nr_cores_sensors)) { + pr_info("nr_core_sensors not found\n"); + return -EINVAL; + } + for_each_possible_cpu(cpu) { unsigned int id = cpu_to_chip_id(cpu); @@ -242,25 +265,6 @@ static int init_chip(void) chips[i].nr_cores = ncpus / threads_per_core; } - sensor_node = of_find_node_by_path("/occ_sensors"); - - if (of_property_read_u32(sensor_node, "nr_system_sensors", - &nr_system_sensors)) { - pr_info("nr_system_sensors not found\n"); - return -EINVAL; - } - - if (of_property_read_u32(sensor_node, "nr_chip_sensors", - &nr_chip_sensors)) { - pr_info("nr_chip_sensors not found\n"); - return -EINVAL; - } - if (of_property_read_u32(sensor_node, "nr_core_sensors", - &nr_cores_sensors)) { - pr_info("nr_core_sensors not found\n"); - return -EINVAL; - } - system_sensors = kcalloc(nr_system_sensors, sizeof(sensor_t), GFP_KERNEL); for (i = 0; i < nr_chips; i++) { @@ -354,7 +358,7 @@ static int sensor_init(void) rc = sysfs_create_group(occ_sensor_kobj, &system_attr_group); if (rc) { pr_info("Failed to create system attribute group\n"); - goto out; + goto out_free_chips; } for (i = 0; i < nr_chips; i++) { @@ -370,8 +374,9 @@ static int sensor_init(void) out_clean_kobj: kobject_put(occ_sensor_kobj); -out: +out_free_chips: clear_chips(); +out: return rc; } -- cgit v1.2.1