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>
This commit is contained in:
Alexander Amelkin
2018-08-21 17:16:19 +03:00
parent f3ef88724f
commit e9716e216d
48 changed files with 1050 additions and 1090 deletions

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}