diff --git a/lib/dimm_spd.c b/lib/dimm_spd.c index 4ce9412..163a2c2 100644 --- a/lib/dimm_spd.c +++ b/lib/dimm_spd.c @@ -1632,7 +1632,7 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return -1; } @@ -1656,7 +1656,7 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id) spd_data = malloc(fru.size); - if (spd_data == NULL) { + if (!spd_data) { printf(" Unable to malloc memory for spd array of size=%d\n", fru.size); return -1; @@ -1677,7 +1677,7 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id) msg_data[3] = FRU_DATA_RQST_SIZE; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); free(spd_data); spd_data = NULL; diff --git a/lib/helper.c b/lib/helper.c index bef85fd..4d07b70 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -94,7 +94,7 @@ buf2str_extended(const uint8_t *buf, int len, const char *sep) int left; int sep_len; - if (buf == NULL) { + if (!buf) { snprintf(str, sizeof(str), ""); return (const char *)str; } @@ -174,7 +174,7 @@ ipmi_parse_hex(const char *str, uint8_t *out, int size) } len /= 2; /* out bytes */ - if (out == NULL) { + if (!out) { return -2; } @@ -322,7 +322,7 @@ const char * val2str(uint16_t val, const struct valstr *vs) static char un_str[32]; int i; - for (i = 0; vs[i].str != NULL; i++) { + for (i = 0; vs[i].str; i++) { if (vs[i].val == val) return vs[i].str; } @@ -339,7 +339,7 @@ const char * oemval2str(uint32_t oem, uint16_t val, static char un_str[32]; int i; - for (i = 0; vs[i].oem != 0xffffff && vs[i].str != NULL; i++) { + for (i = 0; vs[i].oem != 0xffffff && vs[i].str; i++) { /* FIXME: for now on we assume PICMG capability on all IANAs */ if ( (vs[i].oem == oem || vs[i].oem == IPMI_OEM_PICMG) && vs[i].val == val ) { @@ -599,7 +599,7 @@ uint16_t str2val(const char *str, const struct valstr *vs) { int i; - for (i = 0; vs[i].str != NULL; i++) { + for (i = 0; vs[i].str; i++) { if (strncasecmp(vs[i].str, str, __maxlen(str, vs[i].str)) == 0) return vs[i].val; } @@ -618,10 +618,10 @@ print_valstr(const struct valstr * vs, const char * title, int loglevel) { int i; - if (vs == NULL) + if (!vs) return; - if (title != NULL) { + if (title) { if (loglevel < 0) printf("\n%s:\n\n", title); else @@ -636,7 +636,7 @@ print_valstr(const struct valstr * vs, const char * title, int loglevel) lprintf(loglevel, "=============================================="); } - for (i = 0; vs[i].str != NULL; i++) { + for (i = 0; vs[i].str; i++) { if (loglevel < 0) { if (vs[i].val < 256) printf(" %d\t0x%02x\t%s\n", vs[i].val, vs[i].val, vs[i].str); @@ -667,18 +667,18 @@ print_valstr_2col(const struct valstr * vs, const char * title, int loglevel) { int i; - if (vs == NULL) + if (!vs) return; - if (title != NULL) { + if (title) { if (loglevel < 0) printf("\n%s:\n\n", title); else lprintf(loglevel, "\n%s:\n", title); } - for (i = 0; vs[i].str != NULL; i++) { - if (vs[i+1].str == NULL) { + for (i = 0; vs[i].str; i++) { + if (!vs[i+1].str) { /* last one */ if (loglevel < 0) { printf(" %4d %-32s\n", vs[i].val, vs[i].str); @@ -737,7 +737,7 @@ ipmi_open_file(const char * file, int rw) if (rw) { /* does not exist, ok to create */ fp = fopen(file, "w"); - if (fp == NULL) { + if (!fp) { lperror(LOG_ERR, "Unable to open file %s " "for write", file); return NULL; @@ -754,7 +754,7 @@ ipmi_open_file(const char * file, int rw) if (!rw) { /* on read skip the extra checks */ fp = fopen(file, "r"); - if (fp == NULL) { + if (!fp) { lperror(LOG_ERR, "Unable to open file %s", file); return NULL; } @@ -777,7 +777,7 @@ ipmi_open_file(const char * file, int rw) } fp = fopen(file, rw ? "w+" : "r"); - if (fp == NULL) { + if (!fp) { lperror(LOG_ERR, "Unable to open file %s", file); return NULL; } @@ -1048,7 +1048,7 @@ ipmi_get_oem_id(struct ipmi_intf *intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Board ID command failed"); return 0; } diff --git a/lib/ipmi_cfgp.c b/lib/ipmi_cfgp.c index dfc4743..4131a65 100644 --- a/lib/ipmi_cfgp.c +++ b/lib/ipmi_cfgp.c @@ -53,7 +53,7 @@ ipmi_cfgp_init(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp *set, unsigned int count, const char *cmdname, ipmi_cfgp_handler_t handler, void *priv) { - if (ctx == NULL || set == NULL || handler == NULL || !cmdname) { + if (!ctx || !set || !handler || !cmdname) { return -1; } @@ -78,7 +78,7 @@ ipmi_cfgp_uninit(struct ipmi_cfgp_ctx *ctx) { struct ipmi_cfgp_data *d; - if (ctx == NULL) { + if (!ctx) { return -1; } @@ -127,7 +127,7 @@ ipmi_cfgp_parse_sel(struct ipmi_cfgp_ctx *ctx, { const struct ipmi_cfgp *p; - if (ctx == NULL || argv == NULL || sel == NULL) { + if (!ctx || !argv || !sel) { return -1; } @@ -141,7 +141,7 @@ ipmi_cfgp_parse_sel(struct ipmi_cfgp_ctx *ctx, } p = lookup_cfgp(ctx, argv[0]); - if (p == NULL) { + if (!p) { lprintf(LOG_ERR, "invalid parameter"); return -1; } @@ -205,11 +205,11 @@ cfgp_add_data(struct ipmi_cfgp_ctx *ctx, struct ipmi_cfgp_data *data) static void cfgp_usage(const struct ipmi_cfgp *p, int write) { - if (p->name == NULL) { + if (!p->name) { return; } - if (write && p->format == NULL) { + if (write && !p->format) { return; } @@ -231,7 +231,7 @@ ipmi_cfgp_usage(const struct ipmi_cfgp *set, int count, int write) const struct ipmi_cfgp *p; int i; - if (set == NULL) { + if (!set) { return; } @@ -267,7 +267,7 @@ ipmi_cfgp_parse_data(struct ipmi_cfgp_ctx *ctx, struct ipmi_cfgp_data *data; struct ipmi_cfgp_action action; - if (ctx == NULL || sel == NULL || argv == NULL) { + if (!ctx || !sel || !argv) { return -1; } @@ -294,7 +294,7 @@ ipmi_cfgp_parse_data(struct ipmi_cfgp_ctx *ctx, } data = malloc(sizeof(struct ipmi_cfgp_data) + p->size); - if (data == NULL) { + if (!data) { return -1; } @@ -374,7 +374,7 @@ cfgp_get_param(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp *p, do { data = malloc(sizeof(struct ipmi_cfgp_data) + p->size); - if (data == NULL) { + if (!data) { return -1; } @@ -426,7 +426,7 @@ ipmi_cfgp_get(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp_sel *sel) int i; int ret; - if (ctx == NULL || sel == NULL) { + if (!ctx || !sel) { return -1; } @@ -465,7 +465,7 @@ cfgp_do_action(struct ipmi_cfgp_ctx *ctx, int action_type, struct ipmi_cfgp_action action; int ret; - if (ctx == NULL || sel == NULL) { + if (!ctx || !sel) { return -1; } @@ -474,7 +474,7 @@ cfgp_do_action(struct ipmi_cfgp_ctx *ctx, int action_type, action.argv = NULL; action.file = file; - for (data = ctx->v; data != NULL; data = data->next) { + for (data = ctx->v; data; data = data->next) { if (sel->param != -1 && sel->param != data->sel.param) { continue; } @@ -527,7 +527,7 @@ int ipmi_cfgp_save(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp_sel *sel, FILE *file) { - if (file == NULL) { + if (!file) { return -1; } @@ -538,7 +538,7 @@ int ipmi_cfgp_print(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp_sel *sel, FILE *file) { - if (file == NULL) { + if (!file) { return -1; } diff --git a/lib/ipmi_channel.c b/lib/ipmi_channel.c index 74e49bb..57aebef 100644 --- a/lib/ipmi_channel.c +++ b/lib/ipmi_channel.c @@ -75,7 +75,7 @@ _ipmi_get_channel_access(struct ipmi_intf *intf, struct ipmi_rq req = {0}; uint8_t data[2]; - if (channel_access == NULL) { + if (!channel_access) { return (-3); } data[0] = channel_access->channel & 0x0F; @@ -87,7 +87,7 @@ _ipmi_get_channel_access(struct ipmi_intf *intf, req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -118,7 +118,7 @@ _ipmi_get_channel_info(struct ipmi_intf *intf, struct ipmi_rq req = {0}; uint8_t data[1]; - if (channel_info == NULL) { + if (!channel_info) { return (-3); } data[0] = channel_info->channel & 0x0F; @@ -128,7 +128,7 @@ _ipmi_get_channel_info(struct ipmi_intf *intf, req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -202,7 +202,7 @@ _ipmi_set_channel_access(struct ipmi_intf *intf, req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } return rsp->ccode; @@ -284,7 +284,7 @@ ipmi_get_channel_auth_cap(struct ipmi_intf *intf, uint8_t channel, uint8_t priv) msg_data[0] &= 0x7F; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to Get Channel Authentication Capabilities"); return (-1); } @@ -374,7 +374,7 @@ ipmi_get_channel_cipher_suites(struct ipmi_intf *intf, const char *payload_type, rqdata[2] = 0x80; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to Get Channel Cipher Suites"); return -1; } @@ -409,7 +409,7 @@ ipmi_get_channel_cipher_suites(struct ipmi_intf *intf, const char *payload_type, rqdata[2] = (rqdata[2] & 0x80) + list_index; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to Get Channel Cipher Suites"); return -1; } diff --git a/lib/ipmi_chassis.c b/lib/ipmi_chassis.c index 1684ff9..c251cfc 100644 --- a/lib/ipmi_chassis.c +++ b/lib/ipmi_chassis.c @@ -57,7 +57,7 @@ ipmi_chassis_power_status(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to get Chassis Power Status"); return -1; } @@ -96,7 +96,7 @@ ipmi_chassis_power_control(struct ipmi_intf * intf, uint8_t ctl) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to set Chassis Power Control to %s", val2str(ctl, ipmi_chassis_power_control_vals)); return -1; @@ -129,7 +129,7 @@ ipmi_chassis_identify(struct ipmi_intf * intf, char * arg) req.msg.netfn = IPMI_NETFN_CHASSIS; req.msg.cmd = 0x4; - if (arg != NULL) { + if (arg) { if (strncmp(arg, "force", 5) == 0) { identify_data.force_on = 1; } else { @@ -152,7 +152,7 @@ ipmi_chassis_identify(struct ipmi_intf * intf, char * arg) } rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to set Chassis Identify"); return -1; } @@ -170,7 +170,7 @@ ipmi_chassis_identify(struct ipmi_intf * intf, char * arg) } printf("Chassis identify interval: "); - if (arg == NULL) { + if (!arg) { printf("default (15 seconds)\n"); } else { if (identify_data.force_on != 0) { @@ -200,7 +200,7 @@ ipmi_chassis_poh(struct ipmi_intf * intf) req.msg.cmd = 0xf; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to get Chassis Power-On-Hours"); return -1; } @@ -243,7 +243,7 @@ ipmi_chassis_restart_cause(struct ipmi_intf * intf) req.msg.cmd = 0x7; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to get Chassis Restart Cause"); return -1; } @@ -304,7 +304,7 @@ ipmi_chassis_status(struct ipmi_intf * intf) req.msg.cmd = 0x1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error sending Chassis Status command"); return -1; } @@ -387,7 +387,7 @@ ipmi_chassis_selftest(struct ipmi_intf * intf) req.msg.cmd = 0x4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error sending Get Self Test command"); return -1; } @@ -462,7 +462,7 @@ ipmi_chassis_set_bootparam(struct ipmi_intf * intf, uint8_t param, uint8_t * dat req.msg.data_len = len + 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error setting Chassis Boot Parameter %d", param); return -1; } @@ -486,7 +486,7 @@ ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg) uint8_t msg_data[3]; uint8_t param_id = 0; - if (arg == NULL) + if (!arg) return -1; if (str2uchar(arg, ¶m_id) != 0) { @@ -508,7 +508,7 @@ ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg) req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error Getting Chassis Boot Parameter %s", arg); return -1; } @@ -787,7 +787,7 @@ get_bootparam_options(char *optstring, return -1; } token = strtok_r(optstring + 8, ",", &saveptr); - while (token != NULL) { + while (token) { int setbit = 0; if (strcmp(token, "help") == 0) { optionError = 1; @@ -797,7 +797,7 @@ get_bootparam_options(char *optstring, setbit = 1; token += 3; } - for (op = options; op->name != NULL; ++op) { + for (op = options; op->name; ++op) { if (strncmp(token, op->name, strlen(op->name)) == 0) { if (setbit) { *set_flag |= op->value; @@ -807,7 +807,7 @@ get_bootparam_options(char *optstring, break; } } - if (op->name == NULL) { + if (!op->name) { /* Option not found */ optionError = 1; if (setbit) { @@ -820,7 +820,7 @@ get_bootparam_options(char *optstring, if (optionError) { lprintf(LOG_NOTICE, " Legal options are:"); lprintf(LOG_NOTICE, " %-8s: print this message", "help"); - for (op = options; op->name != NULL; ++op) { + for (op = options; op->name; ++op) { lprintf(LOG_NOTICE, " %-8s: %s", op->name, op->desc); } lprintf(LOG_NOTICE, " Any Option may be prepended with no-" @@ -850,7 +850,7 @@ ipmi_chassis_get_bootvalid(struct ipmi_intf * intf) req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error Getting Chassis Boot Parameter %d", param_id); return -1; @@ -975,12 +975,12 @@ ipmi_chassis_set_bootdev(struct ipmi_intf * intf, char * arg, uint8_t *iflags) return -1; } - if (iflags == NULL) + if (!iflags) memset(flags, 0, 5); else memcpy(flags, iflags, sizeof (flags)); - if (arg == NULL) + if (!arg) flags[1] |= 0x00; else if (strncmp(arg, "none", 4) == 0) flags[1] |= 0x00; @@ -1059,7 +1059,7 @@ ipmi_chassis_power_policy(struct ipmi_intf * intf, uint8_t policy) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in Power Restore Policy command"); return -1; } @@ -1351,19 +1351,19 @@ ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv) memset(&flags[0], 0, sizeof(flags)); token = strtok_r(argv[2] + 8, ",", &saveptr); - while (token != NULL) { + while (token) { if (strcmp(token, "help") == 0) { optionError = 1; break; } - for (op = options; op->name != NULL; ++op) { + for (op = options; op->name; ++op) { if (strcmp(token, op->name) == 0) { flags[op->i] &= op->mask; flags[op->i] |= op->value; break; } } - if (op->name == NULL) { + if (!op->name) { /* Option not found */ optionError = 1; lprintf(LOG_ERR, "Invalid option: %s", token); @@ -1373,7 +1373,7 @@ ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv) if (optionError) { lprintf(LOG_NOTICE, "Legal options settings are:"); lprintf(LOG_NOTICE, "\thelp:\tprint this message"); - for (op = options; op->name != NULL; ++op) { + for (op = options; op->name; ++op) { lprintf(LOG_NOTICE, "\t%s:\t%s", op->name, op->desc); } return (-1); diff --git a/lib/ipmi_dcmi.c b/lib/ipmi_dcmi.c index 8868461..94cc1ec 100755 --- a/lib/ipmi_dcmi.c +++ b/lib/ipmi_dcmi.c @@ -597,16 +597,16 @@ print_strs(const struct dcmi_cmd * vs, const char * title, int loglevel, { int i; - if (vs == NULL) + if (!vs) return; - if (title != NULL) { + if (title) { if (loglevel < 0) printf("\n%s\n", title); else lprintf(loglevel, "\n%s", title); } - for (i = 0; vs[i].str != NULL; i++) { + for (i = 0; vs[i].str; i++) { if (loglevel < 0) { if (vs[i].val < 256) if (verthorz == 0) @@ -626,7 +626,7 @@ print_strs(const struct dcmi_cmd * vs, const char * title, int loglevel, /* Check to see if this is NOT the last element in vs.str if true * print the | else don't print anything. */ - if ((verthorz == 1) && (vs[i+1].str != NULL)) + if (verthorz == 1 && vs[i+1].str) printf(" | "); } if (verthorz == 0) { @@ -650,10 +650,10 @@ uint16_t str2val2(const char *str, const struct dcmi_cmd *vs) { int i; - if (vs == NULL || str == NULL) { + if (!vs || !str) { return 0; } - for (i = 0; vs[i].str != NULL; i++) { + for (i = 0; vs[i].str; i++) { if (strncasecmp(vs[i].str, str, __maxlen(str, vs[i].str)) == 0) return vs[i].val; } @@ -674,10 +674,10 @@ val2str2(uint16_t val, const struct dcmi_cmd *vs) static char un_str[32]; int i; - if (vs == NULL) + if (!vs) return NULL; - for (i = 0; vs[i].str != NULL; i++) { + for (i = 0; vs[i].str; i++) { if (vs[i].val == val) return vs[i].str; } @@ -695,7 +695,7 @@ chk_rsp(struct ipmi_rs * rsp) /* if the response from the intf is NULL then the BMC is experiencing * some issue and cannot complete the command */ - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "\n Unable to get DCMI information"); return 1; } @@ -730,7 +730,7 @@ chk_nm_rsp(struct ipmi_rs * rsp) /* if the response from the intf is NULL then the BMC is experiencing * some issue and cannot complete the command */ - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "\n No response to NM request"); return 1; } @@ -812,11 +812,11 @@ ipmi_dcmi_prnt_oobDiscover(struct ipmi_intf * intf) # else struct ipmi_session_params *p; - if (intf->opened == 0 && intf->open != NULL) { + if (intf->opened == 0 && intf->open) { if (intf->open(intf) < 0) return (-1); } - if (intf == NULL || intf->session == NULL) + if (!intf || !intf->session) return -1; p = &intf->ssn_params; @@ -830,7 +830,7 @@ ipmi_dcmi_prnt_oobDiscover(struct ipmi_intf * intf) if (p->retry == 0) p->retry = IPMI_LAN_RETRY; - if (p->hostname == NULL || strlen((const char *)p->hostname) == 0) { + if (!p->hostname || strlen((const char *)p->hostname) == 0) { lprintf(LOG_ERR, "No hostname specified!"); return -1; } @@ -1003,7 +1003,7 @@ ipmi_dcmi_prnt_getcapabilities(struct ipmi_intf * intf, uint8_t selector) printf(" DCMI Specification %d.%d\n", reply[1], reply[2]); printf(" Rolling average time period options: %d\n", reply[4]); printf(" Sample time options: "); - for (j = 1; dcmi_sampling_vals[j-1].str != NULL; j++) + for (j = 1; dcmi_sampling_vals[j-1].str; j++) printf(" %s ", val2str2(reply[4+j],dcmi_sampling_vals)); printf("\n"); break; @@ -1075,7 +1075,7 @@ ipmi_dcmi_prnt_getassettag(struct ipmi_intf * intf) /* macro has no effect here where can generate sig segv * if rsp occurs with null */ - if (rsp != NULL) { + if (rsp) { GOOD_ASSET_TAG_CCODE(rsp->ccode); } if (chk_rsp(rsp)) { @@ -1591,7 +1591,7 @@ ipmi_dcmi_prnt_get_temp_readings(struct ipmi_intf * intf) int i,j, tota_inst, get_inst, offset = 0; /* Print sensor description */ printf("\n\tEntity ID\t\t\tEntity Instance\t Temp. Readings"); - for (i = 0; dcmi_temp_read_vals[i].str != NULL; i++) { + for (i = 0; dcmi_temp_read_vals[i].str; i++) { /* get all of the information about this sensor */ rsp = ipmi_dcmi_get_temp_readings(intf, dcmi_temp_read_vals[i].val, @@ -1794,7 +1794,7 @@ ipmi_dcmi_pwr_prnt_glimit(struct ipmi_intf * intf) /* rsp can be a null so check response before any operation * on it to avoid sig segv */ - if (rsp != NULL) { + if (rsp) { realCc = rsp->ccode; GOOD_PWR_GLIMIT_CCODE(rsp->ccode); } @@ -1842,7 +1842,7 @@ ipmi_dcmi_pwr_slimit(struct ipmi_intf * intf, const char * option, /* rsp can be a null so check response before any operation on it to * avoid sig segv */ - if (rsp != NULL) { + if (rsp) { GOOD_PWR_GLIMIT_CCODE(rsp->ccode); } if (chk_rsp(rsp)) { @@ -2512,7 +2512,7 @@ ipmi_nm_getcapabilities(struct ipmi_intf * intf, int argc, char **argv) while (--argc > 0) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if ((option = str2val2(argv[0], nm_capability_opts)) == 0xFF) { print_strs(nm_capability_opts, "Capability commands", LOG_ERR, 0); return -1; @@ -2594,7 +2594,7 @@ ipmi_nm_get_policy(struct ipmi_intf * intf, int argc, char **argv) while (--argc) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if ((option = str2val2(argv[0], nm_policy_options)) == 0xFF) { print_strs(nm_policy_options, "Get Policy commands", LOG_ERR, 0); return -1; @@ -2688,8 +2688,9 @@ ipmi_nm_policy(struct ipmi_intf * intf, int argc, char **argv) argv++; argc--; - if ((argv[0] == NULL) || - ((action = str2val2(argv[0], nm_policy_action)) == 0xFF)) { + if (!argv[0] || + 0xFF == (action = str2val2(argv[0], nm_policy_action))) + { print_strs(nm_policy_action, "Policy commands", LOG_ERR, 0); return -1; } @@ -2705,7 +2706,7 @@ ipmi_nm_policy(struct ipmi_intf * intf, int argc, char **argv) */ while (--argc > 0) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if ((option = str2val2(argv[0], nm_policy_options)) == 0xFF) { print_strs(nm_policy_options, "Policy options", LOG_ERR, 0); return -1; @@ -2823,8 +2824,8 @@ ipmi_nm_control(struct ipmi_intf * intf, int argc, char **argv) argv++; argc--; /* nm_ctl_cmds returns 0 for disable, 1 for enable */ - if ((argv[0] == NULL) || - ((action = str2val2(argv[0], nm_ctl_cmds)) == 0xFF)) + if (!argv[0] || + 0xFF == (action = str2val2(argv[0], nm_ctl_cmds))) { print_strs(nm_ctl_cmds, "Control parameters:", LOG_ERR, 0); print_strs(nm_ctl_domain, "control Scope (required):", LOG_ERR, 0); @@ -2833,14 +2834,14 @@ ipmi_nm_control(struct ipmi_intf * intf, int argc, char **argv) argv++; while (--argc) { /* nm_ctl_domain returns correct bit field except for action */ - if ((argv[0] == NULL) || - ((scope = str2val2(argv[0], nm_ctl_domain)) == 0xFF)) + if (!argv[0] || + 0xFF == (scope = str2val2(argv[0], nm_ctl_domain))) { print_strs(nm_ctl_domain, "Control Scope (required):", LOG_ERR, 0); return -1; } argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if (scope == 0x02) { /* domain */ if ((domain = str2val2(argv[0], nm_domain_vals)) == 0xFF) { print_strs(nm_domain_vals, "Domain Scope:", LOG_ERR, 0); @@ -2883,15 +2884,15 @@ ipmi_nm_get_statistics(struct ipmi_intf * intf, int argc, char **argv) time_t t; argv++; - if ((argv[0] == NULL) || - ((mode = str2val2(argv[0], nm_stats_mode)) == 0xFF)) + if (!argv[0] || + 0xFF == (mode = str2val2(argv[0], nm_stats_mode))) { print_strs(nm_stats_mode, "Statistics commands", LOG_ERR, 0); return -1; } while (--argc) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if ((option = str2val2(argv[0], nm_stats_opts)) == 0xFF) { print_strs(nm_stats_opts, "Control Scope options", LOG_ERR, 0); return -1; @@ -3008,15 +3009,15 @@ ipmi_nm_reset_statistics(struct ipmi_intf * intf, int argc, char **argv) uint8_t have_policy_id = FALSE; argv++; - if ((argv[0] == NULL) || - ((mode = str2val2(argv[0], nm_reset_mode)) == 0xFF)) + if (!argv[0] || + 0xFF == (mode = str2val2(argv[0], nm_reset_mode))) { print_strs(nm_reset_mode, "Reset Statistics Modes:", LOG_ERR, 0); return -1; } while (--argc) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if ((option = str2val2(argv[0], nm_stats_opts)) == 0xFF) { print_strs(nm_stats_opts, "Reset Scope options", LOG_ERR, 0); return -1; @@ -3060,7 +3061,7 @@ ipmi_nm_set_range(struct ipmi_intf * intf, int argc, char **argv) while (--argc) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if ((param = str2val2(argv[0], nm_power_range)) == 0xFF) { print_strs(nm_power_range, "power range parameters:", LOG_ERR, 0); return -1; @@ -3144,8 +3145,8 @@ ipmi_nm_alert(struct ipmi_intf * intf, int argc, char **argv) argv++; argc--; - if ((argv[0] == NULL) || - ((action = str2val2(argv[0], nm_alert_opts)) == 0xFF)) + if (!argv[0] || + 0xFF == (action = str2val2(argv[0], nm_alert_opts))) { print_strs(nm_alert_opts, "Alert commands", LOG_ERR, 0); return -1; @@ -3156,7 +3157,7 @@ ipmi_nm_alert(struct ipmi_intf * intf, int argc, char **argv) memset(&alert, 0, sizeof(alert)); while (--argc) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; if ((param = str2val2(argv[0], nm_set_alert_param)) == 0xFF) { print_strs(nm_set_alert_param, "Set alert Parameters:", LOG_ERR, 0); return -1; @@ -3236,8 +3237,8 @@ ipmi_nm_thresh(struct ipmi_intf * intf, int argc, char **argv) argv++; argc--; /* set or get */ - if ((argv[0] == NULL) || (argc < 3) || - ((action = str2val2(argv[0], nm_thresh_cmds)) == 0xFF)) + if (!argv[0] || argc < 3 + || 0xFF == (action = str2val2(argv[0], nm_thresh_cmds))) { print_strs(nm_thresh_cmds, "Threshold commands", LOG_ERR, 0); return -1; @@ -3245,7 +3246,7 @@ ipmi_nm_thresh(struct ipmi_intf * intf, int argc, char **argv) memset(&thresh, 0, sizeof(thresh)); while (--argc) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; option = str2val2(argv[0], nm_thresh_param); switch (option) { case 0x01: /* get domain scope */ @@ -3356,8 +3357,8 @@ ipmi_nm_suspend(struct ipmi_intf * intf, int argc, char **argv) argv++; argc--; /* set or get */ - if ((argv[0] == NULL) || (argc < 3) || - ((action = str2val2(argv[0], nm_suspend_cmds)) == 0xFF)) + if (!argv[0] || argc < 3 || + 0xFF == (action = str2val2(argv[0], nm_suspend_cmds))) { print_strs(nm_suspend_cmds, "Suspend commands", LOG_ERR, 0); return -1; @@ -3365,7 +3366,7 @@ ipmi_nm_suspend(struct ipmi_intf * intf, int argc, char **argv) memset(&suspend, 0, sizeof(suspend)); while (--argc > 0) { argv++; - if (argv[0] == NULL) break; + if (!argv[0]) break; option = str2val2(argv[0], nm_thresh_param); switch (option) { case 0x01: /* get domain scope */ @@ -3517,7 +3518,7 @@ ipmi_dcmi_set_limit(struct ipmi_intf * intf, int argc, char **argv) } } else { /* loop through each parameter and value until we have neither */ - while ((argv[1] != NULL) && (argv[2] != NULL)) { + while (argv[1] && argv[2]) { rc = ipmi_dcmi_pwr_slimit(intf, argv[1], argv[2]); /* catch any error that the set limit function returned */ if (rc > 0) { @@ -3543,7 +3544,7 @@ ipmi_dcmi_parse_power(struct ipmi_intf * intf, int argc, char **argv) switch (str2val2(argv[0], dcmi_pwrmgmt_vals)) { case 0x00: /* get reading */ - if (argv[1] != NULL) { + if (argv[1]) { if (!(sample_time = str2val2(argv[1], dcmi_sampling_vals))) { print_strs(dcmi_sampling_vals, "Invalid sample time. Valid times are: ", @@ -3713,7 +3714,7 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv) switch (str2val2(argv[0], dcmi_cmd_vals)) { case 0x00: /* discover capabilities*/ - for (i = 1; dcmi_capable_vals[i-1].str != NULL; i++) { + for (i = 1; dcmi_capable_vals[i-1].str; i++) { if (ipmi_dcmi_prnt_getcapabilities(intf, i) < 0) { lprintf(LOG_ERR,"Error discovering %s capabilities!\n", val2str2(i, dcmi_capable_vals)); @@ -3724,7 +3725,7 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv) case 0x01: /* power */ argv++; - if (argv[0] == NULL) { + if (!argv[0]) { print_strs(dcmi_pwrmgmt_vals, "power ", LOG_ERR, 0); return -1; @@ -3738,7 +3739,7 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv) * and if it exists, print the sdr record id(s) for it. * Use the val from each one as the sensor number. */ - for (i = 0; dcmi_discvry_snsr_vals[i].str != NULL; i++) { + for (i = 0; dcmi_discvry_snsr_vals[i].str; i++) { /* get all of the information about this sensor */ rc = ipmi_dcmi_prnt_discvry_snsr(intf, dcmi_discvry_snsr_vals[i].val); @@ -3852,7 +3853,7 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv) } case 0x0B: { - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "\nOOB discovery is available only via RMCP interface."); return -1; @@ -3971,24 +3972,24 @@ ipmi_print_sensor_info(struct ipmi_intf *intf, uint16_t rec_id) uint8_t *rec = NULL; itr = ipmi_sdr_start(intf, 0); - if (itr == NULL) { + if (!itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return (-1); } - while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, itr))) { if (header->id == rec_id) { break; } } - if (header == NULL) { + if (!header) { lprintf(LOG_DEBUG, "header == NULL"); ipmi_sdr_end(intf, itr); return (-1); } /* yes, we found the SDR for this record ID, now get full record */ rec = ipmi_sdr_get_record(intf, header, itr); - if (rec == NULL) { + if (!rec) { lprintf(LOG_DEBUG, "rec == NULL"); ipmi_sdr_end(intf, itr); return (-1); diff --git a/lib/ipmi_delloem.c b/lib/ipmi_delloem.c index dbb345f..4658d0c 100644 --- a/lib/ipmi_delloem.c +++ b/lib/ipmi_delloem.c @@ -411,7 +411,7 @@ ipmi_delloem_lcd_main(struct ipmi_intf * intf, int argc, char ** argv) ipmi_lcd_usage(); return -1; } - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_lcd_usage(); return -1; } @@ -467,7 +467,7 @@ ipmi_delloem_lcd_main(struct ipmi_intf * intf, int argc, char ** argv) ipmi_lcd_usage(); return -1; } - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_lcd_usage(); return -1; } @@ -493,7 +493,7 @@ ipmi_delloem_lcd_main(struct ipmi_intf * intf, int argc, char ** argv) ipmi_lcd_usage(); return -1; } - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_lcd_usage(); return -1; } @@ -1204,7 +1204,7 @@ ipmi_lcd_set_kvm(struct ipmi_intf * intf, char status) data[1] = status; /* active- inactive */ data[2] = lcdstatus.lock_status; /* full-veiw-locked */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error setting LCD status"); rc= -1; } else if ((rsp->ccode == 0xc1) || (rsp->ccode == 0xcb)) { @@ -1250,7 +1250,7 @@ ipmi_lcd_set_lock(struct ipmi_intf * intf, char lock) data[1] = lcdstatus.vKVM_status; /* active- inactive */ data[2] = lock; /* full- veiw-locked */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error setting LCD status"); rc = -1; } else if ((rsp->ccode == 0xc1) || (rsp->ccode == 0xcb)) { @@ -1526,7 +1526,7 @@ ipmi_delloem_mac_main(struct ipmi_intf * intf, int argc, char ** argv) rc = ipmi_macinfo(intf, 0xff); } else if (strncmp(argv[current_arg], "get\0", 4) == 0) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_mac_usage(); return -1; } @@ -1595,12 +1595,10 @@ ipmi_macinfo_drac_idrac_virtual_mac(struct ipmi_intf* intf,uint8_t NicNum) req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { - return -1; - } - if (rsp->ccode) { + if (!rsp || rsp->ccode) { return -1; } + if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_12G_MONOLITHIC== IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type) @@ -1690,7 +1688,7 @@ ipmi_macinfo_drac_idrac_mac(struct ipmi_intf* intf,uint8_t NicNum) req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting MAC Address"); return -1; } @@ -1756,7 +1754,7 @@ ipmi_macinfo_10g(struct ipmi_intf* intf, uint8_t NicNum) req.msg.data = msg_data; req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting MAC Address"); return -1; } @@ -1830,7 +1828,7 @@ ipmi_macinfo_11g(struct ipmi_intf* intf, uint8_t NicNum) req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting MAC Address"); return -1; } @@ -1861,7 +1859,7 @@ ipmi_macinfo_11g(struct ipmi_intf* intf, uint8_t NicNum) req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting MAC Address"); return -1; } @@ -1964,7 +1962,7 @@ ipmi_delloem_lan_main(struct ipmi_intf * intf, int argc, char ** argv) int nic_selection = 0; char nic_set[2] = {0}; current_arg++; - if (argv[current_arg] == NULL || strcmp(argv[current_arg], "help") == 0) { + if (!argv[current_arg] || strcmp(argv[current_arg], "help") == 0) { ipmi_lan_usage(); return 0; } @@ -1974,7 +1972,7 @@ ipmi_delloem_lan_main(struct ipmi_intf * intf, int argc, char ** argv) return -1; } else if (strncmp(argv[current_arg], "set\0", 4) == 0) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_lan_usage(); return -1; } @@ -2010,7 +2008,7 @@ ipmi_delloem_lan_main(struct ipmi_intf * intf, int argc, char ** argv) return 0; } else if (strncmp(argv[current_arg], "get\0", 4) == 0) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { rc = ipmi_lan_get_nic_selection(intf); return rc; } else if (strncmp(argv[current_arg], "active\0", 7) == 0) { @@ -2053,7 +2051,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, req.msg.data = msg_data; req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting nic selection"); return -1; } else if (rsp->ccode) { @@ -2063,13 +2061,13 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } nic_set[0] = rsp->data[0]; nic_set[1] = rsp->data[1]; - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "dedicated\0", 10) == 0) { nic_set[0] = 1; nic_set[1] = 0; return 0; } - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "shared\0", 7) == 0) { /* placeholder */ } else { @@ -2077,7 +2075,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } current_arg++; - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "with\0", 5) == 0) { /* placeholder */ } else { @@ -2085,14 +2083,14 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } current_arg++; - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "failover\0", 9) == 0) { failover = 1; } if (failover) { current_arg++; } - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "lom1\0", 5) == 0) { if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) { return INVAILD_SHARED_MODE; @@ -2111,7 +2109,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } } return 0; - } else if (argv[current_arg] != NULL + } else if (argv[current_arg] && strncmp(argv[current_arg], "lom2\0", 5) == 0) { if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) { return INVAILD_SHARED_MODE; @@ -2130,7 +2128,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } } return 0; - } else if (argv[current_arg] != NULL + } else if (argv[current_arg] && strncmp(argv[current_arg], "lom3\0", 5) == 0) { if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) { return INVAILD_SHARED_MODE; @@ -2149,7 +2147,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } } return 0; - } else if (argv[current_arg] != NULL + } else if (argv[current_arg] && strncmp(argv[current_arg], "lom4\0", 5) == 0) { if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) { return INVAILD_SHARED_MODE; @@ -2168,7 +2166,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } } return 0; - } else if (failover && argv[current_arg] != NULL + } else if (failover && argv[current_arg] && strncmp(argv[current_arg], "none\0", 5) == 0) { if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type) ) { return INVAILD_SHARED_MODE; @@ -2180,7 +2178,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, nic_set[1] = 0; } return 0; - } else if (failover && argv[current_arg] != NULL + } else if (failover && argv[current_arg] && strncmp(argv[current_arg], "all\0", 4) == 0) { /* placeholder */ } else { @@ -2188,7 +2186,7 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, } current_arg++; - if (failover && argv[current_arg] != NULL + if (failover && argv[current_arg] && strncmp(argv[current_arg], "loms\0", 5) == 0) { if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) { return INVAILD_SHARED_MODE; @@ -2205,19 +2203,19 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg, static int get_nic_selection_mode(int current_arg, char ** argv) { - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "dedicated\0", 10) == 0) { return DEDICATED; } - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "shared\0", 7) == 0) { - if (argv[current_arg+1] == NULL) { + if (!argv[current_arg+1]) { return SHARED; } } current_arg++; - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "with\0", 5) == 0) { /* place holder */ } else { @@ -2225,7 +2223,7 @@ get_nic_selection_mode(int current_arg, char ** argv) } current_arg++; - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "failover\0", 9) == 0) { /* place holder */ } else { @@ -2233,10 +2231,10 @@ get_nic_selection_mode(int current_arg, char ** argv) } current_arg++; - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "lom2\0", 5) == 0) { return SHARED_WITH_FAILOVER_LOM2; - } else if (argv[current_arg] != NULL + } else if (argv[current_arg] && strncmp(argv[current_arg], "all\0", 4) == 0) { /* place holder */ } else { @@ -2244,7 +2242,7 @@ get_nic_selection_mode(int current_arg, char ** argv) } current_arg++; - if (argv[current_arg] != NULL + if (argv[current_arg] && strncmp(argv[current_arg], "loms\0", 5) == 0) { return SHARED_WITH_FAILOVER_ALL_LOMS; } @@ -2268,7 +2266,7 @@ ipmi_lan_set_nic_selection_12g(struct ipmi_intf * intf, uint8_t * nic_selection) req.msg.data = msg_data; req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in setting nic selection"); return -1; } else if( (nic_selection[0] == 1) @@ -2303,7 +2301,7 @@ ipmi_lan_set_nic_selection(struct ipmi_intf * intf, uint8_t nic_selection) req.msg.data = msg_data; req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in setting nic selection"); return -1; } else if (rsp->ccode) { @@ -2336,7 +2334,7 @@ ipmi_lan_get_nic_selection(struct ipmi_intf * intf) req.msg.data = msg_data; req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting nic selection"); return -1; } else if (rsp->ccode) { @@ -2392,7 +2390,7 @@ ipmi_lan_get_active_nic(struct ipmi_intf * intf) req.msg.data = msg_data; req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting Active LOM Status"); return -1; } else if (rsp->ccode) { @@ -2411,7 +2409,7 @@ ipmi_lan_get_active_nic(struct ipmi_intf * intf) req.msg.data = msg_data; req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting Active LOM Status"); return -1; } else if (rsp->ccode) { @@ -2516,7 +2514,7 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv) rc = ipmi_powermgmt(intf); } else if (strncmp(argv[current_arg], "clear\0", 6) == 0) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_powermonitor_usage(); return -1; } else if (strncmp(argv[current_arg], "peakpower\0", 10) == 0) { @@ -2529,7 +2527,7 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv) } } else if (strncmp(argv[current_arg], "powerconsumption\0", 17) == 0) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { rc = ipmi_print_get_power_consmpt_data(intf,watt); } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) { rc = ipmi_print_get_power_consmpt_data(intf, watt); @@ -2541,7 +2539,7 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv) } } else if (strncmp(argv[current_arg], "powerconsumptionhistory\0", 23) == 0) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { rc = ipmi_print_power_consmpt_history(intf,watt); } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) { rc = ipmi_print_power_consmpt_history(intf, watt); @@ -2553,7 +2551,7 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv) } } else if (strncmp(argv[current_arg], "getpowerbudget\0", 15) == 0) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { rc=ipmi_print_power_cap(intf,watt); } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) { rc = ipmi_print_power_cap(intf, watt); @@ -2566,7 +2564,7 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv) } else if (strncmp(argv[current_arg], "setpowerbudget\0", 15) == 0) { int val; current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_powermonitor_usage(); return -1; } @@ -2581,7 +2579,7 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv) return (-1); } current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_powermonitor_usage(); } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) { rc = ipmi_set_power_cap(intf,watt,val); @@ -2645,12 +2643,12 @@ ipmi_get_sensor_reading(struct ipmi_intf *intf, unsigned char sensorNumber, req.msg.cmd = GET_SENSOR_READING; req.msg.data = &sensorNumber; req.msg.data_len = 1; - if (pSensorReadingData == NULL) { + if (!pSensorReadingData) { return -1; } memset(pSensorReadingData, 0, sizeof(SensorReadingType)); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return 1; } else if (rsp->ccode) { return 1; @@ -2690,7 +2688,7 @@ ipmi_get_power_capstatus_command(struct ipmi_intf * intf) data[0] = 01; data[1] = 0xFF; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting powercap status"); return -1; } else if (( iDRAC_FLAG_12_13 ) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) { @@ -2741,7 +2739,7 @@ ipmi_set_power_capstatus_command(struct ipmi_intf * intf, uint8_t val) data[0] = 00; data[1] = val; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error setting powercap status"); return -1; } else if ((iDRAC_FLAG_12_13) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) { @@ -2799,7 +2797,7 @@ ipmi_powermgmt(struct ipmi_intf * intf) req.msg.cmd = IPMI_CMD_GET_SEL_TIME; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting BMC time info."); return -1; } @@ -2828,7 +2826,7 @@ ipmi_powermgmt(struct ipmi_intf * intf) msg_data[1] = 0x01; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting power management information."); return -1; } @@ -2932,7 +2930,7 @@ ipmi_powermgmt_clear(struct ipmi_intf * intf, uint8_t clearValue) msg_data[2] = clearType; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error clearing power values."); return -1; } else if ((iDRAC_FLAG_12_13) @@ -3010,7 +3008,7 @@ ipmi_get_power_headroom_command(struct ipmi_intf * intf,uint8_t unit) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting power headroom status"); return -1; } else if ((iDRAC_FLAG_12_13) @@ -3077,7 +3075,7 @@ ipmi_get_power_consumption_data(struct ipmi_intf * intf,uint8_t unit) int status = 0; int sensor_number = 0; sdr = ipmi_sdr_find_sdr_byid(intf, "System Level"); - if (sdr == NULL) { + if (!sdr) { lprintf(LOG_ERR, "Error : Can not access the System Level sensor data"); return -1; @@ -3089,7 +3087,7 @@ ipmi_get_power_consumption_data(struct ipmi_intf * intf,uint8_t unit) sdr->record.common->keys.owner_id, sdr->record.common->keys.lun, sdr->record.common->keys.channel); - if (rsp == NULL || rsp->ccode) { + if (!rsp || rsp->ccode) { lprintf(LOG_ERR, "Error : Can not access the System Level sensor data"); return -1; @@ -3144,7 +3142,7 @@ ipmi_get_instan_power_consmpt_data(struct ipmi_intf * intf, msg_data[1] = 0x00; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting instantaneous power consumption data ."); return -1; } else if ((iDRAC_FLAG_12_13) @@ -3837,7 +3835,7 @@ get_vFlash_compcode_str(uint8_t vflashcompcode, const struct vFlashstr *vs) { static char un_str[32]; int i; - for (i = 0; vs[i].str != NULL; i++) { + for (i = 0; vs[i].str; i++) { if (vs[i].val == vflashcompcode) return vs[i].str; } @@ -3871,7 +3869,7 @@ ipmi_get_sd_card_info(struct ipmi_intf * intf) { req.msg.data_len = input_length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in getting SD Card Extended Information"); return -1; } else if (rsp->ccode) { @@ -3942,19 +3940,19 @@ ipmi_delloem_vFlash_process(struct ipmi_intf * intf, int current_arg, char ** ar return -1; } - if (argv[current_arg] == NULL || strcmp(argv[current_arg], "help") == 0) { + if (!argv[current_arg] || strcmp(argv[current_arg], "help") == 0) { ipmi_vFlash_usage(); return 0; } ipmi_idracvalidator_command(intf); if (!strncmp(argv[current_arg], "info\0", 5)) { current_arg++; - if (argv[current_arg] == NULL) { + if (!argv[current_arg]) { ipmi_vFlash_usage(); return -1; } else if (strncmp(argv[current_arg], "Card\0", 5) == 0) { current_arg++; - if (argv[current_arg] != NULL) { + if (argv[current_arg]) { ipmi_vFlash_usage(); return -1; } @@ -4052,7 +4050,7 @@ CheckSetLEDSupport(struct ipmi_intf * intf) data[9] = 0x00; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL || rsp->ccode) { + if (!rsp || rsp->ccode) { return; } SetLEDSupported = 1; @@ -4094,7 +4092,7 @@ ipmi_getdrivemap(struct ipmi_intf * intf, int b, int d, int f, int *bay, data[7] = (d << 3) + f; /* devfn */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error issuing getdrivemap command."); return -1; } else if (rsp->ccode) { @@ -4149,7 +4147,7 @@ ipmi_setled_state(struct ipmi_intf * intf, int bayId, int slotId, int state) data[11] = state >> 8; /* state MSB; */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error issuing setled command."); return -1; } else if (rsp->ccode) { diff --git a/lib/ipmi_ekanalyzer.c b/lib/ipmi_ekanalyzer.c index 07b5c1d..2a91b03 100644 --- a/lib/ipmi_ekanalyzer.c +++ b/lib/ipmi_ekanalyzer.c @@ -496,7 +496,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv) */ filename[type_offset] = malloc(strlen(argv[argument_offset]) + 1 - SIZE_OF_FILE_TYPE); - if (filename[type_offset] == NULL) { + if (!filename[type_offset]) { lprintf(LOG_ERR, "malloc failure"); return (-1); } @@ -514,7 +514,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv) &list_head, &list_record, &list_last ); ipmi_ek_display_record(list_record, list_head, list_last); /* Remove record of list */ - while (list_head != NULL) { + while (list_head) { ipmi_ek_remove_record_from_list(list_head, &list_head,&list_last ); if (verbose > 1) { @@ -604,7 +604,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv) filename_size = strlen(argv[index]) - SIZE_OF_FILE_TYPE + 1; if (filename_size > 0) { filename[i] = malloc( filename_size ); - if (filename[i] != NULL) { + if (filename[i]) { strcpy(filename[i], &argv[index][SIZE_OF_FILE_TYPE]); } else { lprintf(LOG_ERR, "ipmitool: malloc failure"); @@ -632,7 +632,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv) option, filename, file_type); } for (i = 0; i < (argc-1); i++) { - if (filename[i] != NULL) { + if (filename[i]) { free(filename[i]); filename[i] = NULL; } @@ -715,8 +715,9 @@ ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type) */ tboolean first_data = TRUE; for (list_record[i] = list_head[i]; - list_record[i] != NULL; - list_record[i] = list_record[i]->next) { + list_record[i]; + list_record[i] = list_record[i]->next) + { if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_P2P) { if (first_data) { printf("%s\n", STAR_LINE_LIMITER); @@ -738,7 +739,7 @@ ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type) } /*Destroy the list of record*/ for (i = 0; i < argc; i++) { - while (list_head[i] != NULL) { + while (list_head[i]) { ipmi_ek_remove_record_from_list(list_head[i], &list_head[i], &list_last[i]); } @@ -788,7 +789,7 @@ ipmi_ek_display_carrier_connectivity(struct ipmi_ek_multi_header *record) int offset = START_DATA_OFFSET; struct fru_picmgext_carrier_p2p_record rsc_desc; struct fru_picmgext_carrier_p2p_descriptor *port_desc; - if (record == NULL) { + if (!record) { lprintf(LOG_ERR, "P2P connectivity record is invalid\n"); return ERROR_STATUS; } @@ -916,11 +917,11 @@ ipmi_ek_display_power( int argc, char * opt, char ** filename, int * file_type ) return_value = ipmi_ekanalyzer_fru_file2structure( filename[num_file], &list_head[num_file], &list_record[num_file], &list_last[num_file]); - if ( list_head[num_file] != NULL ){ + if (list_head[num_file]){ for ( list_record[num_file] = list_head[num_file]; - list_record[num_file] != NULL; - list_record[num_file] = list_record[num_file]->next - ){ + list_record[num_file]; + list_record[num_file] = list_record[num_file]->next) + { if ( ( strcmp(opt, "all") == 0 ) && ( file_type[num_file] == ON_CARRIER_FRU_FILE ) ){ @@ -990,7 +991,7 @@ ipmi_ek_display_power( int argc, char * opt, char ** filename, int * file_type ) return_value = OK_STATUS; /*Destroy the list of record*/ for ( index = 0; index < argc; index++ ){ - while ( list_head[index] != NULL ){ + while (list_head[index]) { ipmi_ek_remove_record_from_list ( list_head[index], &list_head[index],&list_last[index] ); } @@ -1153,13 +1154,13 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt, /*Get Carrier p2p connectivity record for physical check*/ for (num_file=0; num_file < argc; num_file++){ if (file_type[num_file] == ON_CARRIER_FRU_FILE ){ - for ( pcarrier_p2p=list_head[num_file]; - pcarrier_p2p != NULL ; - pcarrier_p2p = pcarrier_p2p->next - ){ - if ( pcarrier_p2p->data[PICMG_ID_OFFSET] - == FRU_AMC_CARRIER_P2P - ){ + for (pcarrier_p2p = list_head[num_file]; + pcarrier_p2p; + pcarrier_p2p = pcarrier_p2p->next) + { + if (FRU_AMC_CARRIER_P2P == + pcarrier_p2p->data[PICMG_ID_OFFSET]) + { break; } } @@ -1193,7 +1194,7 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt, match_pair ++; } for( num_file=0; num_file < argc; num_file++ ){ - if (list_head[num_file] != NULL ){ + if (list_head[num_file]) { ipmi_ek_remove_record_from_list( list_head[num_file], &list_record[num_file], &list_last[num_file]); } @@ -1255,13 +1256,13 @@ static int ipmi_ek_matching_process( int * file_type, int index1, int index2, index2 = index_temp; /*index2 indcate an AMC*/ } /*Calculate record size for Carrier file*/ - for ( record=list_head[index1]; record != NULL;record = record->next ){ + for (record = list_head[index1]; record; record = record->next ){ if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){ num_amc_record2++; } } /*Calculate record size for amc file*/ - for ( record=list_head[index2]; record != NULL;record = record->next){ + for (record = list_head[index2]; record; record = record->next){ if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){ num_amc_record1++; } @@ -1279,17 +1280,17 @@ static int ipmi_ek_matching_process( int * file_type, int index1, int index2, amc_record2 = malloc ( num_amc_record2 * \ sizeof(struct ipmi_ek_amc_p2p_connectivity_record)); - for (record=list_head[index2]; record != NULL;record = record->next){ + for (record = list_head[index2]; record; record = record->next) { if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){ result = ipmi_ek_create_amc_p2p_record( record, &amc_record1[index_record1] ); if (result != ERROR_STATUS){ struct ipmi_ek_multi_header * current_record = NULL; - for ( current_record=list_head[index1]; - current_record != NULL ; - current_record = current_record->next - ){ + for (current_record=list_head[index1]; + current_record; + current_record = current_record->next) + { if ( current_record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){ result = ipmi_ek_create_amc_p2p_record( current_record, &amc_record2[index_record2] ); @@ -1359,7 +1360,7 @@ ipmi_ek_check_physical_connectivity( { int return_status = OK_STATUS; - if ( record == NULL ){ + if (!record){ printf("NO Carrier p2p connectivity !\n"); return_status = ERROR_STATUS; } @@ -1424,7 +1425,7 @@ ipmi_ek_check_physical_connectivity( rsc_desc.p2p_count ); } - if ( (port_desc != NULL) && (return_status != ERROR_STATUS) ){ + if (port_desc && return_status != ERROR_STATUS) { int j=0; for ( j = 0; j < rsc_desc.p2p_count; j++ ){ @@ -1524,7 +1525,7 @@ ipmi_ek_check_physical_connectivity( } return_status = ERROR_STATUS; } - if (port_desc != NULL){ + if (port_desc) { free(port_desc); port_desc = NULL; } @@ -2209,7 +2210,7 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record, int index_oem = 0; amc_record->oem_guid = malloc(amc_record->guid_count * \ sizeof(struct fru_picmgext_guid)); - if (amc_record->oem_guid == NULL) { + if (!amc_record->oem_guid) { return ERROR_STATUS; } for (index_oem = 0; index_oem < amc_record->guid_count; @@ -2239,7 +2240,7 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record, int ch_index = 0; amc_record->ch_desc = malloc((amc_record->ch_count) * \ sizeof(struct fru_picmgext_amc_channel_desc_record)); - if (amc_record->ch_desc == NULL) { + if (!amc_record->ch_desc) { return ERROR_STATUS; } for (ch_index = 0; ch_index < amc_record->ch_count; @@ -2265,7 +2266,7 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record, int i=0; amc_record->link_desc = malloc(amc_record->link_desc_count * \ sizeof(struct fru_picmgext_amc_link_desc_record)); - if (amc_record->link_desc == NULL) { + if (!amc_record->link_desc) { return ERROR_STATUS; } for (i = 0; i< amc_record->link_desc_count; i++) { @@ -2359,7 +2360,7 @@ ipmi_ek_display_fru_header(char *filename) int ret = 0; input_file = fopen(filename, "r"); - if (input_file == NULL) { + if (!input_file) { lprintf(LOG_ERR, "File '%s' not found.", filename); return (ERROR_STATUS); } @@ -2423,7 +2424,7 @@ ipmi_ek_display_fru_header_detail(char *filename) struct tm *strtm; input_file = fopen(filename, "r"); - if (input_file == NULL) { + if (!input_file) { lprintf(LOG_ERR, "File '%s' not found.", filename); return (-1); } @@ -2619,7 +2620,7 @@ ipmi_ek_display_chassis_info_area(FILE *input_file, long offset) unsigned char ch_type = 0; unsigned int len; - if (input_file == NULL) { + if (!input_file) { lprintf(LOG_ERR, "No file stream to read."); return (-1); } @@ -2702,8 +2703,7 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type, unsigned char len = 0; unsigned int size_board = 0; int custom_fields = 0; - if (input_file == NULL || board_type == NULL - || board_length == NULL) { + if (!input_file || !board_type || !board_length) { return (size_t)(-1); } file_offset = ftell(input_file); @@ -2732,7 +2732,7 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type, unsigned char *data, *str; unsigned int i = 0; data = malloc(size_board + 1); /* Make room for type/length field */ - if (data == NULL) { + if (!data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return (size_t)(-1); } @@ -2788,7 +2788,7 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type, unsigned char *additional_data, *str; unsigned int i = 0; additional_data = malloc(size_board + 1); /* Make room for type/length field */ - if (additional_data == NULL) { + if (!additional_data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return (size_t)(-1); } @@ -2796,7 +2796,7 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type, ret = fread(additional_data + 1, size_board, 1, input_file); if ((ret != 1) || ferror(input_file)) { lprintf(LOG_ERR, "Invalid Additional Data!"); - if (additional_data != NULL) { + if (additional_data) { free(additional_data); additional_data = NULL; } @@ -2861,7 +2861,7 @@ ipmi_ek_display_product_info_area(FILE *input_file, long offset) unsigned char data = 0; unsigned int len = 0; - if (input_file == NULL) { + if (!input_file) { lprintf(LOG_ERR, "No file stream to read."); return (-1); } @@ -2961,14 +2961,14 @@ ipmi_ek_display_record(struct ipmi_ek_multi_header *record, struct ipmi_ek_multi_header *list_head, struct ipmi_ek_multi_header *list_last) { - if (list_head == NULL) { + if (!list_head) { printf("***empty list***\n"); return; } printf("%s\n", EQUAL_LINE_LIMITER); printf("FRU Multi Info area\n"); printf("%s\n", EQUAL_LINE_LIMITER); - for (record = list_head; record != NULL; record = record->next) { + for (record = list_head; record; record = record->next) { printf("Record Type ID: 0x%02x\n", record->header.type); printf("Record Format version: 0x%02x\n", record->header.format); @@ -4054,7 +4054,7 @@ ipmi_ekanalyzer_fru_file2structure(char *filename, int ret = 0; input_file = fopen(filename, "r"); - if (input_file == NULL) { + if (!input_file) { lprintf(LOG_ERR, "File: '%s' is not found", filename); return ERROR_STATUS; } @@ -4081,7 +4081,7 @@ ipmi_ekanalyzer_fru_file2structure(char *filename, fseek(input_file, multi_offset, SEEK_SET); while (!feof(input_file)) { *list_record = malloc(sizeof(struct ipmi_ek_multi_header)); - if (*list_record == NULL) { + if (!(*list_record)) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return ERROR_STATUS; } @@ -4099,7 +4099,7 @@ ipmi_ekanalyzer_fru_file2structure(char *filename, continue; } (*list_record)->data = malloc((*list_record)->header.len); - if ((*list_record)->data == NULL) { + if (!(*list_record)->data) { lprintf(LOG_ERR, "Failed to allocation memory size %d\n", (*list_record)->header.len); record_count++; @@ -4163,18 +4163,18 @@ ipmi_ek_add_record2list(struct ipmi_ek_multi_header **record, struct ipmi_ek_multi_header **list_head, struct ipmi_ek_multi_header **list_last) { - if (*list_head == NULL) { - *list_head = *record; - (*record)->prev = NULL; - if (verbose > 2) { - printf("Adding first record to list\n"); - } - } else { + if (*list_head) { (*list_last)->next = *record; (*record)->prev = *list_last; if (verbose > 2) { printf("Add 1 record to list\n"); } + } else { + *list_head = *record; + (*record)->prev = NULL; + if (verbose > 2) { + printf("Adding first record to list\n"); + } } *list_last = *record; (*record)->next = NULL; @@ -4203,12 +4203,12 @@ ipmi_ek_remove_record_from_list(struct ipmi_ek_multi_header *record, struct ipmi_ek_multi_header **list_head, struct ipmi_ek_multi_header **list_last) { - if (record->prev == NULL) { + if (!record->prev) { *list_head = record->next; } else { record->prev->next = record->next; } - if (record->next == NULL) { + if (!record->next) { (*list_last) = record->prev; } else { record->next->prev = record->prev; diff --git a/lib/ipmi_event.c b/lib/ipmi_event.c index 799fa32..0088032 100644 --- a/lib/ipmi_event.c +++ b/lib/ipmi_event.c @@ -108,7 +108,7 @@ ipmi_send_platform_event(struct ipmi_intf * intf, struct platform_event_msg * em ipmi_event_msg_print(intf, emsg); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Platform Event Message command failed"); return -1; } @@ -210,13 +210,13 @@ ipmi_event_find_offset(struct ipmi_intf *intf, uint8_t sensor_type, uint8_t even { const struct ipmi_event_sensor_types *evt; - if (desc == NULL || sensor_type == 0 || event_type == 0) { + if (!desc || sensor_type == 0 || event_type == 0) { return 0x00; } for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type); - evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) { - if (evt->desc != NULL && + evt; evt = ipmi_get_next_event_sensor_type(evt)) { + if (evt->desc && strncasecmp(desc, evt->desc, __maxlen(desc, evt->desc)) == 0) { return evt->offset; } @@ -245,7 +245,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e int off; uint8_t target, lun, channel; - if (id == NULL) { + if (!id) { lprintf(LOG_ERR, "No sensor ID supplied"); return -1; } @@ -253,7 +253,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e memset(&emsg, 0, sizeof(struct platform_event_msg)); emsg.evm_rev = 0x04; - if (evdir == NULL) + if (!evdir) emsg.event_dir = EVENT_DIR_ASSERT; else if (strncasecmp(evdir, "assert", 6) == 0) emsg.event_dir = EVENT_DIR_ASSERT; @@ -266,7 +266,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e printf("Finding sensor %s... ", id); sdr = ipmi_sdr_find_sdr_byid(intf, id); - if (sdr == NULL) { + if (!sdr) { printf("not found!\n"); return -1; } @@ -303,7 +303,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e int hilo = 0; off = 1; - if (state == NULL || strncasecmp(state, "list", 4) == 0) { + if (!state || strncasecmp(state, "list", 4) == 0) { printf("Sensor States:\n"); printf(" lnr : Lower Non-Recoverable \n"); printf(" lcr : Lower Critical\n"); @@ -348,7 +348,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e rsp = ipmi_sdr_get_sensor_thresholds(intf, emsg.sensor_num, target, lun, channel); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Command Get Sensor Thresholds failed: invalid response."); return (-1); @@ -363,7 +363,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e rsp = ipmi_sdr_get_sensor_hysteresis(intf, emsg.sensor_num, target, lun, channel); - if (rsp != NULL && !rsp->ccode) + if (rsp && !rsp->ccode) off = dir ? rsp->data[0] : rsp->data[1]; if (off <= 0) off = 1; @@ -400,7 +400,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e /* * print list of available states for this sensor */ - if (state == NULL || strncasecmp(state, "list", 4) == 0) { + if (!state || strncasecmp(state, "list", 4) == 0) { print_sensor_states(intf, emsg.sensor_type, emsg.event_type); printf("Sensor State Shortcuts:\n"); for (x = 0; x < sizeof(digi_on)/sizeof(*digi_on); x++) { @@ -440,7 +440,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e /* * print list of available states for this sensor */ - if (state == NULL || strncasecmp(state, "list", 4) == 0) { + if (!state || strncasecmp(state, "list", 4) == 0) { print_sensor_states(intf, emsg.sensor_type, emsg.event_type); return 0; } @@ -460,7 +460,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e /* * print list of available states for this sensor */ - if (state == NULL || strncasecmp(state, "list", 4) == 0) { + if (!state || strncasecmp(state, "list", 4) == 0) { print_sensor_states(intf, emsg.sensor_type, emsg.event_type); return 0; } @@ -494,7 +494,7 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file) uint8_t chmed; int rc = 0; - if (file == NULL) + if (!file) return -1; memset(rqdata, 0, 8); @@ -514,11 +514,11 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file) } fp = ipmi_open_file_read(file); - if (fp == NULL) + if (!fp) return -1; while (feof(fp) == 0) { - if (fgets(buf, 1024, fp) == NULL) + if (!fgets(buf, 1024, fp)) continue; /* clip off optional comment tail indicated by # */ @@ -574,7 +574,7 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file) ipmi_sel_print_std_entry(intf, &sel_event); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Platform Event Message command failed"); rc = -1; } diff --git a/lib/ipmi_firewall.c b/lib/ipmi_firewall.c index e2398c2..4a56356 100644 --- a/lib/ipmi_firewall.c +++ b/lib/ipmi_firewall.c @@ -235,7 +235,7 @@ _get_netfn_support(struct ipmi_intf * intf, int channel, unsigned char * lun, un req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get NetFn Support command failed"); return -1; } @@ -289,7 +289,7 @@ _get_command_support(struct ipmi_intf * intf, req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Command Support (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn); return -1; } @@ -316,7 +316,7 @@ _get_command_support(struct ipmi_intf * intf, req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Command Support (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn); return -1; } @@ -368,7 +368,7 @@ _get_command_configurable(struct ipmi_intf * intf, req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Configurable Command (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn); return -1; } @@ -395,7 +395,7 @@ _get_command_configurable(struct ipmi_intf * intf, req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Configurable Command (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn); return -1; } @@ -447,7 +447,7 @@ _get_command_enables(struct ipmi_intf * intf, req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Command Enables (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn); return -1; } @@ -474,7 +474,7 @@ _get_command_enables(struct ipmi_intf * intf, req.msg.data_len = 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Command Enables (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn); return -1; } @@ -558,7 +558,7 @@ _set_command_enables(struct ipmi_intf * intf, req.msg.data_len = 19; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set Command Enables (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn); return -1; } @@ -579,7 +579,7 @@ _set_command_enables(struct ipmi_intf * intf, req.msg.data_len = 19; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set Command Enables (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn); return -1; } @@ -625,7 +625,7 @@ _get_subfn_support(struct ipmi_intf * intf, req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Command Sub-function Support (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command); return -1; } @@ -672,7 +672,7 @@ _get_subfn_configurable(struct ipmi_intf * intf, req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Configurable Command Sub-function (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command); return -1; } @@ -719,7 +719,7 @@ _get_subfn_enables(struct ipmi_intf * intf, req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Command Sub-function Enables (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command); return -1; } @@ -787,7 +787,7 @@ _set_subfn_enables(struct ipmi_intf * intf, req.msg.data_len = 8; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set Command Sub-function Enables (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command); return -1; } diff --git a/lib/ipmi_fru.c b/lib/ipmi_fru.c index a41a256..fdfa2a7 100644 --- a/lib/ipmi_fru.c +++ b/lib/ipmi_fru.c @@ -49,6 +49,7 @@ #endif #define FRU_MULTIREC_CHUNK_SIZE (255 + sizeof(struct fru_multirec_header)) +#define FRU_FIELD_VALID(a) (a && a[0]) static const char *section_id[4] = { "Internal Use Section", @@ -145,7 +146,7 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset) return NULL; } str = malloc(size+1); - if (str == NULL) + if (!str) return NULL; memset(str, 0, size+1); @@ -211,7 +212,7 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset) int is_valid_filename(const char *input_filename) { - if (input_filename == NULL) { + if (!input_filename) { lprintf(LOG_ERR, "ERROR: NULL pointer passed."); return (-1); } @@ -271,7 +272,7 @@ build_fru_bloc(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, " Device not present (No Response)"); return NULL; } @@ -679,7 +680,7 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, msg_data[3] = (uint8_t)tmp; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_NOTICE, "FRU Read failed"); break; } @@ -785,7 +786,7 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, msg_data[3] = (uint8_t)tmp; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_NOTICE, "FRU Read failed"); break; } @@ -834,7 +835,7 @@ fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru, i = last_off = offset; fru_data = malloc(fru->size + 1); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, " Out of memory!"); return; } @@ -912,7 +913,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, } fru_data = malloc(fru_len); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return; } @@ -940,7 +941,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, i++; fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Chassis Part Number : %s\n", fru_area); } @@ -949,7 +950,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Chassis Serial : %s\n", fru_area); } @@ -962,7 +963,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, { int j = i; fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Chassis Extra : %s\n", fru_area); } @@ -975,7 +976,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, } } - if (fru_data != NULL) { + if (fru_data) { free(fru_data); fru_data = NULL; } @@ -1012,7 +1013,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, } fru_data = malloc(fru_len); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return; } @@ -1044,7 +1045,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, i += 3; /* skip mfg. date time */ fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Board Mfg : %s\n", fru_area); } @@ -1053,7 +1054,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Board Product : %s\n", fru_area); } @@ -1062,7 +1063,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Board Serial : %s\n", fru_area); } @@ -1071,7 +1072,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Board Part Number : %s\n", fru_area); } @@ -1080,7 +1081,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0 && verbose > 0) { printf(" Board FRU ID : %s\n", fru_area); } @@ -1093,7 +1094,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, { int j = i; fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Board Extra : %s\n", fru_area); } @@ -1104,7 +1105,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, break; } - if (fru_data != NULL) { + if (fru_data) { free(fru_data); fru_data = NULL; } @@ -1138,7 +1139,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, } fru_data = malloc(fru_len); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return; } @@ -1161,7 +1162,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, i = 3; fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Product Manufacturer : %s\n", fru_area); } @@ -1170,7 +1171,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Product Name : %s\n", fru_area); } @@ -1179,7 +1180,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Product Part Number : %s\n", fru_area); } @@ -1188,7 +1189,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Product Version : %s\n", fru_area); } @@ -1197,7 +1198,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Product Serial : %s\n", fru_area); } @@ -1206,7 +1207,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Product Asset Tag : %s\n", fru_area); } @@ -1215,7 +1216,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, } fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0 && verbose > 0) { printf(" Product FRU ID : %s\n", fru_area); } @@ -1228,7 +1229,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, { int j = i; fru_area = get_fru_area_str(fru_data, &i); - if (fru_area != NULL) { + if (fru_area) { if (strlen(fru_area) > 0) { printf(" Product Extra : %s\n", fru_area); } @@ -1239,7 +1240,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, break; } - if (fru_data != NULL) { + if (fru_data) { free(fru_data); fru_data = NULL; } @@ -1268,7 +1269,7 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru, last_off = offset; fru_data = malloc(FRU_MULTIREC_CHUNK_SIZE); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return; } @@ -2891,7 +2892,7 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return -1; } @@ -2928,7 +2929,7 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return 1; } @@ -3009,7 +3010,7 @@ ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru) uint32_t save_channel; int rc = 0; - if (fru == NULL) + if (!fru) return __ipmi_fru_print(intf, 0); /* Logical FRU Device @@ -3107,7 +3108,7 @@ ipmi_fru_print_all(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Device ID command failed"); return -1; } @@ -3127,14 +3128,15 @@ ipmi_fru_print_all(struct ipmi_intf * intf) printf("\n"); } - if ((itr = ipmi_sdr_start(intf, 0)) == NULL) + itr = ipmi_sdr_start(intf, 0); + if (!itr) return -1; /* Walk the SDRs looking for FRU Devices and Management Controller Devices. */ /* For FRU devices, print the FRU from the SDR locator record. */ /* For MC devices, issue FRU commands to the satellite controller to print */ /* FRU data. */ - while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) + while ((header = ipmi_sdr_get_next_header(intf, itr))) { if (header->type == SDR_RECORD_TYPE_MC_DEVICE_LOCATOR ) { /* Check the capabilities of the Management Controller Device */ @@ -3178,7 +3180,7 @@ ipmi_fru_print_all(struct ipmi_intf * intf) /* Print the FRU from the SDR locator record. */ fru = (struct sdr_record_fru_locator *) ipmi_sdr_get_record(intf, header, itr); - if (fru == NULL || !fru->logical) { + if (!fru || !fru->logical) { if (fru) { free(fru); fru = NULL; @@ -3246,7 +3248,7 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf, } pFruBuf = malloc(fru.size); - if (pFruBuf != NULL) { + if (pFruBuf) { printf("Fru Size : %d bytes\n",fru.size); read_fru_area(intf, &fru, fruId, 0, fru.size, pFruBuf); } else { @@ -3254,7 +3256,7 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf, return; } - if(pFruBuf != NULL) + if(pFruBuf) { FILE * pFile; pFile = fopen(pFileName,"wb"); @@ -3314,13 +3316,13 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf, } pFruBuf = malloc(fru.size); - if (pFruBuf == NULL) { + if (!pFruBuf) { lprintf(LOG_ERR, "Cannot allocate %d bytes\n", fru.size); return; } pFile = fopen(pFileName, "rb"); - if (pFile != NULL) { + if (pFile) { len = fread(pFruBuf, 1, fru.size, pFile); printf("Fru Size : %d bytes\n", fru.size); printf("Size to Write : %d bytes\n", len); @@ -3417,7 +3419,7 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return -1; } @@ -3452,7 +3454,7 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , memset(&fru, 0, sizeof(fru)); fru_data = malloc(fru.size + 1); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, " Out of memory!"); return -1; } @@ -3622,7 +3624,7 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return -1; } @@ -3656,7 +3658,7 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , i = last_off = offset; fru_data = malloc(fru.size + 1); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, " Out of memory!"); return -1; } @@ -3740,7 +3742,7 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf, uint32_t fruMultiRecSize = 0; uint32_t offFileMultiRec = 0; uint32_t fileMultiRecSize = 0; - if (pFileName == NULL) { + if (!pFileName) { lprintf(LOG_ERR, "File expected, but none given."); return (-1); } @@ -3757,14 +3759,14 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf, return (-1); } buf = malloc(fileMultiRecSize); - if (buf == NULL) { + if (!buf) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return (-1); } if (ipmi_fru_get_multirec_from_file(pFileName, buf, fileMultiRecSize, offFileMultiRec) != 0) { lprintf(LOG_ERR, "Failed to get multirec from file '%s'.", pFileName); - if (buf != NULL) { + if (buf) { free(buf); buf = NULL; } @@ -3772,7 +3774,7 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf, } if (ipmi_fru_get_adjust_size_from_buffer(buf, &fileMultiRecSize) != 0) { lprintf(LOG_ERR, "Failed to adjust size from buffer."); - if (buf != NULL) { + if (buf) { free(buf); buf = NULL; } @@ -3781,13 +3783,13 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf, if (write_fru_area(intf, &fruInfo, fruId, 0, offFruMultiRec, fileMultiRecSize, buf) != 0) { lprintf(LOG_ERR, "Failed to write FRU area."); - if (buf != NULL) { + if (buf) { free(buf); buf = NULL; } return (-1); } - if (buf != NULL) { + if (buf) { free(buf); buf = NULL; } @@ -3918,7 +3920,7 @@ ipmi_fru_get_multirec_from_file(char * pFileName, uint8_t * pBufArea, { FILE * pFile; uint32_t len = 0; - if (pFileName == NULL) { + if (!pFileName) { lprintf(LOG_ERR, "Invalid file name given."); return (-1); } @@ -4091,7 +4093,7 @@ ipmi_fru_get_internal_use_info( struct ipmi_intf * intf, req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return -1; } @@ -4127,7 +4129,7 @@ ipmi_fru_get_internal_use_info( struct ipmi_intf * intf, req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return 1; } @@ -4270,7 +4272,7 @@ ipmi_fru_read_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName if(rc == 0) { - if(pFileName == NULL) + if(!pFileName) { uint16_t counter; for(counter = 0; counter < size; counter ++) @@ -4673,7 +4675,7 @@ f_type, uint8_t f_index, char *f_string) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); rc = (-1); goto ipmi_fru_set_field_string_out; @@ -4709,7 +4711,7 @@ f_type, uint8_t f_index, char *f_string) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) + if (!rsp) { printf(" Device not present (No Response)\n"); rc = (-1); @@ -4737,9 +4739,7 @@ f_type, uint8_t f_index, char *f_string) } fru_data = malloc( fru.size ); - - if( fru_data == NULL ) - { + if (!fru_data) { printf("Out of memory!\n"); rc = (-1); goto ipmi_fru_set_field_string_out; @@ -4787,14 +4787,14 @@ f_type, uint8_t f_index, char *f_string) /*Seek to field index */ for (i=0; i <= f_index; i++) { fru_field_offset_tmp = fru_field_offset; - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } fru_area = (uint8_t *) get_fru_area_str(fru_data, &fru_field_offset); } - if( (fru_area == NULL ) || strlen((const char *)fru_area) == 0 ) { + if (!FRU_FIELD_VALID(fru_area)) { printf("Field not found !\n"); rc = (-1); goto ipmi_fru_set_field_string_out; @@ -4836,11 +4836,11 @@ f_type, uint8_t f_index, char *f_string) } ipmi_fru_set_field_string_out: - if (fru_data != NULL) { + if (fru_data) { free(fru_data); fru_data = NULL; } - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } @@ -4899,8 +4899,7 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, fru_data_new = malloc( fru.size ); - if( fru_data_old == NULL || fru_data_new == NULL ) - { + if (!fru_data_old || !fru_data_new) { printf("Out of memory!\n"); rc = (-1); goto ipmi_fru_set_field_string_rebuild_out; @@ -4965,14 +4964,14 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, 3) Seek to field index */ for (i = 0;i <= f_index; i++) { fru_field_offset_tmp = fru_field_offset; - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } fru_area = (uint8_t *) get_fru_area_str(fru_data_old, &fru_field_offset); } - if( (fru_area == NULL ) || strlen((const char *)fru_area) == 0 ) { + if (!FRU_FIELD_VALID(fru_area)) { printf("Field not found (1)!\n"); rc = (-1); goto ipmi_fru_set_field_string_rebuild_out; @@ -5200,15 +5199,15 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, printf("Done.\n"); ipmi_fru_set_field_string_rebuild_out: - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } - if (fru_data_new != NULL) { + if (fru_data_new) { free(fru_data_new); fru_data_new = NULL; } - if (fru_data_old != NULL) { + if (fru_data_old) { free(fru_data_old); fru_data_old = NULL; } diff --git a/lib/ipmi_fwum.c b/lib/ipmi_fwum.c index 2b1f233..90f5183 100644 --- a/lib/ipmi_fwum.c +++ b/lib/ipmi_fwum.c @@ -258,7 +258,7 @@ ipmi_fwum_fwupgrade(struct ipmi_intf *intf, char *file, int action) unsigned short padding; unsigned long fsize = 0; unsigned char not_used; - if (file == NULL) { + if (!file) { lprintf(LOG_ERR, "No file given."); return (-1); } @@ -312,7 +312,7 @@ KfwumGetFileSize(const char *pFileName, unsigned long *pFileSize) { FILE *pFileHandle = NULL; pFileHandle = fopen(pFileName, "rb"); - if (pFileHandle == NULL) { + if (!pFileHandle) { return (-1); } if (fseek(pFileHandle, 0L , SEEK_END) == 0) { @@ -342,7 +342,7 @@ KfwumSetupBuffersFromFile(const char *pFileName, unsigned long fileSize) int qty = 0; pFileHandle = fopen(pFileName, "rb"); - if (pFileHandle == NULL) { + if (!pFileHandle) { lprintf(LOG_ERR, "Failed to open '%s' for reading.", pFileName); return (-1); @@ -501,14 +501,14 @@ KfwumGetInfo(struct ipmi_intf *intf, unsigned char output, printf("Protocol Revision :"); printf(" > 5 optimizing buffers\n"); } - if (strstr(intf->name,"lan") != NULL) { + if (strstr(intf->name,"lan")) { /* also covers lanplus */ save_fw_nfo.bufferSize = KFWUM_SMALL_BUFFER; if (verbose) { printf("IOL payload size : %d\n", save_fw_nfo.bufferSize); } - } else if ((strstr(intf->name,"open")!= NULL) + } else if (strstr(intf->name,"open") && intf->target_addr != IPMI_BMC_SLAVE_ADDR && (intf->target_addr != intf->my_addr)) { save_fw_nfo.bufferSize = KFWUM_SMALL_BUFFER; @@ -549,7 +549,7 @@ KfwumGetDeviceInfo(struct ipmi_intf *intf, unsigned char output, req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in Get Device Id Command"); return (-1); } else if (rsp->ccode) { @@ -610,7 +610,7 @@ KfwumGetStatus(struct ipmi_intf * intf) req.msg.data = &counter; req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in FWUM Firmware Get Status Command."); rc = (-1); @@ -668,7 +668,7 @@ KfwumManualRollback(struct ipmi_intf *intf) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in FWUM Manual Rollback Command."); return (-1); } else if (rsp->ccode) { @@ -707,7 +707,7 @@ KfwumStartFirmwareImage(struct ipmi_intf *intf, unsigned long length, req.msg.data_len = 6; } rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in FWUM Firmware Start Firmware Image Download Command."); return (-1); @@ -755,13 +755,13 @@ KfwumSaveFirmwareImage(struct ipmi_intf *intf, unsigned char sequenceNumber, /* + 1 => sequenceNumber*/ } rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in FWUM Firmware Save Firmware Image Download Command."); /* We don't receive "C7" on errors with IOL, * instead we receive nothing */ - if (strstr(intf->name, "lan") != NULL) { + if (strstr(intf->name, "lan")) { no_rsp++; if (no_rsp < FWUM_SAVE_FIRMWARE_NO_RESPONSE_LIMIT) { *pInBufLength -= 1; @@ -836,7 +836,7 @@ KfwumFinishFirmwareImage(struct ipmi_intf *intf, tKFWUM_InFirmwareInfo firmInfo) /* Infinite loop if BMC doesn't reply or replies 0xc0 every time. */ do { rsp = intf->sendrecv(intf, &req); - } while (rsp == NULL || rsp->ccode == 0xc0); + } while (!rsp || rsp->ccode == 0xc0); if (rsp->ccode) { lprintf(LOG_ERR, @@ -917,7 +917,7 @@ KfwumStartFirmwareUpgrade(struct ipmi_intf *intf) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in FWUM Firmware Start Firmware Upgrade Command"); rc = (-1); @@ -958,7 +958,7 @@ KfwumGetTraceLog(struct ipmi_intf *intf) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in FWUM Firmware Get Trace Log Command"); rc = (-1); diff --git a/lib/ipmi_gendev.c b/lib/ipmi_gendev.c index 45ebd18..845f81a 100644 --- a/lib/ipmi_gendev.c +++ b/lib/ipmi_gendev.c @@ -88,8 +88,7 @@ ipmi_gendev_get_eeprom_size( lprintf(LOG_ERR, "DevType : %x", dev->dev_type); lprintf(LOG_ERR, "DevType Mod: %x", dev->dev_type_modifier); */ - if( info != NULL) - { + if (info) { switch(dev->dev_type) { case 0x08: // 24C01 @@ -280,8 +279,7 @@ ipmi_gendev_read_file( msize ); - if (rsp != NULL) - { + if (rsp) { retryCounter = GENDEV_RETRY_COUNT; rc = 0; } @@ -457,8 +455,6 @@ ipmi_gendev_write_file( break; } - - for( retryCounter = 0; retryCounter Read to file eeprom specify by Generic Device Locators"); lprintf(LOG_ERR, " write Write from file eeprom specify by Generic Device Locators"); - } - else if ( strncmp(argv[0], "list", 4) == 0) - { - rc = ipmi_sdr_print_sdr(intf, - SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR); - } - else if (strncmp(argv[0], "read", 4) == 0) - { + } else if (strncmp(argv[0], "list", 4) == 0) { + rc = ipmi_sdr_print_sdr(intf, SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR); + } else if (strncmp(argv[0], "read", 4) == 0) { if (argc < 3) lprintf(LOG_ERR, "usage: gendev read "); - else - { + else { struct sdr_record_list *sdr; lprintf(LOG_ERR, "Gendev read sdr name : %s", argv[1]); @@ -582,14 +567,12 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv) /* lookup by sensor name */ sdr = ipmi_sdr_find_sdr_byid(intf, argv[1]); - if (sdr == NULL) - { + if (!sdr) { lprintf(LOG_ERR, "Sensor data record not found!"); return -1; } - if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) - { + if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) { lprintf(LOG_ERR, "Target SDR is not a generic device locator"); return -1; } @@ -598,13 +581,10 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv) ipmi_gendev_read_file(intf, sdr->record.genloc, argv[2]); } - } - else if (strncmp(argv[0], "write", 5) == 0) - { + } else if (strncmp(argv[0], "write", 5) == 0) { if (argc < 3) lprintf(LOG_ERR, "usage: gendev write "); - else - { + else { struct sdr_record_list *sdr; lprintf(LOG_ERR, "Gendev write sdr name : %s", argv[1]); @@ -613,25 +593,20 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv) /* lookup by sensor name */ sdr = ipmi_sdr_find_sdr_byid(intf, argv[1]); - if (sdr == NULL) - { + if (!sdr) { lprintf(LOG_ERR, "Sensor data record not found!"); return -1; } - if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) - { + if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) { lprintf(LOG_ERR, "Target SDR is not a generic device locator"); return -1; } lprintf(LOG_ERR, "Gendev write file name: %s", argv[2]); ipmi_gendev_write_file(intf, sdr->record.genloc, argv[2]); - } - } - else - { + } else { lprintf(LOG_ERR, "Invalid gendev command: %s", argv[0]); rc = -1; } diff --git a/lib/ipmi_hpmfwupg.c b/lib/ipmi_hpmfwupg.c index fe9211e..8e98bdd 100644 --- a/lib/ipmi_hpmfwupg.c +++ b/lib/ipmi_hpmfwupg.c @@ -1209,7 +1209,7 @@ HpmFwupgActionUploadFirmware(struct HpmfwupgComponentBitMask components, if (rc == HPMFWUPG_UPLOAD_BLOCK_LENGTH && !bufLengthIsSet) { rc = HPMFWUPG_SUCCESS; /* Retry with a smaller buffer length */ - if (strstr(intf->name,"lan") != NULL && bufLength > 8) { + if (strstr(intf->name,"lan") && bufLength > 8) { bufLength-= 8; lprintf(LOG_INFO, "Trying reduced buffer length: %d", @@ -1389,7 +1389,7 @@ HpmfwupgGetBufferFromFile(char *imageFilename, int rc = HPMFWUPG_SUCCESS; int ret = 0; FILE *pImageFile = fopen(imageFilename, "rb"); - if (pImageFile == NULL) { + if (!pImageFile) { lprintf(LOG_ERR, "Cannot open image file '%s'", imageFilename); return HPMFWUPG_ERROR; @@ -1403,7 +1403,7 @@ HpmfwupgGetBufferFromFile(char *imageFilename, } pFwupgCtx->imageSize = ftell(pImageFile); pFwupgCtx->pImageData = malloc(sizeof(unsigned char)*pFwupgCtx->imageSize); - if (pFwupgCtx->pImageData == NULL) { + if (!pFwupgCtx->pImageData) { lprintf(LOG_ERR, "ipmitool: malloc failure"); fclose(pImageFile); return HPMFWUPG_ERROR; @@ -1434,7 +1434,7 @@ HpmfwupgGetDeviceId(struct ipmi_intf *intf, struct ipm_devid_rsp *pGetDevId) req.msg.cmd = BMC_GET_DEVICE_ID; req.msg.data_len = 0; rsp = HpmfwupgSendCmd(intf, req, NULL); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting device ID."); return HPMFWUPG_ERROR; } @@ -1462,7 +1462,7 @@ HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf, req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgGetTargetUpgCapabilitiesReq); rsp = HpmfwupgSendCmd(intf, req, NULL); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting target upgrade capabilities."); return HPMFWUPG_ERROR; @@ -1539,7 +1539,7 @@ HpmfwupgGetComponentProperties(struct ipmi_intf *intf, req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgGetComponentPropertiesReq); rsp = HpmfwupgSendCmd(intf, req, NULL); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_NOTICE, "Error getting component properties\n"); return HPMFWUPG_ERROR; @@ -1665,7 +1665,7 @@ HpmfwupgAbortUpgrade(struct ipmi_intf *intf, req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgAbortUpgradeReq); rsp = HpmfwupgSendCmd(intf, req, NULL); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error - aborting upgrade."); return HPMFWUPG_ERROR; } @@ -1694,7 +1694,7 @@ HpmfwupgInitiateUpgradeAction(struct ipmi_intf *intf, req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgInitiateUpgradeActionReq); rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error initiating upgrade action."); return HPMFWUPG_ERROR; } @@ -1728,7 +1728,7 @@ HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, /* 2 is the size of the upload struct - data */ req.msg.data_len = 2 + count; rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_NOTICE, "Error uploading firmware block."); return HPMFWUPG_ERROR; } @@ -1805,7 +1805,7 @@ HpmfwupgFinishFirmwareUpload(struct ipmi_intf *intf, req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgFinishFirmwareUploadReq); rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error fininshing firmware upload."); return HPMFWUPG_ERROR; } @@ -1842,7 +1842,7 @@ HpmfwupgActivateFirmware(struct ipmi_intf *intf, req.msg.data_len = sizeof(struct HpmfwupgActivateFirmwareReq) - (!pCtx->req.rollback_override ? 1 : 0); rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error activating firmware."); return HPMFWUPG_ERROR; } @@ -1943,7 +1943,7 @@ HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf, req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgManualFirmwareRollbackReq); rsp = HpmfwupgSendCmd(intf, req, &fwupgCtx); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error sending manual rollback."); return HPMFWUPG_ERROR; } @@ -1981,7 +1981,7 @@ HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgQueryRollbackStatusReq); /* If we are not in upgrade context, we use default timeout values */ - if (pFwupgCtx != NULL) { + if (pFwupgCtx) { struct HpmfwupgImageHeader *pImageHeader; if (pFwupgCtx->pImageData) { pImageHeader = (struct HpmfwupgImageHeader*)pFwupgCtx->pImageData; @@ -2017,7 +2017,7 @@ HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, && ((rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS) || (rsp->ccode == IPMI_CC_TIMEOUT)) && (timeoutSec2 - timeoutSec1 < rollbackTimeout)); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error getting upgrade status."); return HPMFWUPG_ERROR; } @@ -2061,7 +2061,7 @@ HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelftest unsigned int timeoutSec1, timeoutSec2; pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; /* If we are not in upgrade context, we use default timeout values */ - if (pFwupgCtx != NULL) { + if (pFwupgCtx) { /* Getting selftest timeout from new image */ struct HpmfwupgImageHeader *pImageHeader = (struct HpmfwupgImageHeader*) pFwupgCtx->pImageData; @@ -2097,7 +2097,7 @@ HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelftest } while (rsp && (rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS) && (timeoutSec2 - timeoutSec1 < selfTestTimeout)); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_NOTICE, "Error getting upgrade status\n"); return HPMFWUPG_ERROR; } @@ -2131,7 +2131,7 @@ HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, unsigned int timeoutSec1, timeoutSec2; unsigned char retry = 0; /* If we are not in upgrade context, we use default timeout values */ - if (pFwupgCtx != NULL) { + if (pFwupgCtx) { inaccessTimeout = pFwupgCtx->targetCap.inaccessTimeout*5; upgradeTimeout = pFwupgCtx->targetCap.upgradeTimeout*5; } else { @@ -2147,10 +2147,10 @@ HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, do { static unsigned char isValidSize = FALSE; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { #define HPM_LAN_PACKET_RESIZE_LIMIT 6 /* also covers lanplus */ - if (strstr(intf->name, "lan") != NULL) { + if (strstr(intf->name, "lan")) { static int errorCount=0; static struct ipmi_rs fakeRsp; lprintf(LOG_DEBUG, @@ -2215,7 +2215,7 @@ HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, } } /* Handle inaccessibility timeout (rsp = NULL if IOL) */ - if (rsp == NULL || rsp->ccode == 0xff || rsp->ccode == 0xc3 || rsp->ccode == 0xd3) { + if (!rsp || rsp->ccode == 0xff || rsp->ccode == 0xc3 || rsp->ccode == 0xd3) { if (inaccessTimeoutCounter < inaccessTimeout) { timeoutSec2 = time(NULL); if (timeoutSec2 > timeoutSec1) { @@ -2268,7 +2268,7 @@ HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf, unsigned int timeoutSec1, timeoutSec2; struct HpmfwupgGetUpgradeStatusCtx upgStatusCmd; /* If we are not in upgrade context, we use default timeout values */ - if (pFwupgCtx != NULL) { + if (pFwupgCtx) { upgradeTimeout = (unsigned int)(pFwupgCtx->targetCap.upgradeTimeout*5); if (verbose) { printf("Use File Upgrade Capabilities: %i seconds\n", @@ -2465,7 +2465,7 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv) return HPMFWUPG_SUCCESS; } else if ((strcmp(argv[0], "check") == 0)) { /* hpm check */ - if (argv[1] == NULL) { + if (!argv[1]) { rc = HpmfwupgTargetCheck(intf,VIEW_MODE); } else { /* hpm check */ diff --git a/lib/ipmi_ime.c b/lib/ipmi_ime.c index 5f726cd..8de2e4f 100755 --- a/lib/ipmi_ime.c +++ b/lib/ipmi_ime.c @@ -202,7 +202,7 @@ static int ImeGetInfo(struct ipmi_intf *intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Device ID command failed"); return IME_ERROR; } @@ -250,7 +250,7 @@ static int ImeGetInfo(struct ipmi_intf *intf) (devid->product_id[1]<<8)+devid->product_id[0], ipmi_oem_product_info); - if (product!=NULL) + if (product) { printf("Product Name : %s\n", product); } @@ -356,12 +356,7 @@ static int ImeUpgrade(struct ipmi_intf *intf, char* imageFilename) rc = ImeImageCtxFromFile(imageFilename, &imgCtx); - if( - (rc == IME_ERROR) || - (imgCtx.pData == NULL) || - (imgCtx.size == 0) - ) - { + if (rc == IME_ERROR || !imgCtx.pData || !imgCtx.size) { return IME_ERROR; } @@ -509,7 +504,7 @@ static int ImeUpdatePrepare(struct ipmi_intf *intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "UpdatePrepare command failed"); return IME_ERROR; } @@ -544,7 +539,7 @@ static int ImeUpdateOpenArea(struct ipmi_intf *intf) req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "UpdateOpenArea command failed"); return IME_ERROR; } @@ -584,7 +579,7 @@ static int ImeUpdateWriteArea( req.msg.data_len = length + 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "UpdateWriteArea command failed"); return IME_ERROR; } @@ -631,7 +626,7 @@ static int ImeUpdateCloseArea( req.msg.data_len = length; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "UpdateCloseArea command failed"); return IME_ERROR; } @@ -665,7 +660,7 @@ static int ImeUpdateGetStatus(struct ipmi_intf *intf, tImeStatus *pStatus ) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "UpdatePrepare command failed"); return IME_ERROR; } @@ -738,7 +733,7 @@ static int ImeUpdateGetCapabilities(struct ipmi_intf *intf, tImeCaps *pCaps ) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "UpdatePrepare command failed"); return IME_ERROR; } @@ -778,7 +773,7 @@ static int ImeUpdateRegisterUpdate(struct ipmi_intf *intf, tImeUpdateType type) req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "ImeUpdateRegisterUpdate command failed"); return IME_ERROR; } @@ -809,7 +804,7 @@ static int ImeUpdateShowStatus(struct ipmi_intf *intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "UpdatePrepare command failed"); return IME_ERROR; } @@ -878,15 +873,13 @@ static int ImeImageCtxFromFile( { int rc = IME_SUCCESS; FILE* pImageFile = fopen(imageFilename, "rb"); - - if ( pImageFile == NULL ) - { + + if (!pImageFile) { lprintf(LOG_NOTICE,"Cannot open image file %s", imageFilename); rc = IME_ERROR; } - - if ( rc == IME_SUCCESS ) - { + + if (rc == IME_SUCCESS) { /* Get the raw data in file */ fseek(pImageFile, 0, SEEK_END); pImageCtx->size = ftell(pImageFile); @@ -900,32 +893,26 @@ static int ImeImageCtxFromFile( pImageCtx->pData = malloc(sizeof(unsigned char)*pImageCtx->size); rewind(pImageFile); - if ( pImageCtx->pData != NULL ) - { - if (pImageCtx->size < fread(pImageCtx->pData, sizeof(unsigned char), - pImageCtx->size, pImageFile)) - rc = IME_ERROR; - } - else + if (!pImageCtx->pData + || pImageCtx->size < fread(pImageCtx->pData, sizeof(unsigned char), + pImageCtx->size, pImageFile)) { rc = IME_ERROR; } } - + // Calculate checksum CRC8 if ( rc == IME_SUCCESS ) { pImageCtx->crc8 = ImeCrc8(pImageCtx->size, pImageCtx->pData); } - - if( pImageFile != NULL) - { + if (pImageFile) { fclose(pImageFile); } - + return rc; -} +} static uint8_t ImeCrc8( uint32_t length, uint8_t * pBuf ) { diff --git a/lib/ipmi_isol.c b/lib/ipmi_isol.c index fa78010..93bc146 100644 --- a/lib/ipmi_isol.c +++ b/lib/ipmi_isol.c @@ -83,7 +83,7 @@ static int ipmi_get_isol_info(struct ipmi_intf * intf, data[3] = 0x00; /* selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in Get ISOL Config Command"); return -1; } @@ -107,7 +107,7 @@ static int ipmi_get_isol_info(struct ipmi_intf * intf, data[3] = 0x00; /* selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in Get ISOL Config Command"); return -1; } @@ -127,7 +127,7 @@ static int ipmi_get_isol_info(struct ipmi_intf * intf, data[3] = 0x00; /* selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error in Get ISOL Config Command"); return -1; } @@ -271,7 +271,7 @@ static int ipmi_isol_set_param(struct ipmi_intf * intf, */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error setting ISOL parameter '%s'", param); return -1; } @@ -428,7 +428,7 @@ ipmi_isol_deactivate(struct ipmi_intf * intf) data[5] = 0x00; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error deactivating ISOL"); return -1; } @@ -572,7 +572,7 @@ ipmi_isol_red_pill(struct ipmi_intf * intf) int timedout = 0; buffer = (char*)malloc(buffer_size); - if (buffer == NULL) { + if (!buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } diff --git a/lib/ipmi_kontronoem.c b/lib/ipmi_kontronoem.c index d27e99e..8f459b3 100644 --- a/lib/ipmi_kontronoem.c +++ b/lib/ipmi_kontronoem.c @@ -188,7 +188,7 @@ ipmi_kontronoem_send_set_large_buffer(struct ipmi_intf *intf, req.msg.data_len = 2; req.msg.lun = 0x00; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf("Cannot send large buffer command\n"); return(-1); } else if (rsp->ccode) { @@ -243,7 +243,7 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf) /* Set Lun, necessary for this oem command */ req.msg.lun = 0x03; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return (-1); } else if (rsp->ccode) { @@ -252,7 +252,7 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf) } sn_size = rsp->data_len; sn = malloc(sn_size + 1); - if (sn == NULL) { + if (!sn) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return (-1); } @@ -269,7 +269,7 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf) req.msg.data = msg_data; req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); free(sn); sn = NULL; @@ -302,7 +302,7 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf) req.msg.data = msg_data; req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); free(sn); sn = NULL; @@ -328,7 +328,7 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf) /* Set the Board Section */ board_sec_len = (header.offset.product * 8) - (header.offset.board * 8); fru_data = malloc(fru.size); - if (fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); free(sn); sn = NULL; @@ -346,20 +346,20 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf) /* Position at Board Manufacturer */ fru_data_offset = (header.offset.board * 8) + 6; fru_area = get_fru_area_str(fru_data, &fru_data_offset); - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } /* Position at Board Product Name */ fru_area = get_fru_area_str(fru_data, &fru_data_offset); - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } fru_data_offset_tmp = fru_data_offset; /* Position at Serial Number */ fru_area = get_fru_area_str(fru_data, &fru_data_offset_tmp); - if (fru_area == NULL) { + if (!fru_area) { lprintf(LOG_ERR, "Failed to read FRU Area string."); free(fru_data); fru_data = NULL; @@ -420,32 +420,32 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf) /* Position at Product Manufacturer */ fru_data_offset = (header.offset.product * 8) + 3; fru_area = get_fru_area_str(fru_data, &fru_data_offset); - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } /* Position at Product Name */ fru_area = get_fru_area_str(fru_data, &fru_data_offset); - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } /* Position at Product Part */ fru_area = get_fru_area_str(fru_data, &fru_data_offset); - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } /* Position at Product Version */ fru_area = get_fru_area_str(fru_data, &fru_data_offset); - if (fru_area != NULL) { + if (fru_area) { free(fru_area); fru_area = NULL; } fru_data_offset_tmp = fru_data_offset; /* Position at Serial Number */ fru_area = get_fru_area_str(fru_data, &fru_data_offset_tmp); - if (fru_area == NULL) { + if (!fru_area) { lprintf(LOG_ERR, "Failed to read FRU Area string."); free(sn); sn = NULL; @@ -532,7 +532,7 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf) /* Set Lun temporary, necessary for this oem command */ req.msg.lun = 0x03; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf("Device not present (No Response)\n"); return(-1); } else if (rsp->ccode) { @@ -554,7 +554,7 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf) req.msg.data = msg_data; req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return(-1); } else if (rsp->ccode) { @@ -582,7 +582,7 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf) req.msg.data = msg_data; req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf(" Device not present (No Response)\n"); return (-1); } else if (rsp->ccode) { @@ -601,7 +601,7 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf) } board_sec_len = (header.offset.product * 8) - (header.offset.board * 8); fru_data = malloc(fru.size); - if(fru_data == NULL) { + if (!fru_data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return(-1); } @@ -690,7 +690,7 @@ ipmi_kontron_nextboot_set(struct ipmi_intf *intf, int argc, char **argv) /* Set Lun temporary, necessary for this oem command */ req.msg.lun = 0x03; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf("Device not present (No Response)\n"); return(-1); } else if (rsp->ccode) { diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c index f2c1031..183234d 100644 --- a/lib/ipmi_lanp.c +++ b/lib/ipmi_lanp.c @@ -146,7 +146,7 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec } } - if (p == NULL) { + if (!p) { lprintf(LOG_INFO, "Get LAN Parameter failed: Unknown parameter."); return NULL; } @@ -163,7 +163,7 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed", p->desc); return NULL; } @@ -244,7 +244,7 @@ set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan, for (;;) { p = get_lan_param(intf, chan, param); - if (p == NULL) { + if (!p) { sleep(IPMI_LANP_TIMEOUT); if (retry-- == 0) return -1; @@ -360,9 +360,9 @@ ipmi_lanp_lock_state(struct ipmi_intf * intf, uint8_t chan) { struct lan_param * p; p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS); - if (p == NULL) + if (!p) return -1; - if (p->data == NULL) + if (!p->data) return -1; return (p->data[0] & 3); } @@ -473,9 +473,9 @@ lan_set_arp_interval(struct ipmi_intf * intf, uint8_t chan, uint8_t ival) int rc = 0; lp = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP); - if (lp == NULL) + if (!lp) return -1; - if (lp->data == NULL) + if (!lp->data) return -1; if (ival != 0) { @@ -503,9 +503,9 @@ lan_set_arp_generate(struct ipmi_intf * intf, uint8_t data; lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP); - if (lp == NULL) + if (!lp) return -1; - if (lp->data == NULL) + if (!lp->data) return -1; data = lp->data[0]; @@ -527,9 +527,9 @@ lan_set_arp_respond(struct ipmi_intf * intf, uint8_t data; lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP); - if (lp == NULL) + if (!lp) return -1; - if (lp->data == NULL) + if (!lp->data) return -1; data = lp->data[0]; @@ -588,9 +588,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) } p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) { + if (p->data) { printf("%-24s: ", p->desc); p->data[0] &= 3; switch (p->data[0]) { @@ -612,9 +612,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) } p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) { + if (p->data) { printf("%-24s: %s%s%s%s%s\n", p->desc, (p->data[0] & 1<data[0] & 1<data != NULL) { + if (p->data) { printf("%-24s: Callback : %s%s%s%s%s\n", p->desc, (p->data[0] & 1<data[0] & 1<data != NULL) { + if (p->data) { printf("%-24s: ", p->desc); p->data[0] &= 0xf; switch (p->data[0]) { @@ -685,79 +685,79 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) } p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %d.%d.%d.%d\n", p->desc, p->data[0], p->data[1], p->data[2], p->data[3]); p = get_lan_param(intf, chan, IPMI_LANP_SUBNET_MASK); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %d.%d.%d.%d\n", p->desc, p->data[0], p->data[1], p->data[2], p->data[3]); p = get_lan_param(intf, chan, IPMI_LANP_MAC_ADDR); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %s\n", p->desc, mac2str(p->data)); p = get_lan_param(intf, chan, IPMI_LANP_SNMP_STRING); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %s\n", p->desc, p->data); p = get_lan_param(intf, chan, IPMI_LANP_IP_HEADER); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: TTL=0x%02x Flags=0x%02x Precedence=0x%02x TOS=0x%02x\n", p->desc, p->data[0], p->data[1] & 0xe0, p->data[2] & 0xe0, p->data[2] & 0x1e); p = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: ARP Responses %sabled, Gratuitous ARP %sabled\n", p->desc, (p->data[0] & 2) ? "En" : "Dis", (p->data[0] & 1) ? "En" : "Dis"); p = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %.1f seconds\n", p->desc, (float)((p->data[0] + 1) / 2)); p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %d.%d.%d.%d\n", p->desc, p->data[0], p->data[1], p->data[2], p->data[3]); p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %s\n", p->desc, mac2str(p->data)); p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %d.%d.%d.%d\n", p->desc, p->data[0], p->data[1], p->data[2], p->data[3]); p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC); - if (p == NULL) + if (!p) return -1; - if (p->data != NULL) + if (p->data) printf("%-24s: %s\n", p->desc, mac2str(p->data)); p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID); - if (p != NULL && p->data != NULL) { + if (p && p->data) { int id = ((p->data[1] & 0x0f) << 8) + p->data[0]; if (p->data[1] & 0x80) printf("%-24s: %d\n", p->desc, id); @@ -766,25 +766,25 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) } p = get_lan_param(intf, chan, IPMI_LANP_VLAN_PRIORITY); - if (p != NULL && p->data != NULL) + if (p && p->data) printf("%-24s: %d\n", p->desc, p->data[0] & 0x07); /* Determine supported Cipher Suites -- Requires two calls */ p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHER_SUPPORT); - if (p == NULL) + if (!p) return -1; - else if (p->data != NULL) + else if (p->data) { unsigned char cipher_suite_count = p->data[0]; p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHERS); - if (p == NULL) + if (!p) return -1; printf("%-24s: ", p->desc); /* Now we're dangerous. There are only 15 fixed cipher suite IDs, but the spec allows for 16 in the return data.*/ - if ((p->data != NULL) && (p->data_len <= 17)) + if (p->data && p->data_len <= 17) { unsigned int i; for (i = 0; (i < 16) && (i < cipher_suite_count); ++i) @@ -804,9 +804,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) /* RMCP+ Messaging Cipher Suite Privilege Levels */ /* These are the privilege levels for the 15 fixed cipher suites */ p = get_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS); - if (p == NULL) + if (!p) return -1; - if ((p->data != NULL) && (p->data_len == 9)) + if (p->data && 9 == p->data_len) { printf("%-24s: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", p->desc, priv_level_to_char(p->data[1] & 0x0F), @@ -838,9 +838,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan) /* Bad Password Threshold */ p = get_lan_param(intf, chan, IPMI_LANP_BAD_PASS_THRESH); - if (p == NULL) + if (!p) return -1; - if ((p->data != NULL) && (p->data_len == 6)) { + if (p->data && 6 == p->data_len) { int tmp; printf("%-24s: %d\n", p->desc, p->data[1]); @@ -867,13 +867,13 @@ ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * ty char * p; struct lan_param * lp; - if (level == NULL || types == NULL) + if (!level || !types) return -1; lp = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE); - if (lp == NULL) + if (!lp) return -1; - if (lp->data == NULL) + if (!lp->data) return -1; lprintf(LOG_DEBUG, "%-24s: callback=0x%02x user=0x%02x operator=0x%02x admin=0x%02x oem=0x%02x", @@ -942,7 +942,7 @@ ipmi_lan_set_password(struct ipmi_intf *intf, */ ipmi_intf_session_set_password(intf, (char *)password); printf("Password %s for user %d\n", - (password == NULL) ? "cleared" : "set", user_id); + password ? "set" : "cleared", user_id); return 0; } @@ -1206,10 +1206,10 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string) uint8_t data[2]; int rc; - if (string == NULL) { + if (!string) { lprintf(LOG_DEBUG, "Get current VLAN ID from BMC."); p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID); - if (p != NULL && p->data != NULL && p->data_len > 1) { + if (p && p->data && p->data_len > 1) { int id = ((p->data[1] & 0x0f) << 8) + p->data[0]; if (id < 1 || id > 4094) { lprintf(LOG_ERR, @@ -1671,9 +1671,9 @@ is_alert_destination(struct ipmi_intf * intf, uint8_t channel, uint8_t alert) struct lan_param * p; p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST); - if (p == NULL) + if (!p) return 0; - if (p->data == NULL) + if (!p->data) return 0; if (alert <= (p->data[0] & 0xf)) @@ -1693,15 +1693,14 @@ ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert) uint8_t paddr[PADDR_LEN]; lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_TYPE, alert); - if (lp_ptr == NULL || lp_ptr->data == NULL + if (!lp_ptr || !lp_ptr->data || lp_ptr->data_len < PTYPE_LEN) { return (-1); } memcpy(ptype, lp_ptr->data, PTYPE_LEN); lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_ADDR, alert); - if (lp_ptr == NULL || lp_ptr->data == NULL - || lp_ptr->data_len < PADDR_LEN) { + if (!lp_ptr || !lp_ptr->data || lp_ptr->data_len < PADDR_LEN) { return (-1); } memcpy(paddr, lp_ptr->data, PADDR_LEN); @@ -1764,9 +1763,9 @@ ipmi_lan_alert_print_all(struct ipmi_intf * intf, uint8_t channel) struct lan_param * p; p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST); - if (p == NULL) + if (!p) return -1; - if (p->data == NULL) + if (!p->data) return -1; ndest = p->data[0] & 0xf; @@ -1804,7 +1803,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, (get_cmdline_ipaddr(argv[1], temp) == 0)) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert); - if (p == NULL) { + if (!p) { return (-1); } memcpy(data, p->data, p->data_len); @@ -1819,7 +1818,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, (str2mac(argv[1], temp) == 0)) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert); - if (p == NULL) { + if (!p) { return (-1); } memcpy(data, p->data, p->data_len); @@ -1833,7 +1832,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, else if (strncasecmp(argv[0], "gateway", 7) == 0) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert); - if (p == NULL) { + if (!p) { return (-1); } memcpy(data, p->data, p->data_len); @@ -1859,7 +1858,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, else if (strncasecmp(argv[0], "ack", 3) == 0) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert); - if (p == NULL) { + if (!p) { return (-1); } memcpy(data, p->data, p->data_len); @@ -1884,7 +1883,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, else if (strncasecmp(argv[0], "type", 4) == 0) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert); - if (p == NULL) { + if (!p) { return (-1); } memcpy(data, p->data, p->data_len); @@ -1912,7 +1911,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, else if (strncasecmp(argv[0], "time", 4) == 0) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert); - if (p == NULL) { + if (!p) { return (-1); } memcpy(data, p->data, p->data_len); @@ -1928,7 +1927,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, else if (strncasecmp(argv[0], "retry", 5) == 0) { /* get current parameter */ p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert); - if (p == NULL) { + if (!p) { return (-1); } memcpy(data, p->data, p->data_len); @@ -2067,7 +2066,7 @@ ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan) req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get LAN Stats command failed"); return (-1); } @@ -2143,7 +2142,7 @@ ipmi_lan_stats_clear(struct ipmi_intf * intf, uint8_t chan) req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_INFO, "Get LAN Stats command failed"); return (-1); } diff --git a/lib/ipmi_lanp6.c b/lib/ipmi_lanp6.c index 7ede272..4af6d8b 100644 --- a/lib/ipmi_lanp6.c +++ b/lib/ipmi_lanp6.c @@ -333,7 +333,7 @@ ipmi_lanp_err(const struct ipmi_rs *rsp, const struct ipmi_lanp *p, int log_level = LOG_ERR; int err; - if (rsp == NULL) { + if (!rsp) { reason = "No response"; err = -1; } else { @@ -354,7 +354,7 @@ ipmi_lanp_err(const struct ipmi_rs *rsp, const struct ipmi_lanp *p, reason = val2str(rsp->ccode, lanp_cc_vals); } - if (reason == NULL) { + if (!reason) { /* print completion code value */ snprintf(cc_msg, sizeof(cc_msg), "CC=%02x", rsp->ccode); reason = cc_msg; @@ -403,7 +403,7 @@ ipmi_get_dynamic_oem_lanp(void *priv, const struct ipmi_lanp *param, param->name, set_selector, block_selector); rsp = lp->intf->sendrecv(lp->intf, &req); - if (rsp == NULL || rsp->ccode) { + if (!rsp || rsp->ccode) { return ipmi_lanp_err(rsp, param, "get", quiet); } @@ -467,7 +467,7 @@ ipmi_set_dynamic_oem_lanp(void *priv, const struct ipmi_lanp *param, lprintf(LOG_INFO, "Setting parameter '%s'", param->name); rsp = lp->intf->sendrecv(lp->intf, &req); - if (rsp == NULL || rsp->ccode) { + if (!rsp || rsp->ccode) { return ipmi_lanp_err(rsp, param, "set", 0); } diff --git a/lib/ipmi_main.c b/lib/ipmi_main.c index 2d367c2..166995c 100644 --- a/lib/ipmi_main.c +++ b/lib/ipmi_main.c @@ -107,14 +107,14 @@ ipmi_password_file_read(char * filename) int l; pass = malloc(21); - if (pass == NULL) { + if (!pass) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } memset(pass, 0, 21); fp = ipmi_open_file_read((const char *)filename); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Unable to open password file %s", filename); free(pass); @@ -122,7 +122,7 @@ ipmi_password_file_read(char * filename) } /* read in id */ - if (fgets(pass, 21, fp) == NULL) { + if (!fgets(pass, 21, fp)) { lprintf(LOG_ERR, "Unable to read password from file %s", filename); free(pass); @@ -151,10 +151,10 @@ ipmi_cmd_print(struct ipmi_cmd * cmdlist) struct ipmi_cmd * cmd; int hdr = 0; - if (cmdlist == NULL) + if (!cmdlist) return; - for (cmd=cmdlist; cmd->func != NULL; cmd++) { - if (cmd->desc == NULL) + for (cmd=cmdlist; cmd->func; cmd++) { + if (!cmd->desc) continue; if (hdr == 0) { lprintf(LOG_NOTICE, "Commands:"); @@ -185,8 +185,8 @@ ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv) struct ipmi_cmd * cmd = intf->cmdlist; /* hook to run a default command if nothing specified */ - if (name == NULL) { - if (cmd->func == NULL || cmd->name == NULL) + if (!name) { + if (!cmd->func || !cmd->name) return -1; else if (strncmp(cmd->name, "default", 7) == 0) return cmd->func(intf, 0, NULL); @@ -197,11 +197,11 @@ ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv) } } - for (cmd=intf->cmdlist; cmd->func != NULL; cmd++) { + for (cmd=intf->cmdlist; cmd->func; cmd++) { if (strncmp(name, cmd->name, __maxlen(cmd->name, name)) == 0) break; } - if (cmd->func == NULL) { + if (!cmd->func) { cmd = intf->cmdlist; if (strncmp(cmd->name, "default", 7) == 0) return cmd->func(intf, argc+1, argv-1); @@ -263,7 +263,7 @@ ipmi_option_usage(const char * progname, struct ipmi_cmd * cmdlist, struct ipmi_ ipmi_intf_print(intflist); - if (cmdlist != NULL) + if (cmdlist) ipmi_cmd_print(cmdlist); } /* ipmi_catch_sigint - Handle the interrupt signal (Ctrl-C), close the @@ -276,7 +276,7 @@ ipmi_option_usage(const char * progname, struct ipmi_cmd * cmdlist, struct ipmi_ */ void ipmi_catch_sigint() { - if (ipmi_main_intf != NULL) { + if (ipmi_main_intf) { printf("\nSIGN INT: Close Interface %s\n",ipmi_main_intf->desc); /* reduce retry count to a single retry */ ipmi_main_intf->ssn_params.retry = 1; @@ -351,7 +351,7 @@ ipmi_main(int argc, char ** argv, /* save program name */ progname = strrchr(argv[0], '/'); - progname = ((progname == NULL) ? argv[0] : progname+1); + progname = ((!progname) ? argv[0] : progname+1); signal(SIGINT, ipmi_catch_sigint); memset(kgkey, 0, sizeof(kgkey)); @@ -364,13 +364,13 @@ ipmi_main(int argc, char ** argv, intfname = NULL; } intfname = strdup(optarg); - if (intfname == NULL) { + if (!intfname) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } - if (intflist != NULL) { + if (intflist) { found = 0; - for (sup=intflist; sup->name != NULL; sup++) { + for (sup=intflist; sup->name; sup++) { if (strncmp(sup->name, intfname, strlen(intfname)) == 0 && strncmp(sup->name, intfname, strlen(sup->name)) == 0 && sup->supported == 1) @@ -445,7 +445,7 @@ ipmi_main(int argc, char ** argv, hostname = NULL; } hostname = strdup(optarg); - if (hostname == NULL) { + if (!hostname) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -456,7 +456,7 @@ ipmi_main(int argc, char ** argv, password = NULL; } password = ipmi_password_file_read(optarg); - if (password == NULL) + if (!password) lprintf(LOG_ERR, "Unable to read password " "from file %s", optarg); break; @@ -466,14 +466,14 @@ ipmi_main(int argc, char ** argv, #else tmp_pass = getpass("Password: "); #endif - if (tmp_pass != NULL) { + if (tmp_pass) { if (password) { free(password); password = NULL; } password = strdup(tmp_pass); tmp_pass = NULL; - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -513,7 +513,7 @@ ipmi_main(int argc, char ** argv, #else tmp_pass = getpass("Key: "); #endif - if (tmp_pass != NULL) { + if (tmp_pass) { memset(kgkey, 0, sizeof(kgkey)); strncpy((char *)kgkey, tmp_pass, sizeof(kgkey) - 1); @@ -530,7 +530,7 @@ ipmi_main(int argc, char ** argv, goto out_free; } username = strdup(optarg); - if (username == NULL) { + if (!username) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -541,7 +541,7 @@ ipmi_main(int argc, char ** argv, sdrcache = NULL; } sdrcache = strdup(optarg); - if (sdrcache == NULL) { + if (!sdrcache) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -553,7 +553,7 @@ ipmi_main(int argc, char ** argv, free(devfile); } devfile = strdup(optarg); - if (devfile == NULL) { + if (!devfile) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -597,7 +597,7 @@ ipmi_main(int argc, char ** argv, oemtype = NULL; } oemtype = strdup(optarg); - if (oemtype == NULL) { + if (!oemtype) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -630,7 +630,7 @@ ipmi_main(int argc, char ** argv, password = NULL; } password = strdup(optarg); - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -646,7 +646,7 @@ ipmi_main(int argc, char ** argv, password = NULL; } password = strdup(tmp_env); - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -657,7 +657,7 @@ ipmi_main(int argc, char ** argv, password = NULL; } password = strdup(tmp_env); - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -731,7 +731,7 @@ ipmi_main(int argc, char ** argv, seloem = NULL; } seloem = strdup(optarg); - if (seloem == NULL) { + if (!seloem) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -784,17 +784,17 @@ ipmi_main(int argc, char ** argv, * and the authtype was not explicitly set to NONE * then prompt the user. */ - if (hostname != NULL && password == NULL && + if (hostname && !password && (authtype != IPMI_SESSION_AUTHTYPE_NONE || authtype < 0)) { #ifdef HAVE_GETPASSPHRASE tmp_pass = getpassphrase("Password: "); #else tmp_pass = getpass("Password: "); #endif - if (tmp_pass != NULL) { + if (tmp_pass) { password = strdup(tmp_pass); tmp_pass = NULL; - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } @@ -806,15 +806,15 @@ ipmi_main(int argc, char ** argv, * otherwise the default is hardcoded * to use the first entry in the list */ - if (intfname == NULL && hostname != NULL) { + if (!intfname && hostname) { intfname = strdup("lan"); - if (intfname == NULL) { + if (!intfname) { lprintf(LOG_ERR, "%s: malloc failure", progname); goto out_free; } } - if (password != NULL && intfname != NULL) { + if (password && intfname) { if (strcmp(intfname, "lan") == 0 && strlen(password) > 16) { lprintf(LOG_ERR, "%s: password is longer than 16 bytes.", intfname); rc = -1; @@ -824,11 +824,11 @@ ipmi_main(int argc, char ** argv, rc = -1; goto out_free; } - } /* if (password != NULL && intfname != NULL) */ + } /* load interface */ ipmi_main_intf = ipmi_intf_load(intfname); - if (ipmi_main_intf == NULL) { + if (!ipmi_main_intf) { lprintf(LOG_ERR, "Error loading interface %s", intfname); goto out_free; } @@ -837,18 +837,18 @@ ipmi_main(int argc, char ** argv, log_init(progname, 0, verbose); /* run OEM setup if found */ - if (oemtype != NULL && + if (oemtype && ipmi_oem_setup(ipmi_main_intf, oemtype) < 0) { lprintf(LOG_ERR, "OEM setup for \"%s\" failed", oemtype); goto out_free; } /* set session variables */ - if (hostname != NULL) + if (hostname) ipmi_intf_session_set_hostname(ipmi_main_intf, hostname); - if (username != NULL) + if (username) ipmi_intf_session_set_username(ipmi_main_intf, username); - if (password != NULL) + if (password) ipmi_intf_session_set_password(ipmi_main_intf, password); ipmi_intf_session_set_kgkey(ipmi_main_intf, kgkey); if (port > 0) @@ -878,7 +878,7 @@ ipmi_main(int argc, char ** argv, ipmi_main_intf->ai_family = ai_family; /* Open the interface with the specified or default IPMB address */ ipmi_main_intf->my_addr = arg_addr ? arg_addr : IPMI_BMC_SLAVE_ADDR; - if (ipmi_main_intf->open != NULL) { + if (ipmi_main_intf->open) { if (ipmi_main_intf->open(ipmi_main_intf) < 0) { goto out_free; } @@ -973,11 +973,11 @@ ipmi_main(int argc, char ** argv, ipmi_main_intf->target_ipmb_addr); /* parse local SDR cache if given */ - if (sdrcache != NULL) { + if (sdrcache) { ipmi_sdr_list_cache_fromfile(ipmi_main_intf, sdrcache); } /* Parse SEL OEM file if given */ - if (seloem != NULL) { + if (seloem) { ipmi_sel_oem_init(seloem); } @@ -1014,37 +1014,37 @@ ipmi_main(int argc, char ** argv, ipmi_cleanup(ipmi_main_intf); /* call interface close function if available */ - if (ipmi_main_intf->opened > 0 && ipmi_main_intf->close != NULL) + if (ipmi_main_intf->opened && ipmi_main_intf->close) ipmi_main_intf->close(ipmi_main_intf); out_free: log_halt(); - if (intfname != NULL) { + if (intfname) { free(intfname); intfname = NULL; } - if (hostname != NULL) { + if (hostname) { free(hostname); hostname = NULL; } - if (username != NULL) { + if (username) { free(username); username = NULL; } - if (password != NULL) { + if (password) { free(password); password = NULL; } - if (oemtype != NULL) { + if (oemtype) { free(oemtype); oemtype = NULL; } - if (seloem != NULL) { + if (seloem) { free(seloem); seloem = NULL; } - if (sdrcache != NULL) { + if (sdrcache) { free(sdrcache); sdrcache = NULL; } diff --git a/lib/ipmi_mc.c b/lib/ipmi_mc.c index 0edfc55..ee75e95 100644 --- a/lib/ipmi_mc.c +++ b/lib/ipmi_mc.c @@ -84,9 +84,9 @@ ipmi_mc_reset(struct ipmi_intf * intf, int cmd) if (cmd == BMC_COLD_RESET) intf->abort = 1; - if (cmd == BMC_COLD_RESET && rsp == NULL) { + if (cmd == BMC_COLD_RESET && !rsp) { /* This is expected. See 20.2 Cold Reset Command, p.243, IPMIv2.0 rev1.0 */ - } else if (rsp == NULL) { + } else if (!rsp) { lprintf(LOG_ERR, "MC reset command failed."); return (-1); } else if (rsp->ccode) { @@ -190,7 +190,7 @@ printf_mc_usage(void) lprintf(LOG_NOTICE, " selftest"); lprintf(LOG_NOTICE, " getenables"); lprintf(LOG_NOTICE, " setenables ..."); - for (bf = mc_enables_bf; bf->name != NULL; bf++) { + for (bf = mc_enables_bf; bf->name; bf++) { lprintf(LOG_NOTICE, " %-20s %s", bf->name, bf->desc); } printf_sysinfo_usage(0); @@ -281,7 +281,7 @@ ipmi_mc_get_enables(struct ipmi_intf * intf) req.msg.cmd = BMC_GET_GLOBAL_ENABLES; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Global Enables command failed"); return -1; } @@ -291,7 +291,7 @@ ipmi_mc_get_enables(struct ipmi_intf * intf) return -1; } - for (bf = mc_enables_bf; bf->name != NULL; bf++) { + for (bf = mc_enables_bf; bf->name; bf++) { printf("%-40s : %sabled\n", bf->desc, rsp->data[0] & bf->mask ? "en" : "dis"); } @@ -331,7 +331,7 @@ ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv) req.msg.cmd = BMC_GET_GLOBAL_ENABLES; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Global Enables command failed"); return -1; } @@ -344,7 +344,7 @@ ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv) en = rsp->data[0]; for (i = 0; i < argc; i++) { - for (bf = mc_enables_bf; bf->name != NULL; bf++) { + for (bf = mc_enables_bf; bf->name; bf++) { int nl = strlen(bf->name); if (strncmp(argv[i], bf->name, nl) != 0) continue; @@ -373,7 +373,7 @@ ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set Global Enables command failed"); return -1; } @@ -423,7 +423,7 @@ ipmi_mc_get_deviceid(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Device ID command failed"); return -1; } @@ -455,7 +455,7 @@ ipmi_mc_get_deviceid(struct ipmi_intf * intf) product = OEM_PROD_STRING(devid->manufacturer_id, devid->product_id); - if (product!=NULL) { + if (product) { printf("Product Name : %s\n", product); } @@ -497,7 +497,7 @@ _ipmi_mc_get_guid(struct ipmi_intf *intf, struct ipmi_guid_t *guid) { struct ipmi_rs *rsp; struct ipmi_rq req; - if (guid == NULL) { + if (!guid) { return (-3); } @@ -507,7 +507,7 @@ _ipmi_mc_get_guid(struct ipmi_intf *intf, struct ipmi_guid_t *guid) req.msg.cmd = BMC_GET_GUID; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -734,7 +734,7 @@ ipmi_mc_get_watchdog(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Watchdog Timer command failed"); return -1; } @@ -934,7 +934,7 @@ ipmi_mc_set_watchdog(struct ipmi_intf * intf, int argc, char *argv[]) lprintf(LOG_INFO, " - timeout = %hu", conf.timeout); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set Watchdog Timer command failed"); goto out; } @@ -994,7 +994,7 @@ ipmi_mc_shutoff_watchdog(struct ipmi_intf * intf) msg_data[5] = 0x0b; /* countdown msb - 5 mins */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Watchdog Timer Shutoff command failed!"); return -1; } @@ -1029,7 +1029,7 @@ ipmi_mc_rst_watchdog(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Reset Watchdog Timer command failed!"); return -1; } @@ -1236,7 +1236,7 @@ ipmi_mc_getsysinfo(struct ipmi_intf * intf, int param, int block, int set, * u8 data0[14] */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) + if (!rsp) return (-1); if (!rsp->ccode) { @@ -1278,7 +1278,7 @@ ipmi_mc_setsysinfo(struct ipmi_intf * intf, int len, void *buffer) * u8 data1[16] */ rsp = intf->sendrecv(intf, &req); - if (rsp != NULL) { + if (rsp) { return rsp->ccode; } return -1; diff --git a/lib/ipmi_oem.c b/lib/ipmi_oem.c index 86fd803..004c72d 100644 --- a/lib/ipmi_oem.c +++ b/lib/ipmi_oem.c @@ -91,8 +91,8 @@ ipmi_oem_supermicro(struct ipmi_intf * intf) static int ipmi_oem_ibm(struct ipmi_intf * intf) { - char * filename; - if ((filename = getenv("IPMI_OEM_IBM_DATAFILE")) == NULL) { + char * filename = getenv("IPMI_OEM_IBM_DATAFILE"); + if (!filename) { lprintf(LOG_ERR, "Unable to read IPMI_OEM_IBM_DATAFILE from environment"); return -1; } @@ -114,7 +114,7 @@ ipmi_oem_print(void) { struct ipmi_oem_handle * oem; lprintf(LOG_NOTICE, "\nOEM Support:"); - for (oem=ipmi_oem_list; oem->name != NULL && oem->desc != NULL; oem++) { + for (oem=ipmi_oem_list; oem->name && oem->desc; oem++) { lprintf(LOG_NOTICE, "\t%-12s %s", oem->name, oem->desc); } lprintf(LOG_NOTICE, ""); @@ -134,26 +134,27 @@ ipmi_oem_setup(struct ipmi_intf * intf, char * oemtype) struct ipmi_oem_handle * oem; int rc = 0; - if (oemtype == NULL || - strncmp(oemtype, "help", 4) == 0 || - strncmp(oemtype, "list", 4) == 0) { + if (!oemtype + || strncmp(oemtype, "help", 4) == 0 + || strncmp(oemtype, "list", 4) == 0) + { ipmi_oem_print(); return -1; } - for (oem=ipmi_oem_list; oem->name != NULL; oem++) { + for (oem=ipmi_oem_list; oem->name; oem++) { if (strncmp(oemtype, oem->name, strlen(oem->name)) == 0) break; } - if (oem->name == NULL) + if (!oem->name) return -1; /* save pointer for later use */ intf->oem = oem; /* run optional setup function if it is defined */ - if (oem->setup != NULL) { + if (oem->setup) { lprintf(LOG_DEBUG, "Running OEM setup for \"%s\"", oem->desc); rc = oem->setup(intf); } @@ -172,7 +173,7 @@ ipmi_oem_setup(struct ipmi_intf * intf, char * oemtype) int ipmi_oem_active(struct ipmi_intf * intf, const char * oemtype) { - if (intf->oem == NULL) + if (!intf->oem) return 0; if (strncmp(intf->oem->name, oemtype, strlen(oemtype)) == 0) diff --git a/lib/ipmi_pef.c b/lib/ipmi_pef.c index 96bf1bd..fec6d5f 100644 --- a/lib/ipmi_pef.c +++ b/lib/ipmi_pef.c @@ -193,7 +193,7 @@ ipmi_pef_print_1xd(const char * text, uint32_t val) static int ipmi_pef_print_guid(uint8_t *guid) { - if (guid == NULL) { + if (!guid) { return (-1); } @@ -247,7 +247,7 @@ _ipmi_get_pef_capabilities(struct ipmi_intf *intf, { struct ipmi_rs *rsp; struct ipmi_rq req; - if (pcap == NULL) { + if (!pcap) { return (-3); } @@ -257,7 +257,7 @@ _ipmi_get_pef_capabilities(struct ipmi_intf *intf, req.msg.cmd = IPMI_CMD_GET_PEF_CAPABILITIES; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -287,7 +287,7 @@ _ipmi_get_pef_filter_entry(struct ipmi_intf *intf, uint8_t filter_id, uint8_t data[3]; uint8_t data_len = 3 * sizeof(uint8_t); int dest_size; - if (filter_entry == NULL) { + if (!filter_entry) { return (-3); } @@ -303,7 +303,7 @@ _ipmi_get_pef_filter_entry(struct ipmi_intf *intf, uint8_t filter_id, req.msg.data = (uint8_t *)&data; req.msg.data_len = data_len; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -331,7 +331,7 @@ _ipmi_get_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id, uint8_t data[3]; uint8_t data_len = 3 * sizeof(uint8_t); int dest_size; - if (filter_cfg == NULL) { + if (!filter_cfg) { return (-3); } @@ -347,7 +347,7 @@ _ipmi_get_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id, req.msg.data = (uint8_t *)&data; req.msg.data_len = data_len; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -375,7 +375,7 @@ _ipmi_get_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id, uint8_t data[3]; uint8_t data_len = 3 * sizeof(uint8_t); int dest_size; - if (policy_entry == NULL) { + if (!policy_entry) { return (-3); } @@ -391,7 +391,7 @@ _ipmi_get_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id, req.msg.data = (uint8_t *)&data; req.msg.data_len = data_len; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -416,7 +416,7 @@ _ipmi_get_pef_filter_table_size(struct ipmi_intf *intf, uint8_t *table_size) struct ipmi_rq req; struct pef_cfgparm_selector psel; - if (table_size == NULL) { + if (!table_size) { return (-3); } @@ -430,7 +430,7 @@ _ipmi_get_pef_filter_table_size(struct ipmi_intf *intf, uint8_t *table_size) req.msg.data = (uint8_t *)&psel; req.msg.data_len = sizeof(psel); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -455,7 +455,7 @@ _ipmi_get_pef_policy_table_size(struct ipmi_intf *intf, uint8_t *table_size) struct ipmi_rq req; struct pef_cfgparm_selector psel; - if (table_size == NULL) { + if (!table_size) { return (-3); } @@ -469,7 +469,7 @@ _ipmi_get_pef_policy_table_size(struct ipmi_intf *intf, uint8_t *table_size) req.msg.data = (uint8_t *)&psel; req.msg.data_len = sizeof(psel); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -494,7 +494,7 @@ _ipmi_get_pef_system_guid(struct ipmi_intf *intf, struct ipmi_rs *rsp; struct ipmi_rq req; struct pef_cfgparm_selector psel; - if (system_guid == NULL) { + if (!system_guid) { return (-3); } @@ -508,7 +508,7 @@ _ipmi_get_pef_system_guid(struct ipmi_intf *intf, req.msg.data_len = sizeof(psel); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -537,7 +537,7 @@ _ipmi_set_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id, struct ipmi_rq req; uint8_t data[3]; uint8_t data_len = 3 * sizeof(uint8_t); - if (filter_cfg == NULL) { + if (!filter_cfg) { return (-3); } @@ -553,7 +553,7 @@ _ipmi_set_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id, data[2] = filter_cfg->cfg; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -576,7 +576,7 @@ _ipmi_set_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id, struct ipmi_rs *rsp; struct ipmi_rq req; struct pef_cfgparm_set_policy_table_entry payload; - if (policy_entry == NULL) { + if (!policy_entry) { return (-3); } @@ -593,7 +593,7 @@ _ipmi_set_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id, sizeof(policy_entry->entry)); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; diff --git a/lib/ipmi_picmg.c b/lib/ipmi_picmg.c index a5a84e3..ef09de0 100644 --- a/lib/ipmi_picmg.c +++ b/lib/ipmi_picmg.c @@ -2351,7 +2351,7 @@ picmg_discover(struct ipmi_intf *intf) { lprintf(LOG_DEBUG, "Running Get PICMG Properties my_addr %#x, transit %#x, target %#x", intf->my_addr, intf->transit_addr, intf->target_addr); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_DEBUG,"No response from Get PICMG Properties"); } else if (rsp->ccode) { lprintf(LOG_DEBUG,"Error response %#x from Get PICMG Properties", diff --git a/lib/ipmi_quantaoem.c b/lib/ipmi_quantaoem.c index 5a7509b..0ddcefd 100644 --- a/lib/ipmi_quantaoem.c +++ b/lib/ipmi_quantaoem.c @@ -106,7 +106,7 @@ oem_qct_get_platform_id(struct ipmi_intf *intf) req.msg.data_len = sizeof(msg_data); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Platform ID command failed"); return 0; } @@ -138,7 +138,7 @@ oem_qct_get_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) } /* Allocate mem for the Description string */ desc = malloc(SIZE_OF_DESC); - if (desc == NULL) { + if (!desc) { lprintf(LOG_ERR, "ipmitool: malloc failure"); goto out; } @@ -154,7 +154,7 @@ oem_qct_get_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, " Error getting system info"); goto out; } else if (rsp->ccode) { diff --git a/lib/ipmi_raw.c b/lib/ipmi_raw.c index 5d6cf21..e6cbbfb 100644 --- a/lib/ipmi_raw.c +++ b/lib/ipmi_raw.c @@ -101,7 +101,7 @@ ipmi_master_write_read(struct ipmi_intf * intf, uint8_t bus, uint8_t addr, } rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "I2C Master Write-Read command failed"); return NULL; } @@ -171,7 +171,7 @@ ipmi_rawspd_main(struct ipmi_intf * intf, int argc, char ** argv) for (i = 0; i < RAW_SPD_SIZE; i+= msize) { rsp = ipmi_master_write_read(intf, i2cbus, i2caddr, (uint8_t *)&i, 1, msize ); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to perform I2C Master Write-Read"); return -1; } @@ -259,7 +259,7 @@ ipmi_rawi2c_main(struct ipmi_intf * intf, int argc, char ** argv) printbuf(wdata, wsize, "WRITE DATA"); rsp = ipmi_master_write_read(intf, bus, i2caddr, wdata, wsize, rsize); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to perform I2C Master Write-Read"); return -1; } @@ -379,7 +379,7 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to send RAW command " "(channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x)", intf->target_channel & 0x0f, req.msg.netfn, req.msg.lun, req.msg.cmd); @@ -417,7 +417,7 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv) */ int is_valid_param(const char *input_param, uint8_t *uchr_ptr, const char *label) { - if (input_param == NULL || label == NULL) { + if (!input_param || !label) { lprintf(LOG_ERROR, "ERROR: NULL pointer passed."); return (-1); } diff --git a/lib/ipmi_sdr.c b/lib/ipmi_sdr.c index aa6c672..2798b72 100644 --- a/lib/ipmi_sdr.c +++ b/lib/ipmi_sdr.c @@ -792,7 +792,7 @@ ipmi_sdr_get_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr) for (try = 0; try < 5; try++) { sdr_rq.reserve_id = itr->reservation; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SDR %04x command failed", itr->next); continue; @@ -875,7 +875,7 @@ ipmi_sdr_get_next_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr) return NULL; header = ipmi_sdr_get_header(intf, itr); - if (header == NULL) + if (!header) return NULL; itr->next = header->next; @@ -958,7 +958,7 @@ ipmi_sdr_print_sensor_event_status(struct ipmi_intf *intf, rsp = ipmi_sdr_get_sensor_event_status(intf, sensor_num, target, lun, channel); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_DEBUG, "Error reading event status for sensor #%02x", sensor_num); @@ -1172,7 +1172,7 @@ ipmi_sdr_print_sensor_event_enable(struct ipmi_intf *intf, rsp = ipmi_sdr_get_sensor_event_enable(intf, sensor_num, target, lun, channel); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_DEBUG, "Error reading event enable for sensor #%02x", sensor_num); @@ -1398,7 +1398,7 @@ ipmi_sdr_read_sensor_value(struct ipmi_intf *intf, { static struct sensor_reading sr; - if (sensor == NULL) + if (!sensor) return NULL; /* Initialize to reading valid value of zero */ @@ -1438,7 +1438,7 @@ ipmi_sdr_read_sensor_value(struct ipmi_intf *intf, sr.s_a_units = ""; /* no converted analog units units */ - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_DEBUG, "Error reading sensor %s (#%02x)", sr.s_id, sensor->keys.sensor_num); return &sr; @@ -1524,7 +1524,7 @@ ipmi_sdr_print_sensor_fc(struct ipmi_intf *intf, sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 2); - if (sr == NULL) + if (!sr) return -1; target = sensor->keys.owner_id; @@ -1977,7 +1977,7 @@ ipmi_sdr_print_discrete_state_mini(struct ipmi_intf *intf, printf("%s", header); for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type); - evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) { + evt; evt = ipmi_get_next_event_sensor_type(evt)) { if (evt->data != 0xFF) { continue; } @@ -2027,7 +2027,7 @@ ipmi_sdr_print_discrete_state(struct ipmi_intf *intf, const char *desc, return; for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type); - evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) { + evt; evt = ipmi_get_next_event_sensor_type(evt)) { if (evt->data != 0xFF) { continue; } @@ -2079,7 +2079,7 @@ ipmi_sdr_print_sensor_eventonly(struct ipmi_intf *intf, { char desc[17]; - if (sensor == NULL) + if (!sensor) return -1; memset(desc, 0, sizeof (desc)); @@ -2130,7 +2130,7 @@ ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf *intf, { char desc[17]; - if (mc == NULL) + if (!mc) return -1; memset(desc, 0, sizeof (desc)); @@ -2445,9 +2445,9 @@ ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem) { int rc = 0; - if (oem == NULL) + if (!oem) return -1; - if (oem->data_len == 0 || oem->data == NULL) + if (oem->data_len == 0 || !oem->data) return -1; if (verbose > 2) @@ -2661,15 +2661,15 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type) lprintf(LOG_DEBUG, "Querying SDR for sensor list"); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = ipmi_sdr_start(intf, 0); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return -1; } } - for (e = sdr_list_head; e != NULL; e = e->next) { + for (e = sdr_list_head; e; e = e->next) { if (type != e->type && type != 0xff && type != 0xfe) continue; if (type == 0xfe && @@ -2680,21 +2680,21 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type) rc = -1; } - while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) { uint8_t *rec; struct sdr_record_list *sdrr; rec = ipmi_sdr_get_record(intf, header, sdr_list_itr); - if (rec == NULL) { + if (!rec) { lprintf(LOG_ERR, "ipmitool: ipmi_sdr_get_record() failed"); rc = -1; continue; } sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); - if (rec != NULL) { + if (rec) { free(rec); rec = NULL; } @@ -2733,7 +2733,7 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type) default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -2752,7 +2752,7 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type) } /* add to global record liset */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -2791,7 +2791,7 @@ ipmi_sdr_get_reservation(struct ipmi_intf *intf, int use_builtin, rsp = intf->sendrecv(intf, &req); /* be slient for errors, they are handled by calling function */ - if (rsp == NULL) + if (!rsp) return -1; if (rsp->ccode) return -1; @@ -2819,7 +2819,7 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin) struct ipm_devid_rsp *devid; itr = malloc(sizeof (struct ipmi_sdr_iterator)); - if (itr == NULL) { + if (!itr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -2832,7 +2832,7 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Device ID command failed"); free(itr); itr = NULL; @@ -2874,7 +2874,7 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin) req.msg.cmd = GET_SDR_REPO_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error obtaining SDR info"); free(itr); itr = NULL; @@ -2972,7 +2972,7 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header, return NULL; data = malloc(len + 1); - if (data == NULL) { + if (!data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -3018,7 +3018,7 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header, sdr_rq.length, sdr_rq.offset); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { sdr_max_read_len = sdr_rq.length - 1; if (sdr_max_read_len > 0) { /* no response may happen if requests are bridged @@ -3097,11 +3097,11 @@ __sdr_list_add(struct sdr_record_list *head, struct sdr_record_list *entry) struct sdr_record_list *e; struct sdr_record_list *new; - if (head == NULL) + if (!head) return -1; new = malloc(sizeof (struct sdr_record_list)); - if (new == NULL) { + if (!new) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } @@ -3126,7 +3126,7 @@ static void __sdr_list_empty(struct sdr_record_list *head) { struct sdr_record_list *e, *f; - for (e = head; e != NULL; e = f) { + for (e = head; e; e = f) { f = e->next; free(e); e = NULL; @@ -3147,7 +3147,7 @@ ipmi_sdr_list_empty(struct ipmi_intf *intf) ipmi_sdr_end(intf, sdr_list_itr); - for (list = sdr_list_head; list != NULL; list = next) { + for (list = sdr_list_head; list; list = next) { switch (list->type) { case SDR_RECORD_TYPE_FULL_SENSOR: case SDR_RECORD_TYPE_COMPACT_SENSOR: @@ -3214,16 +3214,16 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num struct sdr_record_list *e; int found = 0; - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = ipmi_sdr_start(intf, 0); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return NULL; } } /* check what we've already read */ - for (e = sdr_list_head; e != NULL; e = e->next) { + for (e = sdr_list_head; e; e = e->next) { switch (e->type) { case SDR_RECORD_TYPE_FULL_SENSOR: case SDR_RECORD_TYPE_COMPACT_SENSOR: @@ -3242,12 +3242,12 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num } /* now keep looking */ - while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) { uint8_t *rec; struct sdr_record_list *sdrr; sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); break; } @@ -3256,8 +3256,8 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num sdrr->type = header->type; rec = ipmi_sdr_get_record(intf, header, sdr_list_itr); - if (rec == NULL) { - if (sdrr != NULL) { + if (!rec) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3301,7 +3301,7 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3309,7 +3309,7 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num } /* put in the global record list */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -3338,9 +3338,9 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type) struct sdr_get_rs *header; struct sdr_record_list *e; - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = ipmi_sdr_start(intf, 0); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return NULL; } @@ -3348,13 +3348,13 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type) /* check what we've already read */ head = malloc(sizeof (struct sdr_record_list)); - if (head == NULL) { + if (!head) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } memset(head, 0, sizeof (struct sdr_record_list)); - for (e = sdr_list_head; e != NULL; e = e->next) { + for (e = sdr_list_head; e; e = e->next) { switch (e->type) { case SDR_RECORD_TYPE_FULL_SENSOR: case SDR_RECORD_TYPE_COMPACT_SENSOR: @@ -3369,12 +3369,12 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type) } /* now keep looking */ - while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) { uint8_t *rec; struct sdr_record_list *sdrr; sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); break; } @@ -3383,8 +3383,8 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type) sdrr->type = header->type; rec = ipmi_sdr_get_record(intf, header, sdr_list_itr); - if (rec == NULL) { - if (sdrr != NULL) { + if (!rec) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3424,7 +3424,7 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type) default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3432,7 +3432,7 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type) } /* put in the global record list */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -3458,23 +3458,23 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity) struct sdr_record_list *e; struct sdr_record_list *head; - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = ipmi_sdr_start(intf, 0); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return NULL; } } head = malloc(sizeof (struct sdr_record_list)); - if (head == NULL) { + if (!head) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } memset(head, 0, sizeof (struct sdr_record_list)); /* check what we've already read */ - for (e = sdr_list_head; e != NULL; e = e->next) { + for (e = sdr_list_head; e; e = e->next) { switch (e->type) { case SDR_RECORD_TYPE_FULL_SENSOR: case SDR_RECORD_TYPE_COMPACT_SENSOR: @@ -3523,12 +3523,12 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity) } /* now keep looking */ - while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) { uint8_t *rec; struct sdr_record_list *sdrr; sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); break; } @@ -3537,8 +3537,8 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity) sdrr->type = header->type; rec = ipmi_sdr_get_record(intf, header, sdr_list_itr); - if (rec == NULL) { - if (sdrr != NULL) { + if (!rec) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3604,7 +3604,7 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity) default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3612,7 +3612,7 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity) } /* add to global record list */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -3638,33 +3638,33 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type) struct sdr_record_list *e; struct sdr_record_list *head; - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = ipmi_sdr_start(intf, 0); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return NULL; } } head = malloc(sizeof (struct sdr_record_list)); - if (head == NULL) { + if (!head) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } memset(head, 0, sizeof (struct sdr_record_list)); /* check what we've already read */ - for (e = sdr_list_head; e != NULL; e = e->next) + for (e = sdr_list_head; e; e = e->next) if (e->type == type) __sdr_list_add(head, e); /* now keep looking */ - while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) { uint8_t *rec; struct sdr_record_list *sdrr; sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); break; } @@ -3673,8 +3673,8 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type) sdrr->type = header->type; rec = ipmi_sdr_get_record(intf, header, sdr_list_itr); - if (rec == NULL) { - if (sdrr != NULL) { + if (!rec) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3710,7 +3710,7 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type) default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3721,7 +3721,7 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type) __sdr_list_add(head, sdrr); /* add to global record list */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -3748,21 +3748,21 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id) int found = 0; int idlen; - if (id == NULL) + if (!id) return NULL; idlen = strlen(id); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = ipmi_sdr_start(intf, 0); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return NULL; } } /* check what we've already read */ - for (e = sdr_list_head; e != NULL; e = e->next) { + for (e = sdr_list_head; e; e = e->next) { switch (e->type) { case SDR_RECORD_TYPE_FULL_SENSOR: if (!strncmp((const char *)e->record.full->id_string, @@ -3804,12 +3804,12 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id) } /* now keep looking */ - while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) { uint8_t *rec; struct sdr_record_list *sdrr; sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); break; } @@ -3818,8 +3818,8 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id) sdrr->type = header->type; rec = ipmi_sdr_get_record(intf, header, sdr_list_itr); - if (rec == NULL) { - if (sdrr != NULL) { + if (!rec) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3890,7 +3890,7 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id) default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -3898,7 +3898,7 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id) } /* add to global record liset */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -3934,13 +3934,13 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile) uint8_t *rec; int ret = 0, count = 0, bc = 0; - if (ifile == NULL) { + if (!ifile) { lprintf(LOG_ERR, "No SDR cache filename given"); return -1; } fp = ipmi_open_file_read(ifile); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Unable to open SDR cache %s for reading", ifile); return -1; @@ -3972,7 +3972,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile) } sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); ret = -1; break; @@ -3983,10 +3983,10 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile) sdrr->type = header.type; rec = malloc(header.length + 1); - if (rec == NULL) { + if (!rec) { lprintf(LOG_ERR, "ipmitool: malloc failure"); ret = -1; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -4000,11 +4000,11 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile) "record %04x read %d bytes, expected %d", header.id, bc, header.length); ret = -1; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } - if (rec != NULL) { + if (rec) { free(rec); rec = NULL; } @@ -4040,7 +4040,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile) default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -4048,7 +4048,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile) } /* add to global record liset */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -4061,9 +4061,9 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile) sdrr->id); } - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = malloc(sizeof (struct ipmi_sdr_iterator)); - if (sdr_list_itr != NULL) { + if (sdr_list_itr) { sdr_list_itr->reservation = 0; sdr_list_itr->total = count; sdr_list_itr->next = 0xffff; @@ -4086,20 +4086,20 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf) { struct sdr_get_rs *header; - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { sdr_list_itr = ipmi_sdr_start(intf, 0); - if (sdr_list_itr == NULL) { + if (!sdr_list_itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return -1; } } - while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) { uint8_t *rec; struct sdr_record_list *sdrr; sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); break; } @@ -4108,8 +4108,8 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf) sdrr->type = header->type; rec = ipmi_sdr_get_record(intf, header, sdr_list_itr); - if (rec == NULL) { - if (sdrr != NULL) { + if (!rec) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -4145,7 +4145,7 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf) default: free(rec); rec = NULL; - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } @@ -4153,7 +4153,7 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf) } /* add to global record liset */ - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -4191,7 +4191,7 @@ ipmi_sdr_get_info(struct ipmi_intf *intf, rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SDR Repository Info command failed"); return -1; } @@ -4351,7 +4351,7 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile) /* open connection to SDR */ itr = ipmi_sdr_start(intf, 0); - if (itr == NULL) { + if (!itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return -1; } @@ -4359,9 +4359,9 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile) printf("Dumping Sensor Data Repository to '%s'\n", ofile); /* generate list of records */ - while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, itr))) { sdrr = malloc(sizeof(struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } @@ -4376,16 +4376,16 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile) sdrr->length = header->length; sdrr->raw = ipmi_sdr_get_record(intf, header, itr); - if (sdrr->raw == NULL) { + if (!sdrr->raw) { lprintf(LOG_ERR, "ipmitool: cannot obtain SDR record %04x", header->id); - if (sdrr != NULL) { + if (sdrr) { free(sdrr); sdrr = NULL; } return -1; } - if (sdr_list_head == NULL) + if (!sdr_list_head) sdr_list_head = sdrr; else sdr_list_tail->next = sdrr; @@ -4397,10 +4397,10 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile) /* now write to file */ fp = ipmi_open_file_write(ofile); - if (fp == NULL) + if (!fp) return -1; - for (sdrr = sdr_list_head; sdrr != NULL; sdrr = sdrr->next) { + for (sdrr = sdr_list_head; sdrr; sdrr = sdrr->next) { int r; uint8_t h[5]; @@ -4455,7 +4455,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type) int x; uint8_t sensor_type = 0; - if (type == NULL || + if (!type || strncasecmp(type, "help", 4) == 0 || strncasecmp(type, "list", 4) == 0) { printf("Sensor Types:\n"); @@ -4499,7 +4499,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type) list = ipmi_sdr_find_sdr_bysensortype(intf, sensor_type); - for (entry = list; entry != NULL; entry = entry->next) { + for (entry = list; entry; entry = entry->next) { rc = ipmi_sdr_print_listentry(intf, entry); } @@ -4525,7 +4525,7 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr) unsigned instance = 0; int rc = 0; - if (entitystr == NULL || + if (!entitystr || strncasecmp(entitystr, "help", 4) == 0 || strncasecmp(entitystr, "list", 4) == 0) { print_valstr_2col(entity_id_vals, "Entity IDs", -1); @@ -4541,7 +4541,7 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr) int i, j=0; /* now try string input */ - for (i = 0; entity_id_vals[i].str != NULL; i++) { + for (i = 0; entity_id_vals[i].str; i++) { if (strncasecmp(entitystr, entity_id_vals[i].str, __maxlen(entitystr, entity_id_vals[i].str)) == 0) { entity.id = entity_id_vals[i].val; @@ -4564,7 +4564,7 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr) list = ipmi_sdr_find_sdr_byentity(intf, &entity); - for (entry = list; entry != NULL; entry = entry->next) { + for (entry = list; entry; entry = entry->next) { rc = ipmi_sdr_print_listentry(intf, entry); } @@ -4599,7 +4599,7 @@ ipmi_sdr_print_entry_byid(struct ipmi_intf *intf, int argc, char **argv) for (i = 0; i < argc; i++) { sdr = ipmi_sdr_find_sdr_byid(intf, argv[i]); - if (sdr == NULL) { + if (!sdr) { lprintf(LOG_ERR, "Unable to find sensor id '%s'", argv[i]); } else { diff --git a/lib/ipmi_sdradd.c b/lib/ipmi_sdradd.c index 9f7c758..ab42010 100644 --- a/lib/ipmi_sdradd.c +++ b/lib/ipmi_sdradd.c @@ -80,7 +80,7 @@ partial_send(struct ipmi_intf *intf, struct ipmi_rq *req, uint16_t *id) { struct ipmi_rs *rsp; rsp = intf->sendrecv(intf, req); - if (rsp == NULL) { + if (!rsp) { return -1; } @@ -115,7 +115,7 @@ ipmi_sdr_add_record(struct ipmi_intf *intf, struct sdr_record_list *sdrr) } sdr_rq = (struct sdr_add_rq *)malloc(sizeof(*sdr_rq) + sdr_max_write_len); - if (sdr_rq == NULL) { + if (!sdr_rq) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } @@ -202,7 +202,7 @@ ipmi_sdr_repo_clear(struct ipmi_intf *intf) for (try = 0; try < 5; try++) { rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to clear SDRR"); return -1; } @@ -248,11 +248,11 @@ sdrr_get_records(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr, queue->head = NULL; queue->tail = NULL; - while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, itr))) { struct sdr_record_list *sdrr; sdrr = malloc(sizeof (struct sdr_record_list)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } @@ -266,7 +266,7 @@ sdrr_get_records(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr, (void)ipmi_sdr_print_name_from_rawentry(intf, sdrr->id, sdrr->type,sdrr->raw); /* put in the record queue */ - if (queue->head == NULL) + if (!queue->head) queue->head = sdrr; else queue->tail->next = sdrr; @@ -300,7 +300,7 @@ sdr_copy_to_sdrr(struct ipmi_intf *intf, int use_builtin, /* write the SDRs to the destination SDR Repository */ intf->target_addr = to_addr; - for (sdrr = sdrr_queue.head; sdrr != NULL; sdrr = sdrr_next) { + for (sdrr = sdrr_queue.head; sdrr; sdrr = sdrr_next) { sdrr_next = sdrr->next; rc = ipmi_sdr_add_record(intf, sdrr); if(rc < 0){ @@ -433,7 +433,7 @@ int ipmi_parse_range_list(const char *rangeList, unsigned char * pHexList) do { - if(nextString != NULL) + if(nextString) { (*nextString)= 0; nextString ++; @@ -446,8 +446,7 @@ int ipmi_parse_range_list(const char *rangeList, unsigned char * pHexList) /* At this point, it is a single entry or a range */ rangeString = strstr( inProcessString, "-" ); - if(rangeString == NULL) - { + if (!rangeString) { unsigned char decValue = 0; /* Single entry */ @@ -597,7 +596,7 @@ ipmi_sdr_read_records(const char *filename, struct sdrr_queue *queue) lprintf(LOG_DEBUG, "binHdr[4] (length) = 0x%02x", binHdr[4]); sdrr = malloc(sizeof(*sdrr)); - if (sdrr == NULL) { + if (!sdrr) { lprintf(LOG_ERR, "ipmitool: malloc failure"); rc = -1; break; @@ -607,7 +606,8 @@ ipmi_sdr_read_records(const char *filename, struct sdrr_queue *queue) sdrr->type = binHdr[3]; sdrr->length = binHdr[4]; - if ((sdrr->raw = malloc(sdrr->length)) == NULL) { + sdrr->raw = malloc(sdrr->length); + if (!sdrr->raw) { lprintf(LOG_ERR, "ipmitool: malloc failure"); free(sdrr); sdrr = NULL; @@ -626,7 +626,7 @@ ipmi_sdr_read_records(const char *filename, struct sdrr_queue *queue) } /* put in the record queue */ - if (queue->head == NULL) + if (!queue->head) queue->head = sdrr; else queue->tail->next = sdrr; @@ -654,7 +654,7 @@ ipmi_sdr_add_from_file(struct ipmi_intf *intf, const char *ifile) } /* write the SDRs to the SDR Repository */ - for (sdrr = sdrr_queue.head; sdrr != NULL; sdrr = sdrr_next) { + for (sdrr = sdrr_queue.head; sdrr; sdrr = sdrr_next) { sdrr_next = sdrr->next; rc = ipmi_sdr_add_record(intf, sdrr); if(rc < 0){ diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c index 792b69c..a9ef233 100644 --- a/lib/ipmi_sel.c +++ b/lib/ipmi_sel.c @@ -122,13 +122,13 @@ int ipmi_sel_oem_init(const char * filename) int i, j, k, n, byte; char buf[15][150]; - if (filename == NULL) { + if (!filename) { lprintf(LOG_ERR, "No SEL OEM filename provided"); return -1; } fp = ipmi_open_file_read(filename); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Could not open %s file", filename); return -1; } @@ -314,7 +314,7 @@ ipmi_get_oem(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Device ID command failed"); return IPMI_OEM_UNKNOWN; } @@ -347,7 +347,7 @@ ipmi_sel_add_entry(struct ipmi_intf * intf, struct sel_event_record * rec) ipmi_sel_print_std_entry(intf, rec); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Add SEL Entry failed"); return -1; } @@ -372,15 +372,15 @@ ipmi_sel_add_entries_fromfile(struct ipmi_intf * intf, const char * filename) uint8_t rqdata[8]; struct sel_event_record sel_event; - if (filename == NULL) + if (!filename) return -1; fp = ipmi_open_file_read(filename); - if (fp == NULL) + if (!fp) return -1; while (feof(fp) == 0) { - if (fgets(buf, 1024, fp) == NULL) + if (!fgets(buf, 1024, fp)) continue; /* clip off optional comment tail indicated by # */ @@ -464,7 +464,7 @@ get_kontron_evt_desc(struct ipmi_intf *intf, struct sel_event_record * rec) /* Only standard records are defined so far */ if( rec->record_type < 0xC0 ){ const struct ipmi_event_sensor_types *st=NULL; - for ( st=oem_kontron_event_types ; st->desc != NULL; st++){ + for (st = oem_kontron_event_types; st->desc; st++){ if (st->code == rec->sel_type.standard_type.event_type ){ size_t len =strlen(st->desc); description = (char*)malloc( len + 1 ); @@ -505,7 +505,7 @@ get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) req.msg.data = msg_data; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { if (verbose) lprintf(LOG_ERR, "Error issuing OEM command"); return NULL; @@ -566,7 +566,7 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) } /* Allocate mem for the Description string */ desc = malloc(sizeof(char) * SIZE_OF_DESC); - if (desc == NULL) { + if (!desc) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -582,9 +582,9 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, " Error getting system info"); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } @@ -592,7 +592,7 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) } else if (rsp->ccode) { lprintf(LOG_ERR, " Error getting system info: %s", val2str(rsp->ccode, completion_code_vals)); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } @@ -601,7 +601,7 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) /* check the chipset type */ oem_id = ipmi_get_oem_id(intf); if (oem_id == 0) { - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } @@ -786,7 +786,7 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) if (NULL == rsp) { lprintf(LOG_ERR, " Error getting system info"); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } @@ -796,7 +796,7 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) { lprintf(LOG_ERR, " Error getting system info: %s", val2str(rsp->ccode, completion_code_vals)); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } @@ -1284,9 +1284,9 @@ ipmi_get_first_event_sensor_type(struct ipmi_intf *intf, code = event_type; } - for (evt = start; evt->desc != NULL || next != NULL; evt++) { + for (evt = start; evt->desc || next; evt++) { /* check if VITA sensor event types has finished */ - if (evt->desc == NULL) { + if (!evt->desc) { /* proceed with next table */ evt = next; next = NULL; @@ -1305,7 +1305,7 @@ ipmi_get_next_event_sensor_type(const struct ipmi_event_sensor_types *evt) { const struct ipmi_event_sensor_types *start = evt; - for (evt = start + 1; evt->desc != NULL; evt++) { + for (evt = start + 1; evt->desc; evt++) { if (evt->code == start->code) { return evt; } @@ -1323,7 +1323,7 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char char *sfx = NULL; /* This will be assigned if the Platform is DELL, additional info is appended to the current Description */ - if (desc == NULL) + if (!desc) return; *desc = NULL; @@ -1395,10 +1395,11 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char offset = rec->sel_type.standard_type.event_data[0] & 0xf; for (evt = ipmi_get_first_event_sensor_type(intf, - rec->sel_type.standard_type.sensor_type, - rec->sel_type.standard_type.event_type); - evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) { - if ((evt->offset == offset && evt->desc != NULL) && + rec->sel_type.standard_type.sensor_type, + rec->sel_type.standard_type.event_type); + evt; evt = ipmi_get_next_event_sensor_type(evt)) + { + if ((evt->offset == offset && evt->desc) && ((evt->data == ALL_OFFSETS_SPECIFIED) || ((rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK) && (evt->data == rec->sel_type.standard_type.event_data[1])))) @@ -1521,7 +1522,7 @@ ipmi_get_sensor_type(struct ipmi_intf *intf, uint8_t code) type = ipmi_get_generic_sensor_type(code); } - if (type == NULL) { + if (!type) { type = "Unknown"; } @@ -1545,7 +1546,7 @@ ipmi_sel_get_info(struct ipmi_intf * intf) req.msg.cmd = IPMI_CMD_GET_SEL_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Info command failed"); return -1; } else if (rsp->ccode) { @@ -1626,7 +1627,7 @@ ipmi_sel_get_info(struct ipmi_intf * intf) req.msg.cmd = IPMI_CMD_GET_SEL_ALLOC_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Allocation Info command failed"); return -1; @@ -1672,7 +1673,7 @@ ipmi_sel_get_std_entry(struct ipmi_intf * intf, uint16_t id, req.msg.data_len = 6; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Entry %x command failed", id); return 0; } @@ -1759,7 +1760,7 @@ ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt { char * description; - if (fp == NULL) + if (!fp) return; ipmi_get_event_desc(intf, evt, &description); @@ -1774,9 +1775,9 @@ ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt evt->sel_type.standard_type.event_data[2], ipmi_get_sensor_type(intf, evt->sel_type.standard_type.sensor_type), evt->sel_type.standard_type.sensor_num, - (description != NULL) ? description : "Unknown"); + description ? description : "Unknown"); - if (description != NULL) { + if (description) { free(description); description = NULL; } @@ -1891,7 +1892,7 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) } /* lookup SDR entry based on sensor number and type */ - if (sdr != NULL) { + if (sdr) { printf("%s ", ipmi_get_sensor_type(intf, evt->sel_type.standard_type.sensor_type)); switch (sdr->type) { @@ -1948,7 +1949,7 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) printf("Asserted"); } - if (sdr != NULL && evt->sel_type.standard_type.event_type == 1) { + if (sdr && evt->sel_type.standard_type.event_type == 1) { /* * Threshold Event */ @@ -2122,7 +2123,7 @@ ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_ evt->sel_type.standard_type.gen_id, evt->sel_type.standard_type.sensor_num, evt->sel_type.standard_type.sensor_type); - if (sdr == NULL) + if (!sdr) { ipmi_sel_print_std_entry_verbose(intf, evt); return; @@ -2279,7 +2280,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav req.msg.cmd = IPMI_CMD_GET_SEL_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Info command failed"); return -1; } @@ -2301,7 +2302,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav req.msg.cmd = IPMI_CMD_RESERVE_SEL; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Reserve SEL command failed"); return -1; } @@ -2318,7 +2319,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav req.msg.cmd = IPMI_CMD_GET_SEL_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Info command failed"); return -1; } @@ -2347,7 +2348,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav } } - if (savefile != NULL) { + if (savefile) { fp = ipmi_open_file_write(savefile); } @@ -2372,7 +2373,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav else ipmi_sel_print_std_entry(intf, &evt); - if (fp != NULL) { + if (fp) { if (binary) fwrite(&evt, 1, 16, fp); else @@ -2384,7 +2385,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav } } - if (fp != NULL) + if (fp) fclose(fp); return 0; @@ -2429,13 +2430,13 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana, * Supports a tweak for hotswap events that are already interpreted. */ fp = ipmi_open_file(readfile, 0); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Failed to open file '%s' for reading.", readfile); return (-1); } buffer = (char *)malloc((size_t)256); - if (buffer == NULL) { + if (!buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); fclose(fp); return (-1); @@ -2444,7 +2445,7 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana, /* Only allow complete lines to be parsed, * hardcoded maximum line length */ - if (fgets(buffer, 256, fp) == NULL) { + if (!fgets(buffer, 256, fp)) { status = (-1); break; } @@ -2698,7 +2699,7 @@ ipmi_sel_reserve(struct ipmi_intf * intf) req.msg.cmd = IPMI_CMD_RESERVE_SEL; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_WARN, "Unable to reserve SEL"); return 0; } @@ -2734,7 +2735,7 @@ ipmi_sel_get_time(struct ipmi_intf * intf) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL || rsp->ccode) { + if (!rsp || rsp->ccode) { lprintf(LOG_ERR, "Get SEL Time command failed: %s", rsp ? val2str(rsp->ccode, completion_code_vals) @@ -2838,7 +2839,7 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string) #endif rsp = intf->sendrecv(intf, &req); - if (rsp == NULL || rsp->ccode) { + if (!rsp || rsp->ccode) { lprintf(LOG_ERR, "Set SEL Time command failed: %s", rsp ? val2str(rsp->ccode, completion_code_vals) @@ -2879,7 +2880,7 @@ ipmi_sel_clear(struct ipmi_intf * intf) req.msg.data_len = 6; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to clear SEL"); return -1; } @@ -2933,7 +2934,7 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to delete entry %d", id); rc = -1; } @@ -3004,7 +3005,7 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv) evt.sel_type.standard_type.gen_id, evt.sel_type.standard_type.sensor_num, evt.sel_type.standard_type.sensor_type); - if (sdr == NULL) { + if (!sdr) { continue; } diff --git a/lib/ipmi_sensor.c b/lib/ipmi_sensor.c index 559b19d..461e013 100644 --- a/lib/ipmi_sensor.c +++ b/lib/ipmi_sensor.c @@ -62,7 +62,7 @@ ipmi_sensor_get_sensor_reading_factors( char id[17]; - if (intf == NULL || sensor == NULL) + if (!intf || !sensor) return -1; memset(id, 0, sizeof(id)); @@ -80,7 +80,7 @@ ipmi_sensor_get_sensor_reading_factors( rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error updating reading factor for sensor %s (#%02x)", id, sensor->cmn.keys.sensor_num); return -1; @@ -164,7 +164,7 @@ ipmi_sensor_print_fc_discrete(struct ipmi_intf *intf, sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 3); - if (sr == NULL) { + if (!sr) { return -1; } @@ -253,7 +253,7 @@ ipmi_sensor_print_fc_threshold(struct ipmi_intf *intf, sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 3); - if (sr == NULL) { + if (!sr) { return -1; } @@ -424,16 +424,16 @@ ipmi_sensor_list(struct ipmi_intf *intf) lprintf(LOG_DEBUG, "Querying SDR for sensor list"); itr = ipmi_sdr_start(intf, 0); - if (itr == NULL) { + if (!itr) { lprintf(LOG_ERR, "Unable to open SDR for reading"); return -1; } - while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) { + while ((header = ipmi_sdr_get_next_header(intf, itr))) { uint8_t *rec; rec = ipmi_sdr_get_record(intf, header, itr); - if (rec == NULL) { + if (!rec) { lprintf(LOG_DEBUG, "rec == NULL"); continue; } @@ -481,7 +481,7 @@ __ipmi_sensor_set_threshold(struct ipmi_intf *intf, rsp = ipmi_sensor_set_sensor_thresholds(intf, num, mask, setting, target, lun, channel); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error setting threshold"); return -1; } @@ -612,7 +612,7 @@ ipmi_sensor_set_threshold(struct ipmi_intf *intf, int argc, char **argv) /* lookup by sensor name */ sdr = ipmi_sdr_find_sdr_byid(intf, id); - if (sdr == NULL) { + if (!sdr) { lprintf(LOG_ERR, "Sensor data record not found!"); return -1; } @@ -818,7 +818,7 @@ ipmi_sensor_get_reading(struct ipmi_intf *intf, int argc, char **argv) for (i = 0; i < argc; i++) { sdr = ipmi_sdr_find_sdr_byid(intf, argv[i]); - if (sdr == NULL) { + if (!sdr) { lprintf(LOG_ERR, "Sensor \"%s\" not found!", argv[i]); rc = -1; @@ -833,7 +833,7 @@ ipmi_sensor_get_reading(struct ipmi_intf *intf, int argc, char **argv) struct sdr_record_common_sensor *sensor = sdr->record.common; sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr->type, 3); - if (sr == NULL) { + if (!sr) { rc = -1; continue; } @@ -882,7 +882,7 @@ ipmi_sensor_get(struct ipmi_intf *intf, int argc, char **argv) /* lookup by sensor name */ for (i = 0; i < argc; i++) { sdr = ipmi_sdr_find_sdr_byid(intf, argv[i]); - if (sdr == NULL) { + if (!sdr) { lprintf(LOG_ERR, "Sensor data record \"%s\" not found!", argv[i]); rc = -1; diff --git a/lib/ipmi_session.c b/lib/ipmi_session.c index 5e6f247..ecf4afc 100644 --- a/lib/ipmi_session.c +++ b/lib/ipmi_session.c @@ -288,7 +288,7 @@ ipmi_get_session_info(struct ipmi_intf * intf, } rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) + if (!rsp) { lprintf(LOG_ERR, "Get Session Info command failed"); retval = -1; @@ -322,7 +322,7 @@ ipmi_get_session_info(struct ipmi_intf * intf, rqdata[0] = i++; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) + if (!rsp) { lprintf(LOG_ERR, "Get Session Info command failed"); retval = -1; diff --git a/lib/ipmi_sol.c b/lib/ipmi_sol.c index f71d85a..08a9368 100644 --- a/lib/ipmi_sol.c +++ b/lib/ipmi_sol.c @@ -125,7 +125,7 @@ ipmi_sol_payload_access(struct ipmi_intf * intf, uint8_t channel, /* payload 1 is SOL */ data[2] = 0x02; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error %sabling SOL payload for user %d on channel %d", enable ? "en" : "dis", userid, channel); rc = (-1); @@ -159,7 +159,7 @@ ipmi_sol_payload_access_status(struct ipmi_intf * intf, data[1] = userid & 0x3f; /* user id */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error. No valid response received."); return -1; } @@ -214,7 +214,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -252,7 +252,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -290,7 +290,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -330,7 +330,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -369,7 +369,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -408,7 +408,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -446,7 +446,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -484,7 +484,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -523,7 +523,7 @@ ipmi_get_sol_info( data[3] = 0x00; /* block selector */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'", val2str(data[1], sol_parameter_vals)); return (-1); @@ -541,7 +541,7 @@ ipmi_get_sol_info( } break; case 0x80: - if( intf->session != NULL ) { + if (intf->session) { lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported - defaulting to %d", val2str(data[1], sol_parameter_vals), intf->ssn_params.port); params->payload_port = intf->ssn_params.port; @@ -1068,7 +1068,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf, /* The command proper */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Error setting SOL parameter '%s'", param); return -1; } @@ -1486,7 +1486,7 @@ ipmi_sol_keepalive_using_sol(struct ipmi_intf * intf) if (end.tv_sec - _start_keepalive.tv_sec > SOL_KEEPALIVE_TIMEOUT) { memset(&v2_payload, 0, sizeof(v2_payload)); v2_payload.payload.sol_packet.character_count = 0; - if (intf->send_sol(intf, &v2_payload) == NULL) + if (!intf->send_sol(intf, &v2_payload)) return -1; /* good return, reset start time */ gettimeofday(&_start_keepalive, 0); @@ -1537,7 +1537,7 @@ ipmi_sol_red_pill(struct ipmi_intf * intf, int instance) buffer_size -= 4; buffer = (char*)malloc(buffer_size); - if (buffer == NULL) { + if (!buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } diff --git a/lib/ipmi_sunoem.c b/lib/ipmi_sunoem.c index 0e70e56..364e1f8 100644 --- a/lib/ipmi_sunoem.c +++ b/lib/ipmi_sunoem.c @@ -196,7 +196,7 @@ static void __sdr_list_empty(struct sdr_record_list * head) { struct sdr_record_list * e, *f; - for (e = head; e != NULL; e = f) { + for (e = head; e; e = f) { f = e->next; free(e); } @@ -253,7 +253,7 @@ sunoem_led_get(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev, uint8_t rqdata[7]; int rqdata_len; - if (dev == NULL) { + if (!dev) { *loc_rsp = NULL; return (SUNOEM_EC_INVALID_ARG); } @@ -282,7 +282,7 @@ sunoem_led_get(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev, * Just return NULL if there was * an error. */ - if (rsp == NULL) { + if (!rsp) { *loc_rsp = NULL; return (SUNOEM_EC_BMC_NOT_RESPONDING); } else if (rsp->ccode) { @@ -303,7 +303,7 @@ sunoem_led_set(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev, uint8_t rqdata[9]; int rqdata_len; - if (dev == NULL) + if (!dev) return NULL; rqdata[0] = dev->dev_slave_addr; @@ -329,7 +329,7 @@ sunoem_led_set(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev, req.msg.data_len = rqdata_len; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM Set LED command failed."); return NULL; } else if (rsp->ccode) { @@ -360,11 +360,11 @@ sunoem_led_get_byentity(struct ipmi_intf * intf, uint8_t entity_id, elist = ipmi_sdr_find_sdr_byentity(intf, &entity); - if (elist == NULL) + if (!elist) ret_get = -1; /* for each generic sensor get its led state */ - for (e = elist; e != NULL; e = e->next) { + for (e = elist; e; e = e->next) { if (e->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) continue; @@ -403,11 +403,11 @@ sunoem_led_set_byentity(struct ipmi_intf * intf, uint8_t entity_id, elist = ipmi_sdr_find_sdr_byentity(intf, &entity); - if (elist == NULL) + if (!elist) ret_set = -1; /* for each generic sensor set its led state */ - for (e = elist; e != NULL; e = e->next) { + for (e = elist; e; e = e->next) { if (e->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) continue; @@ -416,7 +416,7 @@ sunoem_led_set_byentity(struct ipmi_intf * intf, uint8_t entity_id, if (rsp && rsp->data_len == 0) { led_print((const char *) e->record.genloc->id_string, PRINT_NORMAL, ledmode); - } else if (rsp == NULL) { + } else if (!rsp) { ret_set = -1; } } @@ -476,10 +476,10 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv) alist = ipmi_sdr_find_sdr_bytype(intf, SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR); - if (alist == NULL) + if (!alist) return (-1); - for (a = alist; a != NULL; a = a->next) { + for (a = alist; a; a = a->next) { if (a->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) continue; if (a->record.genloc->entity.logical) @@ -510,7 +510,7 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv) /* look up generic device locator record in SDR */ sdr = ipmi_sdr_find_sdr_byid(intf, argv[0]); - if (sdr == NULL) { + if (!sdr) { lprintf(LOG_ERR, "No Sensor Data Record found for %s", argv[0]); return (-1); } @@ -555,14 +555,14 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv) /* get entity assoc records */ alist = ipmi_sdr_find_sdr_bytype(intf, SDR_RECORD_TYPE_ENTITY_ASSOC); - if (alist == NULL) + if (!alist) return (-1); - for (a = alist; a != NULL; a = a->next) { + for (a = alist; a; a = a->next) { if (a->type != SDR_RECORD_TYPE_ENTITY_ASSOC) continue; assoc = a->record.entassoc; - if (assoc == NULL) + if (!assoc) continue; /* check that the entity id/instance matches our generic record */ @@ -683,10 +683,10 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv) alist = ipmi_sdr_find_sdr_bytype(intf, SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR); - if (alist == NULL) + if (!alist) return (-1); - for (a = alist; a != NULL; a = a->next) { + for (a = alist; a; a = a->next) { if (a->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) continue; if (a->record.genloc->entity.logical) @@ -709,7 +709,7 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv) /* look up generic device locator records in SDR */ sdr = ipmi_sdr_find_sdr_byid(intf, argv[0]); - if (sdr == NULL) { + if (!sdr) { lprintf(LOG_ERR, "No Sensor Data Record found for %s", argv[0]); return (-1); } @@ -741,14 +741,14 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv) /* get entity assoc records */ alist = ipmi_sdr_find_sdr_bytype(intf, SDR_RECORD_TYPE_ENTITY_ASSOC); - if (alist == NULL) + if (!alist) return (-1); - for (a = alist; a != NULL; a = a->next) { + for (a = alist; a; a = a->next) { if (a->type != SDR_RECORD_TYPE_ENTITY_ASSOC) continue; assoc = a->record.entassoc; - if (assoc == NULL) + if (!assoc) continue; /* check that the entity id/instance matches our generic record */ @@ -812,7 +812,7 @@ ipmi_sunoem_sshkey_del(struct ipmi_intf * intf, uint8_t uid) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to delete ssh key for UID %d", uid); return (-1); } else if (rsp->ccode) { @@ -838,13 +838,13 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile) int32_t r = 0; int32_t size = 0; - if (ifile == NULL) { + if (!ifile) { lprintf(LOG_ERR, "Invalid or misisng input filename."); return (-1); } fp = ipmi_open_file_read(ifile); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Unable to open file '%s' for reading.", ifile); return (-1); } @@ -856,7 +856,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile) if (fseek(fp, 0, SEEK_END) == (-1)) { lprintf(LOG_ERR, "Failed to seek in file '%s'.", ifile); - if (fp != NULL) + if (fp) fclose(fp); return (-1); @@ -865,13 +865,13 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile) size = (int32_t) ftell(fp); if (size < 0) { lprintf(LOG_ERR, "Failed to seek in file '%s'.", ifile); - if (fp != NULL) + if (fp) fclose(fp); return (-1); } else if (size == 0) { lprintf(LOG_ERR, "File '%s' is empty.", ifile); - if (fp != NULL) + if (fp) fclose(fp); return (-1); @@ -879,7 +879,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile) if (fseek(fp, 0, SEEK_SET) == (-1)) { lprintf(LOG_ERR, "Failed to seek in file '%s'.", ifile); - if (fp != NULL) + if (fp) fclose(fp); return (-1); @@ -899,7 +899,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile) printf("failed\n"); lprintf(LOG_ERR, "Unable to read %ld bytes from file '%s'.", i_size, ifile); - if (fp != NULL) + if (fp) fclose(fp); return (-1); @@ -916,7 +916,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile) printf("failed\n"); lprintf(LOG_ERR, "Unable to pack byte %ld from file '%s'.", r, ifile); - if (fp != NULL) + if (fp) fclose(fp); return (-1); @@ -929,19 +929,19 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile) req.msg.data_len = i_size + 3; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { printf("failed\n"); lprintf(LOG_ERR, "Unable to set ssh key for UID %d.", uid); - if (fp != NULL) + if (fp) fclose(fp); return (-1); - } /* if (rsp == NULL) */ + } if (rsp->ccode) { printf("failed\n"); lprintf(LOG_ERR, "Unable to set ssh key for UID %d, %s.", uid, val2str(rsp->ccode, completion_code_vals)); - if (fp != NULL) + if (fp) fclose(fp); return (-1); @@ -1090,7 +1090,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[]) while (1) { cli_req.version = SunOemCliActingVersion; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM cli command failed"); return (-1); } @@ -1253,7 +1253,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[]) req.msg.data_len = SUNOEM_CLI_HEADER + count; for (retries = 0; retries <= SUNOEM_CLI_MAX_RETRY; retries++) { rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Communication error."); error = 1; goto cleanup; @@ -1380,7 +1380,7 @@ ipmi_sunoem_echo(struct ipmi_intf * intf, int argc, char *argv[]) gettimeofday(&end_time, NULL); resp_time = ((end_time.tv_sec - start_time.tv_sec) * 1000) + ((end_time.tv_usec - start_time.tv_usec) / 1000); - if ((rsp == NULL) || rsp->ccode) { + if (!rsp || rsp->ccode) { lprintf(LOG_ERR, "Sun OEM echo command failed. Seq # %d", echo_req.seq_num); rc = (-2); @@ -1500,7 +1500,7 @@ ipmi_sunoem_getversion(struct ipmi_intf * intf, req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM Get SP Version Failed."); return (-1); } @@ -1650,7 +1650,7 @@ ipmi_sunoem_nacname(struct ipmi_intf * intf, int argc, char *argv[]) req.msg.data_len = sizeof(sunoem_nacname_t); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM nacname command failed."); return (-1); } @@ -1820,7 +1820,7 @@ ipmi_sunoem_getval(struct ipmi_intf * intf, int argc, char *argv[]) req.msg.data_len = sizeof(sunoem_getval_t); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM getval1 command failed."); return (-1); } @@ -1842,7 +1842,7 @@ ipmi_sunoem_getval(struct ipmi_intf * intf, int argc, char *argv[]) req.msg.data_len = sizeof(sunoem_getval_t); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM getval2 command failed."); return (-1); } @@ -1910,7 +1910,7 @@ send_luapi_prop_name(struct ipmi_intf * intf, int len, char *prop_name, req.msg.data_len = sizeof(sunoem_setval_t); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM setval prop name: response is NULL"); return (-1); } @@ -1983,7 +1983,7 @@ send_luapi_prop_value(struct ipmi_intf * intf, int len, char *prop_value, req.msg.data_len = sizeof(sunoem_setval_t); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM setval prop value: response is NULL"); return (-1); } @@ -2076,7 +2076,7 @@ ipmi_sunoem_setval(struct ipmi_intf * intf, int argc, char *argv[]) req.msg.data_len = sizeof(sunoem_setval_t); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM setval command failed."); return (-1); } @@ -2166,7 +2166,7 @@ ipmi_sunoem_getfile(struct ipmi_intf * intf, int argc, char *argv[]) /* Create the destination file */ fp = ipmi_open_file_write(argv[1]); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Unable to open file: %s", argv[1]); return (-1); } @@ -2187,7 +2187,7 @@ ipmi_sunoem_getfile(struct ipmi_intf * intf, int argc, char *argv[]) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM getfile command failed."); fclose(fp); return (-1); @@ -2300,7 +2300,7 @@ ipmi_sunoem_getbehavior(struct ipmi_intf * intf, int argc, char *argv[]) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Sun OEM getbehavior command failed."); return (-1); } diff --git a/lib/ipmi_tsol.c b/lib/ipmi_tsol.c index a5cb222..918cbfa 100644 --- a/lib/ipmi_tsol.c +++ b/lib/ipmi_tsol.c @@ -103,7 +103,7 @@ ipmi_tsol_command(struct ipmi_intf *intf, char *recvip, int port, data[5] = (port & 0xff); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to perform TSOL command"); return (-1); } @@ -148,7 +148,7 @@ ipmi_tsol_send_keystroke(struct ipmi_intf *intf, char *buff, int length) rsp = intf->sendrecv(intf, &req); if (verbose) { - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to send keystroke"); return -1; } @@ -429,7 +429,7 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv) if (result <= 0) { struct hostent *host = gethostbyname((const char *)intf->ssn_params.hostname); - if (host == NULL ) { + if (!host ) { lprintf(LOG_ERR, "Address lookup for %s failed", intf->ssn_params.hostname); return -1; @@ -459,7 +459,7 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv) /* * retrieve local IP address if not supplied on command line */ - if (recvip == NULL) { + if (!recvip) { /* must connect first */ result = intf->open(intf); if (result < 0) { @@ -475,7 +475,7 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv) } recvip = inet_ntoa(myaddr.sin_addr); - if (recvip == NULL) { + if (!recvip) { lprintf(LOG_ERR, "Unable to find local IP address"); close(fd_socket); return -1; diff --git a/lib/ipmi_user.c b/lib/ipmi_user.c index afa7044..3c70e8f 100644 --- a/lib/ipmi_user.c +++ b/lib/ipmi_user.c @@ -68,7 +68,7 @@ _ipmi_get_user_access(struct ipmi_intf *intf, struct ipmi_rq req = {0}; struct ipmi_rs *rsp; uint8_t data[2]; - if (user_access_rsp == NULL) { + if (!user_access_rsp) { return (-3); } data[0] = user_access_rsp->channel & 0x0F; @@ -78,7 +78,7 @@ _ipmi_get_user_access(struct ipmi_intf *intf, req.msg.data = data; req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -110,7 +110,7 @@ _ipmi_get_user_name(struct ipmi_intf *intf, struct user_name_t *user_name_ptr) struct ipmi_rq req = {0}; struct ipmi_rs *rsp; uint8_t data[1]; - if (user_name_ptr == NULL) { + if (!user_name_ptr) { return (-3); } data[0] = IPMI_UID(user_name_ptr->user_id); @@ -119,7 +119,7 @@ _ipmi_get_user_name(struct ipmi_intf *intf, struct user_name_t *user_name_ptr) req.msg.data = data; req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else if (rsp->ccode) { return rsp->ccode; @@ -147,7 +147,7 @@ _ipmi_set_user_access(struct ipmi_intf *intf, uint8_t data[4]; struct ipmi_rq req = {0}; struct ipmi_rs *rsp; - if (user_access_req == NULL) { + if (!user_access_req) { return (-3); } data[0] = change_priv_limit_only ? 0x00 : 0x80; @@ -169,7 +169,7 @@ _ipmi_set_user_access(struct ipmi_intf *intf, req.msg.data = data; req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { return (-1); } else { return rsp->ccode; @@ -196,14 +196,14 @@ _ipmi_set_user_password(struct ipmi_intf *intf, uint8_t user_id, uint8_t *data; uint8_t data_len = (is_twenty_byte) ? 22 : 18; data = malloc(sizeof(uint8_t) * data_len); - if (data == NULL) { + if (!data) { return (-4); } memset(data, 0, data_len); data[0] = (is_twenty_byte) ? 0x80 : 0x00; data[0] |= IPMI_UID(user_id); data[1] = 0x03 & operation; - if (password != NULL) { + if (password) { size_t copy_len = strlen(password); if (copy_len > (data_len - 2)) { copy_len = data_len - 2; @@ -220,7 +220,7 @@ _ipmi_set_user_password(struct ipmi_intf *intf, uint8_t user_id, rsp = intf->sendrecv(intf, &req); free(data); data = NULL; - if (rsp == NULL) { + if (!rsp) { return (-1); } return rsp->ccode; @@ -375,7 +375,7 @@ ipmi_user_set_username( rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set User Name command failed (user %d, name %s)", user_id, name); return -1; @@ -551,7 +551,7 @@ ipmi_user_test(struct ipmi_intf *intf, int argc, char **argv) if (argc == 3) { /* We need to prompt for a password */ password = ask_password(user_id); - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return (-1); } @@ -641,12 +641,12 @@ ipmi_user_password(struct ipmi_intf *intf, int argc, char **argv) /* We need to prompt for a password */ char *tmp; password = ask_password(user_id); - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return (-1); } tmp = ask_password(user_id); - if (tmp == NULL) { + if (!tmp) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return (-1); } @@ -668,7 +668,7 @@ ipmi_user_password(struct ipmi_intf *intf, int argc, char **argv) } } - if (password == NULL) { + if (!password) { lprintf(LOG_ERR, "Unable to parse password argument."); return (-1); } else if (strlen(password) > 20) { diff --git a/lib/ipmi_vita.c b/lib/ipmi_vita.c index 7154e75..aaa2a56 100644 --- a/lib/ipmi_vita.c +++ b/lib/ipmi_vita.c @@ -190,7 +190,7 @@ vita_discover(struct ipmi_intf *intf) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received"); } else if (rsp->ccode == 0xC1) { lprintf(LOG_INFO, "Invalid completion code received: %s", @@ -240,7 +240,7 @@ ipmi_vita_ipmb_address(struct ipmi_intf *intf) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received"); } else if (rsp->ccode) { lprintf(LOG_ERR, "Invalid completion code received: %s", @@ -284,7 +284,7 @@ ipmi_vita_getaddr(struct ipmi_intf *intf, int argc, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received"); return -1; } else if (rsp->ccode) { @@ -332,7 +332,7 @@ ipmi_vita_get_vso_capabilities(struct ipmi_intf *intf) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -402,7 +402,7 @@ ipmi_vita_set_fru_activation(struct ipmi_intf *intf, rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -444,7 +444,7 @@ ipmi_vita_get_fru_state_policy_bits(struct ipmi_intf *intf, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -499,7 +499,7 @@ ipmi_vita_set_fru_state_policy_bits(struct ipmi_intf *intf, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -540,7 +540,7 @@ ipmi_vita_get_led_properties(struct ipmi_intf *intf, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -585,7 +585,7 @@ ipmi_vita_get_led_color_capabilities(struct ipmi_intf *intf, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -649,7 +649,7 @@ ipmi_vita_get_led_state(struct ipmi_intf *intf, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -749,7 +749,7 @@ ipmi_vita_set_led_state(struct ipmi_intf *intf, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { @@ -796,7 +796,7 @@ ipmi_vita_fru_control(struct ipmi_intf *intf, char **argv) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "No valid response received."); return -1; } else if (rsp->ccode) { diff --git a/lib/log.c b/lib/log.c index 50352cb..1226b8d 100644 --- a/lib/log.c +++ b/lib/log.c @@ -108,12 +108,12 @@ void log_init(const char * name, int isdaemon, int verbose) if (!logpriv) return; - if (name != NULL) + if (name) logpriv->name = strdup(name); else logpriv->name = strdup(LOG_NAME_DEFAULT); - if (logpriv->name == NULL) + if (!logpriv->name) fprintf(stderr, "ipmitool: malloc failure\n"); logpriv->daemon = isdaemon; diff --git a/src/ipmievd.c b/src/ipmievd.c index 5da576d..fefeb4a 100644 --- a/src/ipmievd.c +++ b/src/ipmievd.c @@ -183,14 +183,15 @@ ipmi_event_intf_load(char * name) struct ipmi_event_intf ** intf; struct ipmi_event_intf * i; - if (name == NULL) { + if (!name) { i = ipmi_event_intf_table[0]; return i; } for (intf = ipmi_event_intf_table; - ((intf != NULL) && (*intf != NULL)); - intf++) { + intf && *intf; + intf++) + { i = *intf; if (strncmp(name, i->name, strlen(name)) == 0) { return i; @@ -224,7 +225,7 @@ log_event(struct ipmi_event_intf * eintf, struct sel_event_record * evt) float trigger_reading = 0.0; float threshold_reading = 0.0; - if (evt == NULL) + if (!evt) return; if (evt->record_type == 0xf0) { @@ -245,7 +246,7 @@ log_event(struct ipmi_event_intf * eintf, struct sel_event_record * evt) sdr = ipmi_sdr_find_sdr_bynumtype(intf, evt->sel_type.standard_type.gen_id, evt->sel_type.standard_type.sensor_num, evt->sel_type.standard_type.sensor_type); - if (sdr == NULL) { + if (!sdr) { /* could not find matching SDR record */ if (desc) { lprintf(LOG_NOTICE, "%s%s sensor - %s", @@ -362,7 +363,7 @@ openipmi_enable_event_msg_buffer(struct ipmi_intf * intf) req.msg.cmd = 0x2f; /* Get BMC Global Enables */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get BMC Global Enables command failed"); return -1; } @@ -378,7 +379,7 @@ openipmi_enable_event_msg_buffer(struct ipmi_intf * intf) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set BMC Global Enables command failed"); return -1; } @@ -507,7 +508,7 @@ selwatch_get_data(struct ipmi_intf * intf, struct sel_data *data) req.msg.cmd = IPMI_CMD_GET_SEL_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Info command failed"); return 0; } @@ -764,7 +765,7 @@ ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv) umask(022); fp = ipmi_open_file_write(pidfile); - if (fp == NULL) { + if (!fp) { /* Failed to get fp on PID file -> exit. */ log_halt(); log_init("ipmievd", daemon, verbose); @@ -795,7 +796,7 @@ ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv) /* call event handler setup routine */ - if (eintf->setup != NULL) { + if (eintf->setup) { rc = eintf->setup(eintf); if (rc < 0) { lprintf(LOG_ERR, "Error setting up Event Interface %s", eintf->name); @@ -806,7 +807,7 @@ ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv) lprintf(LOG_NOTICE, "Waiting for events..."); /* now launch event wait loop */ - if (eintf->wait != NULL) { + if (eintf->wait) { rc = eintf->wait(eintf); if (rc < 0) { lprintf(LOG_ERR, "Error waiting for events!"); @@ -823,14 +824,14 @@ ipmievd_sel_main(struct ipmi_intf * intf, int argc, char ** argv) struct ipmi_event_intf * eintf; eintf = ipmi_event_intf_load("sel"); - if (eintf == NULL) { + if (!eintf) { lprintf(LOG_ERR, "Unable to load event interface"); return -1; } eintf->intf = intf; - if (intf->session != NULL) { + if (intf->session) { snprintf(eintf->prefix, strlen((const char *)intf->ssn_params.hostname) + 3, "%s: ", intf->ssn_params.hostname); @@ -851,7 +852,7 @@ ipmievd_open_main(struct ipmi_intf * intf, int argc, char ** argv) } eintf = ipmi_event_intf_load("open"); - if (eintf == NULL) { + if (!eintf) { lprintf(LOG_ERR, "Unable to load event interface"); return -1; } diff --git a/src/ipmishell.c b/src/ipmishell.c index 6cfcbe8..eea5466 100644 --- a/src/ipmishell.c +++ b/src/ipmishell.c @@ -78,9 +78,9 @@ static int rl_event_keepalive(void) { static int internal_timer = 0; - if (shell_intf == NULL) + if (!shell_intf) return -1; - if (shell_intf->keepalive == NULL) + if (!shell_intf->keepalive) return 0; #if defined (RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0402 if (internal_timer++ < RL_TIMEOUT) @@ -119,7 +119,7 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) #endif } - while ((pbuf = (char *)readline(RL_PROMPT)) != NULL) { + while ((pbuf = (char *)readline(RL_PROMPT))) { if (strlen(pbuf) == 0) { free(pbuf); pbuf = NULL; @@ -168,8 +168,9 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) ap = __argv; for (*ap = strtok(pbuf, " \t"); - *ap != NULL; - *ap = strtok(NULL, " \t")) { + *ap; + *ap = strtok(NULL, " \t")) + { __argc++; ptr = *ap; @@ -296,7 +297,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) if (strncmp(argv[0], "host", 4) == 0 || strncmp(argv[0], "hostname", 8) == 0) { ipmi_intf_session_set_hostname(intf, argv[1]); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session hostname."); return (-1); } @@ -306,7 +307,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) else if (strncmp(argv[0], "user", 4) == 0 || strncmp(argv[0], "username", 8) == 0) { ipmi_intf_session_set_username(intf, argv[1]); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session username."); return (-1); } @@ -316,7 +317,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) else if (strncmp(argv[0], "pass", 4) == 0 || strncmp(argv[0], "password", 8) == 0) { ipmi_intf_session_set_password(intf, argv[1]); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session password."); return (-1); } @@ -331,7 +332,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) return (-1); } ipmi_intf_session_set_authtype(intf, authtype); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session authtype."); return (-1); } @@ -348,7 +349,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) return (-1); } ipmi_intf_session_set_privlvl(intf, privlvl); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session privilege level."); return (-1); @@ -365,7 +366,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) return (-1); } ipmi_intf_session_set_port(intf, port); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session port."); return (-1); } @@ -413,12 +414,12 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv) } fp = ipmi_open_file_read(argv[0]); - if (fp == NULL) + if (!fp) return -1; while (feof(fp) == 0) { ret = fgets(buf, EXEC_BUF_SIZE, fp); - if (ret == NULL) + if (!ret) continue; /* clip off optional comment tail indicated by # */ @@ -462,10 +463,10 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv) /* parse it and make argument list */ __argc = 0; - for (tok = strtok(ptr, " "); tok != NULL; tok = strtok(NULL, " ")) { + for (tok = strtok(ptr, " "); tok; tok = strtok(NULL, " ")) { if (__argc < EXEC_ARG_SIZE) { __argv[__argc++] = strdup(tok); - if (__argv[__argc-1] == NULL) { + if (!__argv[__argc-1]) { lprintf(LOG_ERR, "ipmitool: malloc failure"); if (fp) { fclose(fp); @@ -502,7 +503,7 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv) /* free argument list */ for (i=0; i<__argc; i++) { - if (__argv[i] != NULL) { + if (__argv[i]) { free(__argv[i]); __argv[i] = NULL; } diff --git a/src/plugins/dummy/dummy.c b/src/plugins/dummy/dummy.c index 0512ad3..3a86656 100644 --- a/src/plugins/dummy/dummy.c +++ b/src/plugins/dummy/dummy.c @@ -179,7 +179,7 @@ ipmi_dummyipmi_open(struct ipmi_intf *intf) char *dummy_sock_path; dummy_sock_path = getenv("IPMI_DUMMY_SOCK"); - if (dummy_sock_path == NULL) { + if (!dummy_sock_path) { lprintf(LOG_DEBUG, "No IPMI_DUMMY_SOCK set. Using " IPMI_DUMMY_DEFAULTSOCK); dummy_sock_path = IPMI_DUMMY_DEFAULTSOCK; } @@ -218,7 +218,7 @@ ipmi_dummyipmi_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req) struct dummy_rq req_dummy; struct dummy_rs rsp_dummy; - if (intf == NULL || intf->fd < 0 || intf->opened != 1) { + if (!intf || intf->fd < 0 || intf->opened != 1) { lprintf(LOG_ERR, "dummy failed on intf check."); return NULL; } diff --git a/src/plugins/imb/imbapi.c b/src/plugins/imb/imbapi.c index 33ab434..6306378 100644 --- a/src/plugins/imb/imbapi.c +++ b/src/plugins/imb/imbapi.c @@ -117,7 +117,7 @@ open_imb(void) OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hDevice == NULL || hDevice == INVALID_HANDLE_VALUE) { + if (!hDevice || INVALID_HANDLE_VALUE == hDevice) { return 0; } /* Detect the IPMI version for processing requests later. This @@ -1014,7 +1014,7 @@ GetAsyncImbpMessage_Ex(ImbPacket *msgPtr, DWORD *msgLen, DWORD timeOut, ImbAsyncRequest req; while (1) { - if ((msgPtr == NULL) || (msgLen == NULL) || ( seqNo == NULL)) { + if (!msgPtr || !msgLen || !seqNo) { return ACCESN_ERROR; } @@ -1150,7 +1150,7 @@ RegisterForImbAsyncMessageNotification(unsigned int *handleId) DWORD respLength ; int dummy; /*allow only one app to register */ - if ((handleId == NULL ) || (AsyncEventHandle)) { + if (!handleId || AsyncEventHandle) { return ACCESN_ERROR; } status = DeviceIoControl(hDevice, IOCTL_IMB_REGISTER_ASYNC_OBJ, &dummy, diff --git a/src/plugins/ipmi_intf.c b/src/plugins/ipmi_intf.c index 07d6707..69d2c0d 100644 --- a/src/plugins/ipmi_intf.c +++ b/src/plugins/ipmi_intf.c @@ -137,9 +137,9 @@ void ipmi_intf_print(struct ipmi_intf_support * intflist) for (intf = ipmi_intf_table; intf && *intf; intf++) { - if (intflist != NULL) { + if (intflist) { found = 0; - for (sup=intflist; sup->name != NULL; sup++) { + for (sup=intflist; sup->name; sup++) { if (strncmp(sup->name, (*intf)->name, strlen(sup->name)) == 0 && strncmp(sup->name, (*intf)->name, strlen((*intf)->name)) == 0 && sup->supported == 1) @@ -170,9 +170,9 @@ struct ipmi_intf * ipmi_intf_load(char * name) struct ipmi_intf ** intf; struct ipmi_intf * i; - if (name == NULL) { + if (!name) { i = ipmi_intf_table[0]; - if (i->setup != NULL && (i->setup(i) < 0)) { + if (i->setup && (i->setup(i) < 0)) { lprintf(LOG_ERR, "Unable to setup " "interface %s", name); return NULL; @@ -181,11 +181,12 @@ struct ipmi_intf * ipmi_intf_load(char * name) } for (intf = ipmi_intf_table; - ((intf != NULL) && (*intf != NULL)); - intf++) { + intf && *intf; + intf++) + { i = *intf; if (strncmp(name, i->name, strlen(name)) == 0) { - if (i->setup != NULL && (i->setup(i) < 0)) { + if (i->setup && (i->setup(i) < 0)) { lprintf(LOG_ERR, "Unable to setup " "interface %s", name); return NULL; @@ -200,11 +201,11 @@ struct ipmi_intf * ipmi_intf_load(char * name) void ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname) { - if (intf->ssn_params.hostname != NULL) { + if (intf->ssn_params.hostname) { free(intf->ssn_params.hostname); intf->ssn_params.hostname = NULL; } - if (hostname == NULL) { + if (!hostname) { return; } intf->ssn_params.hostname = strdup(hostname); @@ -215,7 +216,7 @@ ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username) { memset(intf->ssn_params.username, 0, 17); - if (username == NULL) + if (!username) return; memcpy(intf->ssn_params.username, username, __min(strlen(username), 16)); @@ -226,7 +227,7 @@ ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password) { memset(intf->ssn_params.authcode_set, 0, IPMI_AUTHCODE_BUFFER_SIZE); - if (password == NULL) { + if (!password) { intf->ssn_params.password = 0; return; } @@ -299,7 +300,7 @@ ipmi_intf_session_set_retry(struct ipmi_intf * intf, int retry) void ipmi_intf_session_cleanup(struct ipmi_intf *intf) { - if (intf->session == NULL) { + if (!intf->session) { return; } @@ -331,7 +332,7 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) params = &intf->ssn_params; - if (params->hostname == NULL || strlen((const char *)params->hostname) == 0) { + if (!params->hostname || strlen((const char *)params->hostname) == 0) { lprintf(LOG_ERR, "No hostname specified!"); return -1; } @@ -359,7 +360,7 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) * and) try the next address. */ - for (rp = rp0; rp != NULL; rp = rp->ai_next) { + for (rp = rp0; rp; rp = rp->ai_next) { /* We are only interested in IPv4 and IPv6 */ if ((rp->ai_family != AF_INET6) && (rp->ai_family != AF_INET)) { continue; @@ -403,8 +404,8 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) break; } - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) { + for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) { continue; } @@ -421,7 +422,7 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) len = sizeof(struct sockaddr_in6); if ( getnameinfo((struct sockaddr *)tmp6, len, hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) == 0) { lprintf(LOG_DEBUG, "Testing %s interface address: %s scope=%d", - ifa->ifa_name != NULL ? ifa->ifa_name : "???", + ifa->ifa_name ? ifa->ifa_name : "???", hbuf, tmp6->sin6_scope_id); } diff --git a/src/plugins/lan/lan.c b/src/plugins/lan/lan.c index 18f61bb..0d42f12 100644 --- a/src/plugins/lan/lan.c +++ b/src/plugins/lan/lan.c @@ -121,7 +121,7 @@ ipmi_req_add_entry(struct ipmi_intf * intf, struct ipmi_rq * req, uint8_t req_se struct ipmi_rq_entry * e; e = malloc(sizeof(struct ipmi_rq_entry)); - if (e == NULL) { + if (!e) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -132,7 +132,7 @@ ipmi_req_add_entry(struct ipmi_intf * intf, struct ipmi_rq * req, uint8_t req_se e->intf = intf; e->rq_seq = req_seq; - if (ipmi_req_entries == NULL) + if (!ipmi_req_entries) ipmi_req_entries = e; else ipmi_req_entries_tail->next = e; @@ -148,7 +148,7 @@ ipmi_req_lookup_entry(uint8_t seq, uint8_t cmd) { struct ipmi_rq_entry * e = ipmi_req_entries; while (e && (e->rq_seq != seq || e->req.msg.cmd != cmd)) { - if (e->next == NULL || e == e->next) + if (!e->next || e == e->next) return NULL; e = e->next; } @@ -203,7 +203,7 @@ ipmi_req_clear_entries(void) while (e) { lprintf(LOG_DEBUG+3, "cleared list entry seq=0x%02x cmd=0x%02x", e->rq_seq, e->req.msg.cmd); - if (e->next != NULL) { + if (e->next) { p = e->next; free(e); e = p; @@ -342,7 +342,7 @@ ipmi_handle_pong(struct ipmi_intf * intf, struct ipmi_rs * rsp) { struct rmcp_pong * pong; - if (rsp == NULL) + if (!rsp) return -1; pong = (struct rmcp_pong *)rsp->data; @@ -399,7 +399,7 @@ ipmi_lan_ping(struct ipmi_intf * intf) int rv; data = malloc(len); - if (data == NULL) { + if (!data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } @@ -460,7 +460,7 @@ ipmi_lan_poll_recv(struct ipmi_intf * intf) rsp = ipmi_lan_recv_packet(intf); - while (rsp != NULL) { + while (rsp) { /* parse response headers */ memcpy(&rmcp_rsp, rsp->data, 4); @@ -610,7 +610,7 @@ ipmi_lan_poll_recv(struct ipmi_intf * intf) rsp = !rsp->ccode ? ipmi_lan_recv_packet(intf) : NULL; if (!entry->bridging_level) entry->req.msg.cmd = entry->req.msg.target_cmd; - if (rsp == NULL) { + if (!rsp) { ipmi_req_remove_entry(entry->rq_seq, entry->req.msg.cmd); } continue; @@ -736,7 +736,7 @@ ipmi_lan_build_cmd(struct ipmi_intf * intf, struct ipmi_rq * req, int isRetry) // We don't have this request in the list so we can add it // to the list entry = ipmi_req_add_entry(intf, req, curr_seq); - if (entry == NULL) + if (!entry) return NULL; } @@ -746,7 +746,7 @@ ipmi_lan_build_cmd(struct ipmi_intf * intf, struct ipmi_rq * req, int isRetry) if (intf->transit_addr != intf->my_addr && intf->transit_addr != 0) len += 8; msg = malloc(len); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -906,7 +906,7 @@ ipmi_lan_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) lprintf(LOG_DEBUG, "ipmi_lan_send_cmd:opened=[%d], open=[%d]", intf->opened, intf->open); - if (intf->opened == 0 && intf->open != NULL) { + if (!intf->opened && intf->open) { if (intf->open(intf) < 0) { lprintf(LOG_DEBUG, "Failed to open LAN interface"); return NULL; @@ -919,7 +919,7 @@ ipmi_lan_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) isRetry = ( try > 0 ) ? 1 : 0; entry = ipmi_lan_build_cmd(intf, req, isRetry); - if (entry == NULL) { + if (!entry) { lprintf(LOG_ERR, "Aborting send command, unable to build"); return NULL; } @@ -944,7 +944,7 @@ ipmi_lan_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) /* Duplicate Request ccode most likely indicates a response to a previous retry. Ignore and keep polling. */ - if((rsp != NULL) && (rsp->ccode == 0xcf)) { + if(rsp && rsp->ccode == 0xcf) { rsp = NULL; rsp = ipmi_lan_poll_recv(intf); } @@ -1004,7 +1004,7 @@ ipmi_lan_build_rsp(struct ipmi_intf * intf, struct ipmi_rs * rsp, int * llen) len += 16; msg = malloc(len); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -1124,7 +1124,7 @@ uint8_t * ipmi_lan_build_sol_msg(struct ipmi_intf * intf, payload->payload.sol_packet.character_count; // The actual payload msg = malloc(len); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -1217,15 +1217,15 @@ ipmi_lan_send_sol_payload(struct ipmi_intf * intf, int len; int try = 0; - if (intf->opened == 0 && intf->open != NULL) { + if (!intf->opened && intf->open) { if (intf->open(intf) < 0) return NULL; } msg = ipmi_lan_build_sol_msg(intf, payload, &len); - if (len <= 0 || msg == NULL) { + if (len <= 0 || !msg) { lprintf(LOG_ERR, "Invalid SOL payload packet"); - if (msg != NULL) { + if (msg) { free(msg); msg = NULL; } @@ -1273,7 +1273,7 @@ ipmi_lan_send_sol_payload(struct ipmi_intf * intf, } } - if (msg != NULL) { + if (msg) { free(msg); msg = NULL; } @@ -1525,9 +1525,7 @@ ipmi_lan_keepalive(struct ipmi_intf * intf) return 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) - return -1; - if (rsp->ccode) + if (!rsp || rsp->ccode) return -1; return 0; @@ -1555,7 +1553,7 @@ ipmi_get_auth_capabilities_cmd(struct ipmi_intf * intf) req.msg.data_len = 2; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_INFO, "Get Auth Capabilities command failed"); return -1; } @@ -1670,7 +1668,7 @@ ipmi_get_session_challenge_cmd(struct ipmi_intf * intf) req.msg.data_len = 17; /* 1 byte for authtype, 16 for user */ rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Session Challenge command failed"); return -1; } @@ -1745,7 +1743,7 @@ ipmi_activate_session_cmd(struct ipmi_intf * intf) val2str(s->authtype, ipmi_authtype_session_vals)); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Activate Session command failed"); s->active = 0; return -1; @@ -1836,7 +1834,7 @@ ipmi_set_session_privlvl_cmd(struct ipmi_intf * intf) rsp = intf->sendrecv(intf, &req); bridge_possible = backup_bridge_possible; - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set Session Privilege Level to %s failed", val2str(privlvl, ipmi_privlvl_vals)); return -1; @@ -1880,7 +1878,7 @@ ipmi_close_session_cmd(struct ipmi_intf * intf) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Close Session command failed"); return -1; } @@ -1989,7 +1987,7 @@ ipmi_lan_open(struct ipmi_intf * intf) struct ipmi_session *s; struct ipmi_session_params *p; - if (intf == NULL || intf->opened) + if (!intf || intf->opened) return -1; s = intf->session; @@ -2004,7 +2002,7 @@ ipmi_lan_open(struct ipmi_intf * intf) if (p->retry == 0) p->retry = IPMI_LAN_RETRY; - if (p->hostname == NULL || strlen((const char *)p->hostname) == 0) { + if (!p->hostname || strlen((const char *)p->hostname) == 0) { lprintf(LOG_ERR, "No hostname specified!"); return -1; } diff --git a/src/plugins/lanplus/lanplus.c b/src/plugins/lanplus/lanplus.c index c1270f0..1f152eb 100644 --- a/src/plugins/lanplus/lanplus.c +++ b/src/plugins/lanplus/lanplus.c @@ -297,7 +297,7 @@ ipmi_req_add_entry(struct ipmi_intf * intf, struct ipmi_rq * req, uint8_t req_se struct ipmi_rq_entry * e; e = malloc(sizeof(struct ipmi_rq_entry)); - if (e == NULL) { + if (!e) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -308,7 +308,7 @@ ipmi_req_add_entry(struct ipmi_intf * intf, struct ipmi_rq * req, uint8_t req_se e->intf = intf; e->rq_seq = req_seq; - if (ipmi_req_entries == NULL) + if (!ipmi_req_entries) ipmi_req_entries = e; else ipmi_req_entries_tail->next = e; @@ -572,7 +572,7 @@ ipmiv2_lan_ping(struct ipmi_intf * intf) int rv; data = malloc(len); - if (data == NULL) { + if (!data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return -1; } @@ -621,7 +621,7 @@ ipmi_lan_poll_single(struct ipmi_intf * intf) rsp = ipmi_lan_recv_packet(intf); /* check if no packet has come */ - if (rsp == NULL) { + if (!rsp) { return NULL; } @@ -741,7 +741,7 @@ ipmi_lan_poll_single(struct ipmi_intf * intf) entry = ipmi_req_lookup_entry(rsp->payload.ipmi_response.rq_seq, rsp->payload.ipmi_response.cmd); - if (entry == NULL) { + if (!entry) { lprintf(LOG_INFO, "IPMI Request Match NOT FOUND"); /* read one more packet */ return (struct ipmi_rs *)1; @@ -1615,7 +1615,7 @@ ipmi_lanplus_build_v2x_msg( msg = malloc(len); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return; } @@ -1936,7 +1936,7 @@ ipmi_lanplus_build_v2x_ipmi_cmd( } } - if (entry == NULL) + if (!entry) return NULL; // Build our payload @@ -2002,13 +2002,13 @@ ipmi_lanplus_build_v15_ipmi_cmd( struct ipmi_rq_entry * entry; entry = ipmi_req_add_entry(intf, req, 0); - if (entry == NULL) + if (!entry) return NULL; len = req->msg.data_len + 21; msg = malloc(len); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -2199,7 +2199,7 @@ ipmi_lanplus_send_payload( entry = ipmi_lanplus_build_v2x_ipmi_cmd(intf, ipmi_request, isRetry); } - if (entry == NULL) { + if (!entry) { lprintf(LOG_ERR, "Aborting send command, unable to build"); return NULL; } @@ -2345,7 +2345,7 @@ ipmi_lanplus_send_payload( /* Duplicate Request ccode most likely indicates a response to a previous retry. Ignore and keep polling. */ - while ((rsp != NULL) && (rsp->ccode == 0xcf)) + while (rsp && rsp->ccode == 0xcf) { rsp = NULL; rsp = ipmi_lan_poll_recv(intf); @@ -2718,7 +2718,7 @@ ipmi_get_auth_capabilities_cmd( rsp = intf->sendrecv(intf, &req); - if (rsp == NULL || rsp->ccode) { + if (!rsp || rsp->ccode) { /* * It's very possible that this failed because we asked for IPMI * v2 data. Ask again, without requesting IPMI v2 data. @@ -2727,7 +2727,7 @@ ipmi_get_auth_capabilities_cmd( rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_INFO, "Get Auth Capabilities error"); return 1; } @@ -2758,7 +2758,7 @@ ipmi_close_session_cmd(struct ipmi_intf * intf) uint8_t msg_data[4]; uint8_t backupBridgePossible; - if (intf->session == NULL + if (!intf->session || intf->session->v2_data.session_state != LANPLUS_STATE_ACTIVE) return -1; @@ -2776,7 +2776,7 @@ ipmi_close_session_cmd(struct ipmi_intf * intf) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { /* Looks like the session was closed */ lprintf(LOG_ERR, "Close Session command failed"); return -1; @@ -2827,7 +2827,7 @@ ipmi_lanplus_open_session(struct ipmi_intf * intf) * Build an Open Session Request Payload */ msg = (uint8_t*)malloc(IPMI_OPEN_SESSION_REQUEST_SIZE); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -2908,7 +2908,7 @@ ipmi_lanplus_open_session(struct ipmi_intf * intf) free(msg); msg = NULL; - if (rsp == NULL ) { + if (!rsp ) { lprintf(LOG_DEBUG, "Timeout in open session response message."); return 2; } @@ -3013,7 +3013,7 @@ ipmi_lanplus_rakp1(struct ipmi_intf * intf) * Build a RAKP 1 message */ msg = (uint8_t*)malloc(IPMI_RAKP1_MESSAGE_SIZE); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -3092,7 +3092,7 @@ ipmi_lanplus_rakp1(struct ipmi_intf * intf) free(msg); msg = NULL; - if (rsp == NULL) + if (!rsp) { lprintf(LOG_WARNING, "> Error: no response from RAKP 1 message"); return 2; @@ -3176,7 +3176,7 @@ ipmi_lanplus_rakp3(struct ipmi_intf * intf) * Build a RAKP 3 message */ msg = (uint8_t*)malloc(IPMI_RAKP3_MESSAGE_MAX_SIZE); - if (msg == NULL) { + if (!msg) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -3265,7 +3265,7 @@ ipmi_lanplus_rakp3(struct ipmi_intf * intf) */ return 1; } - else if (rsp == NULL) + else if (!rsp) { lprintf(LOG_WARNING, "> Error: no response from RAKP 3 message"); return 2; @@ -3356,7 +3356,7 @@ ipmi_set_session_privlvl_cmd(struct ipmi_intf * intf) req.msg.data_len = 1; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Set Session Privilege Level to %s failed", val2str(privlvl, ipmi_privlvl_vals)); bridgePossible = backupBridgePossible; @@ -3410,7 +3410,7 @@ ipmi_lanplus_open(struct ipmi_intf * intf) if (!params->retry) params->retry = IPMI_LAN_RETRY; - if (params->hostname == NULL || strlen((const char *)params->hostname) == 0) { + if (!params->hostname || strlen((const char *)params->hostname) == 0) { lprintf(LOG_ERR, "No hostname specified!"); return -1; } @@ -3627,7 +3627,7 @@ ipmi_lanplus_keepalive(struct ipmi_intf * intf) return 0; rsp = intf->sendrecv(intf, &req); - while (rsp != NULL && is_sol_packet(rsp)) { + while (rsp && is_sol_packet(rsp)) { /* rsp was SOL data instead of our answer */ /* since it didn't go through the sol recv, do sol recv stuff here */ ack_sol_packet(intf, rsp); @@ -3635,13 +3635,11 @@ ipmi_lanplus_keepalive(struct ipmi_intf * intf) if (rsp->data_len) intf->session->sol_data.sol_input_handler(rsp); rsp = ipmi_lan_poll_recv(intf); - if (rsp == NULL) /* the get device id answer never got back, but retry mechanism was bypassed by SOL data */ + if (!rsp) /* the get device id answer never got back, but retry mechanism was bypassed by SOL data */ return 0; /* so get device id command never returned, the connection is still alive */ } - if (rsp == NULL) - return -1; - if (rsp->ccode) + if (!rsp || rsp->ccode) return -1; return 0; diff --git a/src/plugins/lanplus/lanplus_crypt.c b/src/plugins/lanplus/lanplus_crypt.c index 07c22af..145c880 100644 --- a/src/plugins/lanplus/lanplus_crypt.c +++ b/src/plugins/lanplus/lanplus_crypt.c @@ -103,7 +103,7 @@ lanplus_rakp2_hmac_matches(const struct ipmi_session * session, strlen((const char *)intf->ssn_params.username); /* optional */ buffer = malloc(bufferLength); - if (buffer == NULL) { + if (!buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -265,7 +265,7 @@ lanplus_rakp4_hmac_matches(const struct ipmi_session * session, 16; /* GUIDc */ buffer = (uint8_t *)malloc(bufferLength); - if (buffer == NULL) { + if (!buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -432,7 +432,7 @@ lanplus_generate_rakp3_authcode(uint8_t * output_buffer, strlen((const char *)intf->ssn_params.username); input_buffer = malloc(input_buffer_length); - if (input_buffer == NULL) { + if (!input_buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -554,7 +554,7 @@ lanplus_generate_sik(struct ipmi_session * session, struct ipmi_intf * intf) strlen((const char *)intf->ssn_params.username); input_buffer = malloc(input_buffer_length); - if (input_buffer == NULL) { + if (!input_buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -836,7 +836,7 @@ lanplus_encrypt_payload(uint8_t crypt_alg, pad_length = IPMI_CRYPT_AES_CBC_128_BLOCK_SIZE - mod; padded_input = (uint8_t*)malloc(input_length + pad_length + 1); - if (padded_input == NULL) { + if (!padded_input) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } @@ -853,7 +853,7 @@ lanplus_encrypt_payload(uint8_t crypt_alg, if (lanplus_rand(output, IPMI_CRYPT_AES_CBC_128_BLOCK_SIZE)) { lprintf(LOG_ERR, "lanplus_encrypt_payload: Error generating IV"); - if (padded_input != NULL) { + if (padded_input) { free(padded_input); padded_input = NULL; } @@ -1003,7 +1003,7 @@ lanplus_decrypt_payload(uint8_t crypt_alg, const uint8_t * key, assert(crypt_alg == IPMI_CRYPT_AES_CBC_128); decrypted_payload = (uint8_t*)malloc(input_length); - if (decrypted_payload == NULL) { + if (!decrypted_payload) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return 1; } diff --git a/src/plugins/lanplus/lanplus_crypt_impl.c b/src/plugins/lanplus/lanplus_crypt_impl.c index 6cbf1a2..3ff585b 100644 --- a/src/plugins/lanplus/lanplus_crypt_impl.c +++ b/src/plugins/lanplus/lanplus_crypt_impl.c @@ -179,7 +179,7 @@ lanplus_encrypt_aes_cbc_128(const uint8_t * iv, } ctx = EVP_CIPHER_CTX_new(); - if (ctx == NULL) { + if (!ctx) { lprintf(LOG_DEBUG, "ERROR: EVP_CIPHER_CTX_new() failed"); return; } @@ -258,7 +258,7 @@ lanplus_decrypt_aes_cbc_128(const uint8_t * iv, return; ctx = EVP_CIPHER_CTX_new(); - if (ctx == NULL) { + if (!ctx) { lprintf(LOG_DEBUG, "ERROR: EVP_CIPHER_CTX_new() failed"); return; } diff --git a/src/plugins/open/open.c b/src/plugins/open/open.c index f25369f..fd1defd 100644 --- a/src/plugins/open/open.c +++ b/src/plugins/open/open.c @@ -186,12 +186,12 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) int retval = 0; - if (intf == NULL || req == NULL) + if (!intf || !req) return NULL; ipmb_addr.channel = intf->target_channel & 0x0f; - if (intf->opened == 0 && intf->open != NULL) + if (!intf->opened && intf->open) if (intf->open(intf) < 0) return NULL; @@ -253,7 +253,7 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) /* FIXME backup "My address" */ data_len = req->msg.data_len + 8; data = malloc(data_len); - if (data == NULL) { + if (!data) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -296,7 +296,7 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) _req.msgid = curr_seq++; /* In case of a bridge request */ - if( data != NULL && data_len != 0 ) { + if (data && data_len != 0) { _req.msg.data = data; _req.msg.data_len = data_len; _req.msg.netfn = IPMI_NETFN_APP; @@ -311,7 +311,7 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) if (ioctl(intf->fd, IPMICTL_SEND_COMMAND, &_req) < 0) { lperror(LOG_ERR, "Unable to send command"); - if (data != NULL) { + if (data) { free(data); data = NULL; } @@ -323,7 +323,7 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) */ if (intf->noanswer) { - if (data != NULL) { + if (data) { free(data); data = NULL; } @@ -339,14 +339,14 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) } while (retval < 0 && errno == EINTR); if (retval < 0) { lperror(LOG_ERR, "I/O Error"); - if (data != NULL) { + if (data) { free(data); data = NULL; } return NULL; } else if (retval == 0) { lprintf(LOG_ERR, "No data available"); - if (data != NULL) { + if (data) { free(data); data = NULL; } @@ -354,7 +354,7 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) } if (FD_ISSET(intf->fd, &rset) == 0) { lprintf(LOG_ERR, "No data available"); - if (data != NULL) { + if (data) { free(data); data = NULL; } @@ -370,7 +370,7 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) if (ioctl(intf->fd, IPMICTL_RECEIVE_MSG_TRUNC, &recv) < 0) { lperror(LOG_ERR, "Error receiving message"); if (errno != EMSGSIZE) { - if (data != NULL) { + if (data) { free(data); data = NULL; } @@ -430,9 +430,9 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) rsp.data[rsp.data_len] = 0; } - if (data != NULL) { - free(data); - data = NULL; + if (data) { + free(data); + data = NULL; } return &rsp; diff --git a/src/plugins/usb/usb.c b/src/plugins/usb/usb.c index 80e5726..a03b1fe 100644 --- a/src/plugins/usb/usb.c +++ b/src/plugins/usb/usb.c @@ -121,14 +121,14 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos) FILE *fp; fp = fopen("/proc/scsi/sg/device_strs", "r"); - if (fp == NULL) { + if (!fp) { /* Return 1 on error */ return 1; } while (1) { /* Read line by line and search for "AMI" */ - if (fgets(linebuf, 80, fp) == NULL) { + if (!fgets(linebuf, 80, fp)) { break; } @@ -145,7 +145,7 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos) } *num_ami_devices = numdevfound; - if (fp != NULL) { + if (fp) { fclose(fp); fp = NULL; }