mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-06-28 08:11:36 +00:00
Refactoring: get rid of superfluous comparisons
Make code better readable by replacing `if (rsp->ccode > 0)` and 'if (rsp->ccode != 0)' with just `if (rsp->ccode)` as rsp->ccode is anyway an unsigned byte and can't be negative. Also replace 'if (rsp->ccode == 0)' with 'if (!rsp->ccode)'. All these changes make lines shorter and easier to read as a non-zero ccode is an indication of some failure, and so !ccode naturally reads as 'no error'. Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
@@ -366,7 +366,7 @@ openipmi_enable_event_msg_buffer(struct ipmi_intf * intf)
|
||||
lprintf(LOG_ERR, "Get BMC Global Enables command failed");
|
||||
return -1;
|
||||
}
|
||||
else if (rsp->ccode > 0) {
|
||||
else if (rsp->ccode) {
|
||||
lprintf(LOG_ERR, "Get BMC Global Enables command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
@@ -382,7 +382,7 @@ openipmi_enable_event_msg_buffer(struct ipmi_intf * intf)
|
||||
lprintf(LOG_ERR, "Set BMC Global Enables command failed");
|
||||
return -1;
|
||||
}
|
||||
else if (rsp->ccode > 0) {
|
||||
else if (rsp->ccode) {
|
||||
lprintf(LOG_ERR, "Set BMC Global Enables command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
@@ -511,7 +511,7 @@ selwatch_get_data(struct ipmi_intf * intf, struct sel_data *data)
|
||||
lprintf(LOG_ERR, "Get SEL Info command failed");
|
||||
return 0;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return 0;
|
||||
|
||||
@@ -1527,7 +1527,7 @@ ipmi_lan_keepalive(struct ipmi_intf * intf)
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (rsp == NULL)
|
||||
return -1;
|
||||
if (rsp->ccode > 0)
|
||||
if (rsp->ccode)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@@ -1562,7 +1562,7 @@ ipmi_get_auth_capabilities_cmd(struct ipmi_intf * intf)
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "get_auth_capabilities");
|
||||
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
lprintf(LOG_INFO, "Get Auth Capabilities command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
@@ -1677,7 +1677,7 @@ ipmi_get_session_challenge_cmd(struct ipmi_intf * intf)
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "get_session_challenge");
|
||||
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
switch (rsp->ccode) {
|
||||
case 0x81:
|
||||
lprintf(LOG_ERR, "Invalid user name");
|
||||
@@ -1844,7 +1844,7 @@ ipmi_set_session_privlvl_cmd(struct ipmi_intf * intf)
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "set_session_privlvl");
|
||||
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
lprintf(LOG_ERR, "Set Session Privilege Level to %s failed: %s",
|
||||
val2str(privlvl, ipmi_privlvl_vals),
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
@@ -1892,7 +1892,7 @@ ipmi_close_session_cmd(struct ipmi_intf * intf)
|
||||
"session ID %08lx", (long)session_id);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
lprintf(LOG_ERR, "Close Session command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
|
||||
@@ -2718,7 +2718,7 @@ ipmi_get_auth_capabilities_cmd(
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (rsp == NULL || rsp->ccode > 0) {
|
||||
if (rsp == NULL || rsp->ccode) {
|
||||
/*
|
||||
* It's very possible that this failed because we asked for IPMI
|
||||
* v2 data. Ask again, without requesting IPMI v2 data.
|
||||
@@ -2731,7 +2731,7 @@ ipmi_get_auth_capabilities_cmd(
|
||||
lprintf(LOG_INFO, "Get Auth Capabilities error");
|
||||
return 1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
lprintf(LOG_INFO, "Get Auth Capabilities error: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return 1;
|
||||
@@ -2790,7 +2790,7 @@ ipmi_close_session_cmd(struct ipmi_intf * intf)
|
||||
(long)intf->session->v2_data.bmc_id);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
lprintf(LOG_ERR, "Close Session command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
@@ -3365,7 +3365,7 @@ ipmi_set_session_privlvl_cmd(struct ipmi_intf * intf)
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "set_session_privlvl");
|
||||
|
||||
if (rsp->ccode > 0) {
|
||||
if (rsp->ccode) {
|
||||
lprintf(LOG_ERR, "Set Session Privilege Level to %s failed: %s",
|
||||
val2str(privlvl, ipmi_privlvl_vals),
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
@@ -3641,7 +3641,7 @@ ipmi_lanplus_keepalive(struct ipmi_intf * intf)
|
||||
|
||||
if (rsp == NULL)
|
||||
return -1;
|
||||
if (rsp->ccode > 0)
|
||||
if (rsp->ccode)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -425,7 +425,7 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
|
||||
rsp.data_len = recv.msg.data_len - 1;
|
||||
|
||||
/* save response data for caller */
|
||||
if (rsp.ccode == 0 && rsp.data_len > 0) {
|
||||
if (!rsp.ccode && rsp.data_len > 0) {
|
||||
memmove(rsp.data, rsp.data + 1, rsp.data_len);
|
||||
rsp.data[rsp.data_len] = 0;
|
||||
}
|
||||
|
||||
@@ -603,7 +603,7 @@ ipmi_usb_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req)
|
||||
rsp.ccode = rsp.data[0];
|
||||
|
||||
/* Save response data for caller */
|
||||
if ((rsp.ccode == 0) && (rsp.data_len > 0)) {
|
||||
if (!rsp.ccode && rsp.data_len > 0) {
|
||||
memmove(rsp.data, rsp.data + 1, rsp.data_len - 1);
|
||||
rsp.data[rsp.data_len] = 0;
|
||||
rsp.data_len -= 1;
|
||||
|
||||
Reference in New Issue
Block a user