diff options
author | Michal Minar <miminar@redhat.com> | 2013-10-08 10:00:27 +0200 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2013-10-09 15:08:27 +0200 |
commit | 22dc08806a852b998d87c26ec2562551920c95a4 (patch) | |
tree | f4fbad5682c3ddd8069f7b577bce09e532645fa5 /src/fan | |
parent | 97f7d0cd33684ed88ea2ff80c578dbc8009f5000 (diff) | |
download | openlmi-providers-22dc08806a852b998d87c26ec2562551920c95a4.tar.gz openlmi-providers-22dc08806a852b998d87c26ec2562551920c95a4.tar.xz openlmi-providers-22dc08806a852b998d87c26ec2562551920c95a4.zip |
fan: coverity fixes
Diffstat (limited to 'src/fan')
-rw-r--r-- | src/fan/fan.c | 89 |
1 files changed, 41 insertions, 48 deletions
diff --git a/src/fan/fan.c b/src/fan/fan.c index 370572e..5e36cb0 100644 --- a/src/fan/fan.c +++ b/src/fan/fan.c @@ -246,43 +246,43 @@ static struct cim_fan * _load_fan_data( sensors_chip_name const *chip }; - if ((f = calloc(1, sizeof(struct cim_fan)))) { - if (!(chip_name = sprintf_chip_name(chip))) { - error("could not get chip name\n"); - goto lab_err_free_fan; - } - if (!(f->chip_name = strdup(chip_name))) { - perror("strdup"); - goto lab_err_free_fan; - } - f->sys_path = chip->path; - if (!(f->name = sensors_get_label(chip, feature))) { - error("could not get fan name for chip: %s\n", - f->chip_name); - goto lab_err_chip_name; - } - length = strlen(f->sys_path); - if (!(f->device_id = malloc((length + strlen(f->name) + 2) - * sizeof(char)))) { - perror("malloc"); - goto lab_err_fan_name; - } - tmp = strcpy((char*) f->device_id, f->sys_path); - tmp += length * sizeof(char); - if (f->sys_path[length - 1] != '/') { - //this will be almost certainly true - *(tmp++) = '/'; - } - strcpy(tmp, f->name); + if (!(f = calloc(1, sizeof(struct cim_fan)))) { + return NULL; + } + if (!(chip_name = sprintf_chip_name(chip))) { + error("could not get chip name\n"); + goto lab_err_free_fan; + } + if (!(f->chip_name = strdup(chip_name))) { + perror("strdup"); + goto lab_err_free_fan; + } + f->sys_path = chip->path; + if (!(f->name = sensors_get_label(chip, feature))) { + error("could not get fan name for chip: %s\n", + f->chip_name); + goto lab_err_chip_name; + } + length = strlen(f->sys_path); + if (!(f->device_id = malloc((length + strlen(f->name) + 2) + * sizeof(char)))) { + perror("malloc"); + goto lab_err_fan_name; + } + tmp = strcpy((char*) f->device_id, f->sys_path); + tmp += length * sizeof(char); + if (f->sys_path[length - 1] != '/') { + //this will be almost certainly true + *(tmp++) = '/'; + } + strcpy(tmp, f->name); - for (int const *sf_ptr=sfs; *sf_ptr != -1; ++sf_ptr) { - _assign_sf_value(chip, feature, *sf_ptr, f); - } - f->accessible_features = _load_accessible_features(chip, feature); - return f; + for (int const *sf_ptr=sfs; *sf_ptr != -1; ++sf_ptr) { + _assign_sf_value(chip, feature, *sf_ptr, f); } -//lab_err_device_id: -// free((char*) f->device_id); + f->accessible_features = _load_accessible_features(chip, feature); + return f; + lab_err_fan_name: free((char*) f->name); lab_err_chip_name: @@ -304,23 +304,24 @@ static cim_fan_error_t _find_fan( int length; cim_fan_error_t ret = CIM_FAN_OTHER_ERROR; - if (!sys_path || !fan_name) goto lab_err_fan_data; + if (!sys_path || !fan_name) return ret; length = strlen(sys_path); if (length && sys_path[length - 1] == '/') { if (!(sp = strdup(sys_path))) { perror("strdup"); - goto lab_err_fan_data; + return ret; } sp[length - 1] = '\0'; } while ((*chip = sensors_get_detected_chips(NULL, &chip_nr))) { - if ((*chip)->path && !strcmp((*chip)->path, sys_path)) break; + if ((*chip)->path && !strcmp((*chip)->path, sp)) break; } + if (sp != sys_path) free(sp); if (!(*chip)) { ret = CIM_FAN_NO_SUCH_CHIP; - goto lab_err_sys_path; + return ret; } while ((*feature = sensors_get_features(*chip, &feature_nr))) { if ((*feature)->type != SENSORS_FEATURE_FAN) continue; @@ -333,15 +334,7 @@ static cim_fan_error_t _find_fan( } free((char*) label); } - if (!(*feature)) { - ret = CIM_FAN_NO_SUCH_FAN_NAME; - goto lab_err_sys_path; - } - return CIM_FAN_SUCCESS; - -lab_err_sys_path: - if (sp != sys_path) free(sp); -lab_err_fan_data: + ret = (*feature) ? CIM_FAN_SUCCESS : CIM_FAN_NO_SUCH_FAN_NAME; return ret; } |