diff options
author | Alexander Amelkin <alexander@amelkin.msk.ru> | 2018-08-21 17:16:19 +0300 |
---|---|---|
committer | Alexander Amelkin <alexander@amelkin.msk.ru> | 2018-08-21 17:30:25 +0300 |
commit | e9716e216d970b2c84eff5bde5802a05c202cacb (patch) | |
tree | 9e6d868ac902db4ccc3b9a667faad16a50189c27 /lib/ipmi_chassis.c | |
parent | f3ef88724f4fb16bc6854e8e850acc2a2145e659 (diff) | |
download | ipmitool-e9716e216d970b2c84eff5bde5802a05c202cacb.tar.gz |
Refactoring: optimize pointer checks
Remove all direct comparisons to 'NULL' for pointers.
Replace them with boolean-like 'if (ptr)' and 'if (!ptr)'.
This makes conditions shorter and easier to read.
Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
Diffstat (limited to 'lib/ipmi_chassis.c')
-rw-r--r-- | lib/ipmi_chassis.c | 48 |
1 files changed, 24 insertions, 24 deletions
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); |