diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-08-30 14:51:39 +0200 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-08-30 14:51:39 +0200 |
commit | 1580c5208dc5468ca0fd9303345fb18d395bf6e8 (patch) | |
tree | dd9461fa9ef00fbd8f5d85747525f6667e8cd65f /src/hardware | |
parent | 25598959ae0204bb52e103e6e7b2b4bf3bbe7c38 (diff) | |
download | openlmi-providers-1580c5208dc5468ca0fd9303345fb18d395bf6e8.tar.gz openlmi-providers-1580c5208dc5468ca0fd9303345fb18d395bf6e8.tar.xz openlmi-providers-1580c5208dc5468ca0fd9303345fb18d395bf6e8.zip |
Hardware: Get rid of different error return codes.
Different error return code for every failure in function is pretty useless, so,
get rid of them. Now, if function exits successfully, 0 is returned. In case of
any problem, function returns -1 and prints warning log message.
Diffstat (limited to 'src/hardware')
-rw-r--r-- | src/hardware/LMI_ProcessorProvider.c | 2 | ||||
-rw-r--r-- | src/hardware/dmidecode.c | 101 | ||||
-rw-r--r-- | src/hardware/lscpu.c | 3 | ||||
-rw-r--r-- | src/hardware/procfs.c | 4 | ||||
-rw-r--r-- | src/hardware/sysfs.c | 21 | ||||
-rw-r--r-- | src/hardware/utils.c | 20 |
6 files changed, 3 insertions, 148 deletions
diff --git a/src/hardware/LMI_ProcessorProvider.c b/src/hardware/LMI_ProcessorProvider.c index 8b5ba11..8e1c9f5 100644 --- a/src/hardware/LMI_ProcessorProvider.c +++ b/src/hardware/LMI_ProcessorProvider.c @@ -842,7 +842,7 @@ CMPIUint16 get_flag(const char *flag, short *stat) } } - *stat = -2; + *stat = -1; return 0; } diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c index 84ce0c1..c241cea 100644 --- a/src/hardware/dmidecode.c +++ b/src/hardware/dmidecode.c @@ -65,79 +65,66 @@ short check_dmiprocessor_attributes(DmiProcessor *cpu) if (!cpu->id) { if (!(cpu->id = strdup(""))) { - ret = -2; goto done; } } if (!cpu->family) { if (!(cpu->family = strdup("Unknown"))) { - ret = -3; goto done; } } if (!cpu->status) { if (!(cpu->status = strdup("Unknown"))) { - ret = -4; goto done; } } if (!cpu->name) { if (!(cpu->name = strdup(""))) { - ret = -5; goto done; } } if (!cpu->type) { if (!(cpu->type = strdup(""))) { - ret = -6; goto done; } } if (!cpu->stepping) { if (!(cpu->stepping = strdup(""))) { - ret = -7; goto done; } } if (!cpu->upgrade) { if (!(cpu->upgrade = strdup("Unknown"))) { - ret = -8; goto done; } } if (!cpu->l1_cache_handle) { if (!(cpu->l1_cache_handle = strdup(""))) { - ret = -9; goto done; } } if (!cpu->l2_cache_handle) { if (!(cpu->l2_cache_handle = strdup(""))) { - ret = -10; goto done; } } if (!cpu->l3_cache_handle) { if (!(cpu->l3_cache_handle = strdup(""))) { - ret = -11; goto done; } } if (!cpu->manufacturer) { if (!(cpu->manufacturer = strdup(""))) { - ret = -12; goto done; } } if (!cpu->serial_number) { if (!(cpu->serial_number = strdup(""))) { - ret = -13; goto done; } } if (!cpu->part_number) { if (!(cpu->part_number = strdup(""))) { - ret = -14; goto done; } } @@ -163,7 +150,6 @@ short dmi_get_processors(DmiProcessor **cpus, unsigned *cpus_nb) /* get dmidecode output */ if (run_command("dmidecode -t 4", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -177,7 +163,6 @@ short dmi_get_processors(DmiProcessor **cpus, unsigned *cpus_nb) /* if no processor was found */ if (*cpus_nb < 1) { warn("Dmidecode didn't recognize any processor."); - ret = -3; goto done; } @@ -186,7 +171,6 @@ short dmi_get_processors(DmiProcessor **cpus, unsigned *cpus_nb) if (!(*cpus)) { warn("Failed to allocate memory."); *cpus_nb = 0; - ret = -4; goto done; } @@ -208,7 +192,6 @@ short dmi_get_processors(DmiProcessor **cpus, unsigned *cpus_nb) snprintf(curr_cpu_str, LONG_INT_LEN, "-%u", curr_cpu); (*cpus)[curr_cpu].id = append_str(buf, curr_cpu_str, NULL); if (!(*cpus)[curr_cpu].id) { - ret = -8; goto done; } buf = NULL; @@ -366,7 +349,6 @@ short dmi_get_processors(DmiProcessor **cpus, unsigned *cpus_nb) if (!(*cpus)[curr_cpu].characteristics) { warn("Failed to allocate memory."); (*cpus)[curr_cpu].charact_nb = 0; - ret = -5; goto done; } unsigned j; @@ -379,7 +361,6 @@ short dmi_get_processors(DmiProcessor **cpus, unsigned *cpus_nb) (*cpus)[curr_cpu].characteristics[j] = strdup(""); if (!(*cpus)[curr_cpu].characteristics[j]) { warn("Failed to allocate memory."); - ret = -6; goto done; } } @@ -392,7 +373,6 @@ short dmi_get_processors(DmiProcessor **cpus, unsigned *cpus_nb) /* fill in default attributes if needed */ for (i = 0; i < *cpus_nb; i++) { if (check_dmiprocessor_attributes(&(*cpus)[i]) != 0) { - ret = -7; goto done; } } @@ -492,37 +472,31 @@ short check_dmi_cpu_cache_attributes(DmiCpuCache *cache) if (!cache->id) { if (!(cache->id = strdup(""))) { - ret = -2; goto done; } } if (!cache->name) { if (!(cache->name = strdup(""))) { - ret = -3; goto done; } } if (!cache->status) { if (!(cache->status = strdup(""))) { - ret = -4; goto done; } } if (!cache->op_mode) { if (!(cache->op_mode = strdup("Unknown"))) { - ret = -5; goto done; } } if (!cache->type) { if (!(cache->type = strdup("Unknown"))) { - ret = -6; goto done; } } if (!cache->associativity) { if (!(cache->associativity = strdup("Unknown"))) { - ret = -7; goto done; } } @@ -548,7 +522,6 @@ short dmi_get_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb) /* get dmidecode output */ if (run_command("dmidecode -t 7", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -562,7 +535,6 @@ short dmi_get_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb) /* if no cache was found */ if (*caches_nb < 1) { warn("Dmidecode didn't recognize any processor cache memory."); - ret = -3; goto done; } @@ -571,7 +543,6 @@ short dmi_get_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb) if (!(*caches)) { warn("Failed to allocate memory."); *caches_nb = 0; - ret = -4; goto done; } @@ -586,13 +557,11 @@ short dmi_get_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb) char *id_end = strchr(buffer[i], ','); if (!id_end) { warn("Unrecognized output from dmidecode program."); - ret = -5; goto done; } (*caches)[curr_cache].id = strndup(id_start, id_end - id_start); if (!(*caches)[curr_cache].id) { warn("Failed to allocate memory."); - ret = -6; goto done; } @@ -665,7 +634,6 @@ short dmi_get_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb) /* fill in default attributes if needed */ for (i = 0; i < *caches_nb; i++) { if (check_dmi_cpu_cache_attributes(&(*caches)[i]) != 0) { - ret = -7; goto done; } } @@ -774,43 +742,36 @@ short check_dmi_memory_attributes(DmiMemory *memory) if (!memory->modules[i].serial_number) { if (asprintf(&memory->modules[i].serial_number, "%u", i) < 0) { memory->modules[i].serial_number = NULL; - ret = -2; goto done; } } if (!memory->modules[i].form_factor) { if (!(memory->modules[i].form_factor = strdup("Unknown"))) { - ret = -3; goto done; } } if (!memory->modules[i].type) { if (!(memory->modules[i].type = strdup("Unknown"))) { - ret = -4; goto done; } } if (!memory->modules[i].bank_label) { if (!(memory->modules[i].bank_label = strdup(""))) { - ret = -5; goto done; } } if (!memory->modules[i].name) { if (!(memory->modules[i].name = strdup("Memory Module"))) { - ret = -6; goto done; } } if (!memory->modules[i].manufacturer) { if (!(memory->modules[i].manufacturer = strdup(""))) { - ret = -7; goto done; } } if (!memory->modules[i].part_number) { if (!(memory->modules[i].part_number = strdup(""))) { - ret = -8; goto done; } } @@ -824,7 +785,6 @@ short check_dmi_memory_attributes(DmiMemory *memory) if (asprintf(&memory->slots[i].name, "Memory Slot %d", memory->slots[i].slot_number) < 0) { memory->slots[i].name = NULL; - ret = -9; goto done; } } @@ -853,7 +813,6 @@ short dmi_get_memory(DmiMemory *memory) /* get dmidecode output for memory modules */ if (run_command("dmidecode -t 17", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -868,7 +827,6 @@ short dmi_get_memory(DmiMemory *memory) /* if no module was found */ if (memory->modules_nb < 1) { warn("Dmidecode didn't recognize any memory module."); - ret = -3; goto done; } @@ -877,7 +835,6 @@ short dmi_get_memory(DmiMemory *memory) if (!memory->modules) { warn("Failed to allocate memory."); memory->modules_nb = 0; - ret = -4; goto done; } @@ -926,7 +883,6 @@ short dmi_get_memory(DmiMemory *memory) if (asprintf(&memory->modules[curr_mem].name, str_format, memory_size) < 0) { memory->modules[curr_mem].name = NULL; warn("Failed to allocate memory."); - ret = -5; goto done; } @@ -957,7 +913,6 @@ short dmi_get_memory(DmiMemory *memory) if (asprintf(&memory->modules[curr_mem].serial_number, "%u", curr_mem) < 0) { memory->modules[curr_mem].serial_number = NULL; warn("Failed to allocate memory."); - ret = -6; goto done; } } @@ -1025,7 +980,6 @@ short dmi_get_memory(DmiMemory *memory) /* get additional dmidecode output for memory modules */ if (run_command("dmidecode -t 6", &buffer, &buffer_size) != 0) { - ret = -7; goto done; } @@ -1041,7 +995,6 @@ short dmi_get_memory(DmiMemory *memory) if (!memory->slots) { warn("Failed to allocate memory."); memory->slots_nb = 0; - ret = -10; goto done; } @@ -1084,7 +1037,6 @@ short dmi_get_memory(DmiMemory *memory) /* get dmidecode output for memory array */ if (run_command("dmidecode -t 19", &buffer, &buffer_size) != 0) { - ret = -8; goto done; } @@ -1120,7 +1072,6 @@ short dmi_get_memory(DmiMemory *memory) /* fill in default attributes if needed */ if (check_dmi_memory_attributes(memory) != 0) { - ret = -9; goto done; } @@ -1211,55 +1162,46 @@ short check_dmi_chassis_attributes(DmiChassis *chassis) if (!chassis->serial_number) { if (!(chassis->serial_number = strdup("Not Specified"))) { - ret = -2; goto done; } } if (!chassis->type) { if (!(chassis->type = strdup("Unknown"))) { - ret = -3; goto done; } } if (!chassis->manufacturer) { if (!(chassis->manufacturer = strdup(""))) { - ret = -4; goto done; } } if (!chassis->sku_number) { if (!(chassis->sku_number = strdup(""))) { - ret = -5; goto done; } } if (!chassis->version) { if (!(chassis->version = strdup(""))) { - ret = -6; goto done; } } if (!chassis->asset_tag) { if (!(chassis->asset_tag = strdup(""))) { - ret = -7; goto done; } } if (!chassis->model) { if (!(chassis->model = strdup(""))) { - ret = -8; goto done; } } if (!chassis->product_name) { if (!(chassis->product_name = strdup(""))) { - ret = -9; goto done; } } if (!chassis->uuid) { if (!(chassis->uuid = strdup(""))) { - ret = -10; goto done; } } @@ -1284,14 +1226,12 @@ short dmi_get_chassis(DmiChassis *chassis) /* get dmidecode output for chassis */ if (run_command("dmidecode -t 3", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } /* empty output from dmidecode */ if (buffer_size < 5) { warn("Dmidecode has no information about chassis."); - ret = -3; goto done; } @@ -1393,7 +1333,6 @@ short dmi_get_chassis(DmiChassis *chassis) /* fill in default attributes if needed */ if (check_dmi_chassis_attributes(chassis) != 0) { - ret = -4; goto done; } @@ -1480,25 +1419,21 @@ short check_dmi_baseboard_attributes(DmiBaseboard *baseboard) if (!baseboard->serial_number) { if (!(baseboard->serial_number = strdup("Not Specified"))) { - ret = -2; goto done; } } if (!baseboard->manufacturer) { if (!(baseboard->manufacturer = strdup(""))) { - ret = -3; goto done; } } if (!baseboard->product_name) { if (!(baseboard->product_name = strdup(""))) { - ret = -4; goto done; } } if (!baseboard->version) { if (!(baseboard->version = strdup(""))) { - ret = -5; goto done; } } @@ -1523,14 +1458,12 @@ short dmi_get_baseboard(DmiBaseboard *baseboard) /* get dmidecode output for baseboard */ if (run_command("dmidecode -t 2", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } /* empty output from dmidecode */ if (buffer_size < 5) { warn("Dmidecode has no information about baseboard."); - ret = -3; goto done; } @@ -1568,7 +1501,6 @@ short dmi_get_baseboard(DmiBaseboard *baseboard) /* fill in default attributes if needed */ if (check_dmi_baseboard_attributes(baseboard) != 0) { - ret = -4; goto done; } @@ -1627,19 +1559,16 @@ short check_dmiport_attributes(DmiPort *port) if (!port->name) { if (!(port->name = strdup("Port"))) { - ret = -2; goto done; } } if (!port->type) { if (!(port->type = strdup("Unknown"))) { - ret = -3; goto done; } } if (!port->port_type) { if (!(port->port_type = strdup("Unknown"))) { - ret = -4; goto done; } } @@ -1665,7 +1594,6 @@ short dmi_get_ports(DmiPort **ports, unsigned *ports_nb) /* get dmidecode output */ if (run_command("dmidecode -t 8", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -1679,7 +1607,6 @@ short dmi_get_ports(DmiPort **ports, unsigned *ports_nb) /* if no port was found */ if (*ports_nb < 1) { warn("Dmidecode didn't recognize any port."); - ret = -3; goto done; } @@ -1688,7 +1615,6 @@ short dmi_get_ports(DmiPort **ports, unsigned *ports_nb) if (!(*ports)) { warn("Failed to allocate memory."); *ports_nb = 0; - ret = -4; goto done; } @@ -1729,7 +1655,6 @@ short dmi_get_ports(DmiPort **ports, unsigned *ports_nb) /* fill in default attributes if needed */ for (i = 0; i < *ports_nb; i++) { if (check_dmiport_attributes(&(*ports)[i]) != 0) { - ret = -5; goto done; } } @@ -1796,19 +1721,16 @@ short check_dmislot_attributes(DmiSystemSlot *slot) if (!slot->name) { if (!(slot->name = strdup("System slot"))) { - ret = -2; goto done; } } if (!slot->type) { if (!(slot->type = strdup("Unknown"))) { - ret = -3; goto done; } } if (!slot->link_width) { if (!(slot->link_width = strdup("Unknown"))) { - ret = -4; goto done; } } @@ -1834,7 +1756,6 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb) /* get dmidecode output */ if (run_command("dmidecode -t 9", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -1848,7 +1769,6 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb) /* if no slot was found */ if (*slots_nb < 1) { warn("Dmidecode didn't recognize any system slot."); - ret = -3; goto done; } @@ -1857,7 +1777,6 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb) if (!(*slots)) { warn("Failed to allocate memory."); *slots_nb = 0; - ret = -4; goto done; } @@ -1889,7 +1808,6 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb) /* Dmi type consists of 2 information. First is data width (NUM-bit) or link width (xNUM) or nothing, second is slot type. */ if (explode(buf, NULL, &exploded_buf, &exploded_buf_size) != 0) { - ret = -5; goto done; } if (exploded_buf_size < 1) { @@ -1901,7 +1819,6 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb) if (!(*slots)[curr_slot].link_width) { free_2d_buffer(&exploded_buf, &exploded_buf_size); warn("Failed to allocate memory."); - ret = -6; goto done; } from = 1; @@ -1922,7 +1839,6 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb) /* If type is NULL here, append_str failed. */ if (!(*slots)[curr_slot].type) { free_2d_buffer(&exploded_buf, &exploded_buf_size); - ret = -7; goto done; } } @@ -1940,7 +1856,6 @@ short dmi_get_system_slots(DmiSystemSlot **slots, unsigned *slots_nb) /* fill in default attributes if needed */ for (i = 0; i < *slots_nb; i++) { if (check_dmislot_attributes(&(*slots)[i]) != 0) { - ret = -8; goto done; } } @@ -2004,7 +1919,6 @@ short check_dmipointingdev_attributes(DmiPointingDevice *dev) if (!dev->type) { if (!(dev->type = strdup("Unknown"))) { - ret = -2; goto done; } } @@ -2030,7 +1944,6 @@ short dmi_get_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb /* get dmidecode output */ if (run_command("dmidecode -t 21", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -2044,7 +1957,6 @@ short dmi_get_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb /* if no slot was found */ if (*devices_nb < 1) { warn("Dmidecode didn't recognize any pointing device."); - ret = -3; goto done; } @@ -2053,7 +1965,6 @@ short dmi_get_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb if (!(*devices)) { warn("Failed to allocate memory."); *devices_nb = 0; - ret = -4; goto done; } @@ -2088,7 +1999,6 @@ short dmi_get_pointing_devices(DmiPointingDevice **devices, unsigned *devices_nb /* fill in default attributes if needed */ for (i = 0; i < *devices_nb; i++) { if (check_dmipointingdev_attributes(&(*devices)[i]) != 0) { - ret = -5; goto done; } } @@ -2154,43 +2064,36 @@ short check_dmibattery_attributes(DmiBattery *batt) if (!batt->name) { if (!(batt->name = strdup("Battery"))) { - ret = -2; goto done; } } if (!batt->chemistry) { if (!(batt->chemistry = strdup("Unknown"))) { - ret = -3; goto done; } } if (!batt->manufacturer) { if (!(batt->manufacturer = strdup(""))) { - ret = -4; goto done; } } if (!batt->serial_number) { if (!(batt->serial_number = strdup(""))) { - ret = -5; goto done; } } if (!batt->version) { if (!(batt->version = strdup(""))) { - ret = -6; goto done; } } if (!batt->manufacture_date) { if (!(batt->manufacture_date = strdup(""))) { - ret = -7; goto done; } } if (!batt->location) { if (!(batt->location = strdup(""))) { - ret = -8; goto done; } } @@ -2216,7 +2119,6 @@ short dmi_get_batteries(DmiBattery **batteries, unsigned *batteries_nb) /* get dmidecode output */ if (run_command("dmidecode -t 22", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -2230,7 +2132,6 @@ short dmi_get_batteries(DmiBattery **batteries, unsigned *batteries_nb) /* if no battery was found */ if (*batteries_nb < 1) { warn("Dmidecode didn't recognize any batteries."); - ret = -3; goto done; } @@ -2239,7 +2140,6 @@ short dmi_get_batteries(DmiBattery **batteries, unsigned *batteries_nb) if (!(*batteries)) { warn("Failed to allocate memory."); *batteries_nb = 0; - ret = -4; goto done; } @@ -2336,7 +2236,6 @@ short dmi_get_batteries(DmiBattery **batteries, unsigned *batteries_nb) /* fill in default attributes if needed */ for (i = 0; i < *batteries_nb; i++) { if (check_dmibattery_attributes(&(*batteries)[i]) != 0) { - ret = -5; goto done; } } diff --git a/src/hardware/lscpu.c b/src/hardware/lscpu.c index be00f87..2a0cf35 100644 --- a/src/hardware/lscpu.c +++ b/src/hardware/lscpu.c @@ -46,7 +46,6 @@ short check_lscpuprocessor_attributes(LscpuProcessor *cpu) if (!cpu->stepping) { if (!(cpu->stepping = strdup(""))) { - ret = -2; goto done; } } @@ -69,7 +68,6 @@ short lscpu_get_processor(LscpuProcessor *cpu) /* get lscpu output */ if (run_command("lscpu", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -131,7 +129,6 @@ short lscpu_get_processor(LscpuProcessor *cpu) } if (check_lscpuprocessor_attributes(cpu) != 0) { - ret = -3; goto done; } diff --git a/src/hardware/procfs.c b/src/hardware/procfs.c index 3c01cd4..ba41da8 100644 --- a/src/hardware/procfs.c +++ b/src/hardware/procfs.c @@ -44,7 +44,6 @@ short check_cpuinfoprocessor_attributes(CpuinfoProcessor *cpu) if (!cpu->model_name) { if (!(cpu->model_name = strdup(""))) { - ret = -2; goto done; } } @@ -67,7 +66,6 @@ short cpuinfo_get_processor(CpuinfoProcessor *cpu) /* read /proc/cpuinfo file */ if (read_file("/proc/cpuinfo", &buffer, &buffer_size) != 0) { - ret = -2; goto done; } @@ -79,7 +77,6 @@ short cpuinfo_get_processor(CpuinfoProcessor *cpu) buf = copy_string_part_after_delim(buffer[i], "flags\t\t: "); if (buf) { if (explode(buf, NULL, &cpu->flags, &cpu->flags_nb) != 0) { - ret = -3; goto done; } free(buf); @@ -104,7 +101,6 @@ short cpuinfo_get_processor(CpuinfoProcessor *cpu) } if (check_cpuinfoprocessor_attributes(cpu) != 0) { - ret = -4; goto done; } diff --git a/src/hardware/sysfs.c b/src/hardware/sysfs.c index 084a11d..4410ff7 100644 --- a/src/hardware/sysfs.c +++ b/src/hardware/sysfs.c @@ -34,13 +34,11 @@ short path_get_unsigned(const char *path, unsigned *result) char **buffer = NULL; if (read_file(path, &buffer, &buffer_size) != 0 || buffer_size < 1) { - ret = -2; goto done; } if (sscanf(buffer[0], "%u", result) != 1) { warn("Failed to parse file: \"%s\"; Error: %s", path, strerror(errno)); - ret = -3; goto done; } @@ -69,13 +67,11 @@ short path_get_string(const char *path, char **result) char **buffer = NULL; if (read_file(path, &buffer, &buffer_size) != 0 || buffer_size < 1) { - ret = -2; goto done; } *result = trim(buffer[0], NULL); if (!(*result)) { warn("Failed to parse file: \"%s\"", path); - ret = -3; goto done; } @@ -117,19 +113,16 @@ short check_sysfs_cpu_cache_attributes(SysfsCpuCache *cache) if (!cache->id) { if (!(cache->id = strdup(""))) { - ret = -2; goto done; } } if (!cache->name) { if (!(cache->name = strdup(""))) { - ret = -3; goto done; } } if (!cache->type) { if (!(cache->type = strdup("Unknown"))) { - ret = -4; goto done; } } @@ -187,7 +180,6 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) dmi_free_processors(&dmi_cpus, &dmi_cpus_nb); if (lscpu_get_processor(&lscpu) != 0) { - ret = -11; goto done; } } @@ -197,7 +189,6 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) cpus_nb = lscpu.processors; } else { warn("No processor found."); - ret = -12; goto done; } @@ -208,7 +199,6 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) if (!dir) { warn("Failed to read directory: \"%s\"; Error: %s", cache_dir, strerror(errno)); - ret = -2; goto done; } while (readdir(dir)) { @@ -222,7 +212,6 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) /* if no cache was found */ if (*caches_nb < 1) { warn("No processor cache was found in sysfs."); - ret = -3; goto done; } @@ -231,7 +220,6 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) if (!(*caches)) { warn("Failed to allocate memory."); *caches_nb = 0; - ret = -4; goto done; } @@ -242,14 +230,12 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) /* cache level */ snprintf(path, PATH_MAX, SYSFS_CPU_PATH "/cpu0/cache/index%u/level", i); if (path_get_unsigned(path, &level) != 0) { - ret = -5; goto done; } (*caches)[i].level = level; /* cache type */ snprintf(path, PATH_MAX, SYSFS_CPU_PATH "/cpu0/cache/index%u/type", i); if (path_get_string(path, &buf) != 0) { - ret = -6; goto done; } if (strncmp(buf, "Data", 4) == 0) { @@ -262,14 +248,12 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) if (asprintf(&(*caches)[i].id, format_str, level) < 0) { (*caches)[i].id = NULL; warn("Failed to allocate memory."); - ret = -7; goto done; } if (asprintf(&(*caches)[i].name, "Level %u %s cache", level, buf) < 0) { (*caches)[i].name = NULL; warn("Failed to allocate memory."); - ret = -8; goto done; } (*caches)[i].type = buf; @@ -298,7 +282,6 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) /* fill in default attributes if needed */ if (check_sysfs_cpu_cache_attributes(&(*caches)[i]) != 0) { - ret = -9; goto done; } } @@ -316,7 +299,6 @@ short sysfs_get_cpu_caches(SysfsCpuCache **caches, unsigned *caches_nb) snprintf(cache_id, LONG_INT_LEN, "-%u", i); (*caches)[i].id = append_str((*caches)[i].id, cache_id, NULL); if (!(*caches)[i].id) { - ret = -10; goto done; } } @@ -384,7 +366,6 @@ short sysfs_get_sizes_of_hugepages(unsigned **sizes, unsigned *sizes_nb) if (!dir) { warn("Failed to read directory: \"%s\"; Error: %s", sizes_dir, strerror(errno)); - ret = -2; goto done; } while (readdir(dir)) { @@ -397,7 +378,6 @@ short sysfs_get_sizes_of_hugepages(unsigned **sizes, unsigned *sizes_nb) /* if no size was found */ if (*sizes_nb < 1) { warn("Looks like kernel doesn't support huge memory pages."); - ret = -3; goto done; } @@ -406,7 +386,6 @@ short sysfs_get_sizes_of_hugepages(unsigned **sizes, unsigned *sizes_nb) if (!(*sizes)) { warn("Failed to allocate memory."); *sizes_nb = 0; - ret = -4; goto done; } diff --git a/src/hardware/utils.c b/src/hardware/utils.c index f23be27..c9deda9 100644 --- a/src/hardware/utils.c +++ b/src/hardware/utils.c @@ -33,7 +33,6 @@ short read_fp_to_2d_buffer(FILE *fp, char ***buffer, unsigned *buffer_size) if (!fp) { warn("Given file pointer is NULL."); - ret = -2; goto done; } @@ -43,7 +42,6 @@ short read_fp_to_2d_buffer(FILE *fp, char ***buffer, unsigned *buffer_size) if (!tmp_buffer) { warn("Failed to allocate memory."); tmp_buffer_lines = 0; - ret = -3; goto done; } @@ -61,7 +59,6 @@ short read_fp_to_2d_buffer(FILE *fp, char ***buffer, unsigned *buffer_size) if (!newtmp) { warn("Failed to allocate memory."); tmp_buffer_lines /= 2; - ret = -4; goto done; } tmp_buffer = newtmp; @@ -73,7 +70,6 @@ short read_fp_to_2d_buffer(FILE *fp, char ***buffer, unsigned *buffer_size) tmp_buffer[lines_read] = strdup(""); if (!tmp_buffer[lines_read]) { warn("Failed to allocate memory."); - ret = -5; goto done; } } @@ -82,7 +78,6 @@ short read_fp_to_2d_buffer(FILE *fp, char ***buffer, unsigned *buffer_size) if (lines_read < 1) { warn("No data read from given source."); - ret = -6; goto done; } @@ -92,7 +87,6 @@ short read_fp_to_2d_buffer(FILE *fp, char ***buffer, unsigned *buffer_size) lines_read * sizeof(char *)); if (!newtmp) { warn("Failed to allocate memory."); - ret = -7; goto done; } tmp_buffer = newtmp; @@ -140,7 +134,6 @@ short run_command(const char *command, char ***buffer, unsigned *buffer_size) /* if command is empty */ if (!command || strlen(command) < 1) { warn("Given command is empty."); - ret = -2; goto done; } @@ -150,12 +143,10 @@ short run_command(const char *command, char ***buffer, unsigned *buffer_size) if (!fp) { warn("Failed to run command: \"%s\"; Error: %s", command, strerror(errno)); - ret = -3; goto done; } if (read_fp_to_2d_buffer(fp, buffer, buffer_size) != 0) { - ret = -4; goto done; } @@ -168,12 +159,12 @@ done: warn("Failed to run command: \"%s\"; Error: %s", command, strerror(errno)); if (ret == 0) { - ret = -5; + ret = -1; } } else if (ret_code != 0) { warn("Command \"%s\" exited unexpectedly.", command); if (ret == 0) { - ret = -6; + ret = -1; } } } @@ -193,7 +184,6 @@ short read_file(const char *filename, char ***buffer, unsigned *buffer_size) /* if filename is empty */ if (!filename || strlen(filename) < 1) { warn("Given file name is empty."); - ret = -4; goto done; } @@ -202,12 +192,10 @@ short read_file(const char *filename, char ***buffer, unsigned *buffer_size) fp = fopen(filename, "r"); if (!fp) { warn("Failed to open \"%s\" file.", filename); - ret = -2; goto done; } if (read_fp_to_2d_buffer(fp, buffer, buffer_size) != 0) { - ret = -3; goto done; } @@ -317,7 +305,6 @@ short explode(const char *str, const char *delims, char ***buffer, unsigned *buf if (!tmp_buffer) { warn("Failed to allocate memory."); tmp_buffer_size = 0; - ret = -2; goto done; } @@ -340,7 +327,6 @@ short explode(const char *str, const char *delims, char ***buffer, unsigned *buf if (!new_temp) { warn("Failed to allocate memory."); tmp_buffer_size /= 2; - ret = -3; goto done; } tmp_buffer = new_temp; @@ -349,7 +335,6 @@ short explode(const char *str, const char *delims, char ***buffer, unsigned *buf tmp_buffer[item] = strndup(ts, l); if (!tmp_buffer[item]) { warn("Failed to allocate memory."); - ret = -4; goto done; } item++; @@ -362,7 +347,6 @@ short explode(const char *str, const char *delims, char ***buffer, unsigned *buf item * sizeof(char *)); if (!new_temp) { warn("Failed to allocate memory."); - ret = -5; goto done; } tmp_buffer = new_temp; |