mirror of
https://github.com/SCST-project/scst.git
synced 2026-10-22 06:02:33 +00:00
scst: Simplify pointer tests and redundant condition grouping
Use direct pointer truth tests, put scalar constants on the right and remove redundant parentheses from conditions and address expressions. Preserve required precedence, dereferenced-pointer semantics and short-circuit evaluation. Keep preprocessor expressions and disabled debug alternatives intact. Use __func__ for unchanged parameter-error diagnostics and correct the byte-order diagnostic spelling. Source review also identified eight negated negative-index tests in the daemon's parameter lookup chains. Use explicit >= 0 comparisons while retaining assignment order and short-circuit evaluation. This readability cleanup does not remove assignment-in-condition findings. Checkpatch reports COMPARISON_TO_NULL: Comparison to NULL could be written "target" Checkpatch reports UNNECESSARY_PARENTHESES: Unnecessary parentheses around tlv->value Checkpatch reports CONSTANT_COMPARISON, COMPARISON_TO_NULL. One example: Comparisons should place the constant on the right side of the test Checkpatch reports CONSTANT_COMPARISON, EMBEDDED_FUNCTION_NAME, TYPO_SPELLING. One example: Comparisons should place the constant on the right side of the test
This commit is contained in:
@@ -128,7 +128,7 @@ static void decode_base64_string(const char *string, u8 *intnum, int int_len)
|
||||
u8 num[4];
|
||||
int octets;
|
||||
|
||||
if ((string == NULL) || (intnum == NULL))
|
||||
if (!string || !intnum)
|
||||
return;
|
||||
len = strlen(string);
|
||||
if (len == 0)
|
||||
@@ -142,7 +142,7 @@ static void decode_base64_string(const char *string, u8 *intnum, int int_len)
|
||||
num[1] = decode_base64_digit(string[count + 1]);
|
||||
num[2] = decode_base64_digit(string[count + 2]);
|
||||
num[3] = decode_base64_digit(string[count + 3]);
|
||||
if ((num[0] == 65) || (num[1] == 65) || (num[2] == 65) || (num[3] == 65))
|
||||
if (num[0] == 65 || num[1] == 65 || num[2] == 65 || num[3] == 65)
|
||||
return;
|
||||
count += 4;
|
||||
octets =
|
||||
@@ -158,7 +158,7 @@ static void decode_base64_string(const char *string, u8 *intnum, int int_len)
|
||||
num[3] = decode_base64_digit(string[count + 3]);
|
||||
//XXX Check for the special "bad character in string" value here like above?
|
||||
//XXX Also check the string for missing/incorrect padding?
|
||||
if ((num[0] == 64) || (num[1] == 64))
|
||||
if (num[0] == 64 || num[1] == 64)
|
||||
return;
|
||||
if (num[2] == 64) {
|
||||
if (num[3] != 64)
|
||||
@@ -201,7 +201,7 @@ static void encode_base64_string(const u8 *intnum, long length, char *string)
|
||||
'4', '5', '6', '7', '8', '9', '+',
|
||||
'/', '=' };
|
||||
|
||||
if ((!intnum) || (!string) || (!length))
|
||||
if (!intnum || !string || !length)
|
||||
return;
|
||||
|
||||
count = 0;
|
||||
@@ -663,7 +663,7 @@ static int chap_target_auth_create_response(struct connection *conn)
|
||||
chap_id = strtol(value, &value, 10);
|
||||
|
||||
user = account_get_first(conn->tid, ISCSI_USER_DIR_OUTGOING);
|
||||
if (user == NULL) {
|
||||
if (!user) {
|
||||
log_warning("CHAP target auth.: no outgoing credentials configured%s",
|
||||
conn->tid ? "." : " for discovery.");
|
||||
retval = CHAP_AUTH_ERROR;
|
||||
|
||||
+40
-40
@@ -113,28 +113,28 @@ int iscsi_attr_create(int attr_size, struct __qelem *attrs_list,
|
||||
struct iscsi_attr *attr;
|
||||
int num = 0;
|
||||
|
||||
if (iscsi_attr_lookup_by_key(attrs_list, key) != NULL) {
|
||||
if (iscsi_attr_lookup_by_key(attrs_list, key)) {
|
||||
log_error("Attribute %s already exists", key);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
attr = malloc(attr_size);
|
||||
if (attr == NULL)
|
||||
if (!attr)
|
||||
goto out;
|
||||
|
||||
memset(attr, 0, attr_size);
|
||||
|
||||
attr->attr_key = strdup(key);
|
||||
if (attr->attr_key == NULL) {
|
||||
if (!attr->attr_key) {
|
||||
log_error("Unable to duplicate attr_key %s", key);
|
||||
res = -ENOMEM;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if ((val != NULL) && (*val != '\0')) {
|
||||
if ((val) && (*val != '\0')) {
|
||||
attr->attr_value = strdup(val);
|
||||
if (attr->attr_value == NULL) {
|
||||
if (!attr->attr_value) {
|
||||
log_error("Unable to duplicate attr_value %s", val);
|
||||
res = -ENOMEM;
|
||||
goto out_free;
|
||||
@@ -143,12 +143,12 @@ int iscsi_attr_create(int attr_size, struct __qelem *attrs_list,
|
||||
|
||||
attr->sysfs_mode = mode;
|
||||
|
||||
if (sysfs_name_tmpl == NULL)
|
||||
if (!sysfs_name_tmpl)
|
||||
goto add;
|
||||
|
||||
if (sysfs_name_tmpl != NULL) {
|
||||
if (sysfs_name_tmpl) {
|
||||
iscsi_strscpy(attr->sysfs_name, sysfs_name_tmpl, sizeof(attr->sysfs_name));
|
||||
if (iscsi_attr_lookup_by_sysfs_name(attrs_list, attr->sysfs_name) == NULL)
|
||||
if (!iscsi_attr_lookup_by_sysfs_name(attrs_list, attr->sysfs_name))
|
||||
goto add;
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ int iscsi_attr_create(int attr_size, struct __qelem *attrs_list,
|
||||
num++;
|
||||
snprintf(attr->sysfs_name, sizeof(attr->sysfs_name),
|
||||
"%s%d", sysfs_name_tmpl, num);
|
||||
if (iscsi_attr_lookup_by_sysfs_name(attrs_list, attr->sysfs_name) == NULL)
|
||||
if (!iscsi_attr_lookup_by_sysfs_name(attrs_list, attr->sysfs_name))
|
||||
break;
|
||||
num++;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ int iscsi_attr_replace(const struct __qelem *attrs_list, const char *sysfs_name,
|
||||
val = config_sep_string(&raw_value);
|
||||
|
||||
attr = iscsi_attr_lookup_by_sysfs_name(attrs_list, sysfs_name);
|
||||
if (attr == NULL) {
|
||||
if (!attr) {
|
||||
log_error("Unknown parameter %s\n", sysfs_name);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
@@ -195,7 +195,7 @@ int iscsi_attr_replace(const struct __qelem *attrs_list, const char *sysfs_name,
|
||||
|
||||
a = iscsi_attr_lookup_by_key(attrs_list, key);
|
||||
|
||||
if ((a != NULL) && (a != attr)) {
|
||||
if (a && a != attr) {
|
||||
log_error("Attr %s (sysfs_name %s) already exists\n", key,
|
||||
a->sysfs_name);
|
||||
res = -EEXIST;
|
||||
@@ -203,15 +203,15 @@ int iscsi_attr_replace(const struct __qelem *attrs_list, const char *sysfs_name,
|
||||
}
|
||||
|
||||
new_key = strdup(key);
|
||||
if (new_key == NULL) {
|
||||
if (!new_key) {
|
||||
log_error("Unable to duplicate attr_key %s", key);
|
||||
res = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((val != NULL) && (*val != '\0')) {
|
||||
if ((val) && (*val != '\0')) {
|
||||
new_val = strdup(val);
|
||||
if (new_val == NULL) {
|
||||
if (!new_val) {
|
||||
log_error("Unable to duplicate attr_value %s", val);
|
||||
res = -ENOMEM;
|
||||
free(new_key);
|
||||
@@ -234,7 +234,7 @@ static struct __qelem *account_list_get(struct target *target, int dir)
|
||||
{
|
||||
struct __qelem *list = NULL;
|
||||
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
list = (dir == ISCSI_USER_DIR_INCOMING) ?
|
||||
&target->target_in_accounts : &target->target_out_accounts;
|
||||
} else
|
||||
@@ -250,7 +250,7 @@ char *config_sep_string(char **pp)
|
||||
char *q;
|
||||
static char blank = '\0';
|
||||
|
||||
if ((pp == NULL) || (*pp == NULL))
|
||||
if (!pp || (!*pp))
|
||||
return ␣
|
||||
|
||||
for (p = *pp; isspace(*p) || (*p == '='); p++)
|
||||
@@ -299,7 +299,7 @@ static char *config_gets(char *buf, int size, const char *data, int *offset)
|
||||
while ((i < size-1) && (data[offs] != '\n') && (data[offs] != ';') && (data[offs] != '\0'))
|
||||
buf[i++] = data[offs++];
|
||||
|
||||
if ((i == 0) && (data[offs] == '\0'))
|
||||
if (i == 0 && (data[offs] == '\0'))
|
||||
return NULL;
|
||||
|
||||
if (data[offs] != '\0')
|
||||
@@ -318,7 +318,7 @@ int accounts_empty(u32 tid, int dir)
|
||||
|
||||
if (tid) {
|
||||
target = target_find_by_id(tid);
|
||||
if (target == NULL)
|
||||
if (!target)
|
||||
return 0;
|
||||
} else
|
||||
target = NULL;
|
||||
@@ -344,7 +344,7 @@ static struct iscsi_attr *account_lookup_by_name(u32 tid, int dir, const char *n
|
||||
|
||||
if (tid) {
|
||||
target = target_find_by_id(tid);
|
||||
if (target == NULL)
|
||||
if (!target)
|
||||
return NULL;
|
||||
} else
|
||||
target = NULL;
|
||||
@@ -360,7 +360,7 @@ struct iscsi_attr *account_get_first(u32 tid, int dir)
|
||||
|
||||
if (tid) {
|
||||
target = target_find_by_id(tid);
|
||||
if (target == NULL)
|
||||
if (!target)
|
||||
return NULL;
|
||||
} else
|
||||
target = NULL;
|
||||
@@ -408,7 +408,7 @@ int config_account_list(u32 tid, int dir, u32 *cnt, u32 *overflow,
|
||||
|
||||
if (tid) {
|
||||
target = target_find_by_id(tid);
|
||||
if (target == NULL)
|
||||
if (!target)
|
||||
return -ENOENT;
|
||||
} else
|
||||
target = NULL;
|
||||
@@ -457,7 +457,7 @@ int config_account_del(u32 tid, int dir, char *name, u32 cookie)
|
||||
|
||||
if (tid) {
|
||||
target = target_find_by_id(tid);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target %d not found", tid);
|
||||
res = -ESRCH;
|
||||
goto out;
|
||||
@@ -466,7 +466,7 @@ int config_account_del(u32 tid, int dir, char *name, u32 cookie)
|
||||
target = NULL;
|
||||
|
||||
user = __account_lookup_by_name(target, dir, name);
|
||||
if (user == NULL) {
|
||||
if (!user) {
|
||||
log_error("User %s not found", name);
|
||||
res = -ENOENT;
|
||||
goto out;
|
||||
@@ -531,7 +531,7 @@ int __config_account_add(struct target *target, int dir, char *name, const char
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (sysfs_name == NULL)
|
||||
if (!sysfs_name)
|
||||
sysfs_name = (dir == ISCSI_USER_DIR_OUTGOING) ?
|
||||
user_keys[ISCSI_USER_DIR_OUTGOING].name :
|
||||
user_keys[ISCSI_USER_DIR_INCOMING].name;
|
||||
@@ -554,7 +554,7 @@ int __config_account_add(struct target *target, int dir, char *name, const char
|
||||
if (err != 0)
|
||||
goto out;
|
||||
|
||||
if (send_to_kern && (sysfs_name != NULL)) {
|
||||
if (send_to_kern && (sysfs_name)) {
|
||||
err = kernel_user_add(target, user, cookie);
|
||||
if (err != 0)
|
||||
goto out_destroy;
|
||||
@@ -581,7 +581,7 @@ int config_account_add(u32 tid, int dir, char *name, const char *pass,
|
||||
|
||||
if (tid) {
|
||||
target = target_find_by_id(tid);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
err = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
@@ -841,7 +841,7 @@ int config_params_get(u32 tid, u64 sid, int type, struct iscsi_param *params)
|
||||
err = 0;
|
||||
|
||||
target = target_find_by_id(tid);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("target %d not found", tid);
|
||||
err = -EINVAL;
|
||||
goto out;
|
||||
@@ -938,7 +938,7 @@ int config_parse_main(const char *data, u32 cookie)
|
||||
* If stop_on_errors is false, let's always continue parsing
|
||||
* and only report errors.
|
||||
*/
|
||||
if (stop_on_errors && (res != 0))
|
||||
if (stop_on_errors && res != 0)
|
||||
goto out_target_free;
|
||||
|
||||
q = buf;
|
||||
@@ -949,7 +949,7 @@ int config_parse_main(const char *data, u32 cookie)
|
||||
if (!strcasecmp(p, "Target")) {
|
||||
global_section = 0;
|
||||
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
res = target_add(target, NULL, cookie);
|
||||
if (res != 0)
|
||||
target_free(target);
|
||||
@@ -975,7 +975,7 @@ int config_parse_main(const char *data, u32 cookie)
|
||||
goto out;
|
||||
} else if (!strcasecmp(p, "Alias") && target) {
|
||||
;
|
||||
} else if (!((idx = params_index_by_name(p, target_keys)) < 0) && (target != NULL)) {
|
||||
} else if ((idx = params_index_by_name(p, target_keys)) >= 0 && (target)) {
|
||||
char *str = config_sep_string(&q);
|
||||
|
||||
n = config_sep_string(&q);
|
||||
@@ -1000,7 +1000,7 @@ int config_parse_main(const char *data, u32 cookie)
|
||||
continue;
|
||||
}
|
||||
target->target_params[idx] = val;
|
||||
} else if (!((idx = params_index_by_name(p, session_keys)) < 0) && (target != NULL)) {
|
||||
} else if ((idx = params_index_by_name(p, session_keys)) >= 0 && (target)) {
|
||||
char *str = config_sep_string(&q);
|
||||
|
||||
n = config_sep_string(&q);
|
||||
@@ -1025,8 +1025,8 @@ int config_parse_main(const char *data, u32 cookie)
|
||||
continue;
|
||||
}
|
||||
target->session_params[idx] = val;
|
||||
} else if (!((idx = params_index_by_name_numwild(p, user_keys)) < 0) &&
|
||||
((target != NULL) || global_section)) {
|
||||
} else if ((idx = params_index_by_name_numwild(p, user_keys)) >= 0 &&
|
||||
((target) || global_section)) {
|
||||
char *name;
|
||||
const char *pass;
|
||||
|
||||
@@ -1055,10 +1055,10 @@ int config_parse_main(const char *data, u32 cookie)
|
||||
}
|
||||
}
|
||||
|
||||
if (stop_on_errors && (res != 0))
|
||||
if (stop_on_errors && res != 0)
|
||||
goto out_target_free;
|
||||
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
res = target_add(target, NULL, cookie);
|
||||
if (res != 0)
|
||||
goto out_target_free;
|
||||
@@ -1066,7 +1066,7 @@ int config_parse_main(const char *data, u32 cookie)
|
||||
|
||||
out:
|
||||
if (stop_on_errors) {
|
||||
if ((res == 0) && !parsed_something)
|
||||
if (res == 0 && !parsed_something)
|
||||
res = -ENOENT;
|
||||
} else
|
||||
res = 0;
|
||||
@@ -1074,7 +1074,7 @@ out:
|
||||
return res;
|
||||
|
||||
out_target_free:
|
||||
if (target != NULL)
|
||||
if (target)
|
||||
target_free(target);
|
||||
goto out;
|
||||
}
|
||||
@@ -1121,14 +1121,14 @@ int config_load(const char *config_name)
|
||||
int size;
|
||||
char *buf;
|
||||
|
||||
if (config_name != NULL)
|
||||
if (config_name)
|
||||
cname = config_name;
|
||||
else
|
||||
cname = CONFIG_FILE;
|
||||
|
||||
config = open(cname, O_RDONLY);
|
||||
if (config == -1) {
|
||||
if ((errno == ENOENT) && (config_name == NULL)) {
|
||||
if (errno == ENOENT && !config_name) {
|
||||
goto out;
|
||||
} else {
|
||||
err = -errno;
|
||||
@@ -1146,7 +1146,7 @@ int config_load(const char *config_name)
|
||||
}
|
||||
|
||||
buf = malloc(size+1);
|
||||
if (buf == NULL) {
|
||||
if (!buf) {
|
||||
err = -ENOMEM;
|
||||
log_error("malloc() failed: %s", strerror(-err));
|
||||
goto out_close;
|
||||
|
||||
@@ -34,7 +34,7 @@ struct connection *conn_alloc(void)
|
||||
int i;
|
||||
|
||||
conn = malloc(sizeof(*conn));
|
||||
if (conn == NULL)
|
||||
if (!conn)
|
||||
goto out;
|
||||
|
||||
memset(conn, 0, sizeof(*conn));
|
||||
|
||||
@@ -75,7 +75,7 @@ int kernel_target_create(struct target *target, u32 *tid, u32 cookie)
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
iscsi_strscpy(info.name, target->name, sizeof(info.name));
|
||||
info.tid = (tid != NULL) ? *tid : 0;
|
||||
info.tid = tid ? *tid : 0;
|
||||
info.cookie = cookie;
|
||||
|
||||
/*
|
||||
@@ -104,7 +104,7 @@ int kernel_target_create(struct target *target, u32 *tid, u32 cookie)
|
||||
}
|
||||
|
||||
kern_attrs = calloc(info.attrs_num, sizeof(*kern_attrs));
|
||||
if (kern_attrs == NULL) {
|
||||
if (!kern_attrs) {
|
||||
err = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ int kernel_target_create(struct target *target, u32 *tid, u32 cookie)
|
||||
strerror(errno));
|
||||
} else {
|
||||
target->tid = err;
|
||||
if (tid != NULL)
|
||||
if (tid)
|
||||
*tid = err;
|
||||
err = 0;
|
||||
}
|
||||
@@ -209,7 +209,7 @@ int kernel_attr_add(const struct target *target, const char *name, u32 mode,
|
||||
int res;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
if (target != NULL)
|
||||
if (target)
|
||||
info.tid = target->tid;
|
||||
info.cookie = cookie;
|
||||
|
||||
@@ -229,7 +229,7 @@ int kernel_attr_del(const struct target *target, const char *name, u32 cookie)
|
||||
int res;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
if (target != NULL)
|
||||
if (target)
|
||||
info.tid = target->tid;
|
||||
info.cookie = cookie;
|
||||
|
||||
@@ -298,7 +298,7 @@ int kernel_params_get(u32 tid, u64 sid, int type, struct iscsi_param *params)
|
||||
struct iscsi_kern_params_info info;
|
||||
|
||||
if (sid == 0) {
|
||||
log_error("kernel_params_get(): sid must be not %d", 0);
|
||||
log_error("%s(): sid must be not %d", __func__, 0);
|
||||
err = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -333,7 +333,7 @@ int kernel_params_set(u32 tid, u64 sid, int type, u32 partial,
|
||||
struct iscsi_kern_params_info info;
|
||||
|
||||
if (sid == 0) {
|
||||
log_error("kernel_params_set(): sid must be not %d", 0);
|
||||
log_error("%s(): sid must be not %d", __func__, 0);
|
||||
err = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -370,7 +370,7 @@ int kernel_session_create(struct connection *conn)
|
||||
struct target *target;
|
||||
|
||||
target = target_find_by_id(conn->tid);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target %d not found", conn->tid);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
|
||||
+61
-61
@@ -130,7 +130,7 @@ static int send_mgmt_cmd_res(u32 tid, u32 cookie, u32 req_cmd, int result,
|
||||
cinfo.req_cmd = req_cmd;
|
||||
cinfo.result = result;
|
||||
|
||||
if (res_str != NULL)
|
||||
if (res_str)
|
||||
iscsi_strscpy(cinfo.value, res_str, sizeof(cinfo.value));
|
||||
|
||||
log_debug(1, "Sending result %d (cookie %d)", result, cookie);
|
||||
@@ -163,7 +163,7 @@ static int handle_e_add_target(int fd, const struct iscsi_kern_event *event)
|
||||
1 + NLMSG_ALIGNTO - 1;
|
||||
|
||||
buf = malloc(size);
|
||||
if (buf == NULL) {
|
||||
if (!buf) {
|
||||
log_error("Unable to allocate tmp buffer (size %d)", size);
|
||||
res = -ENOMEM;
|
||||
goto out;
|
||||
@@ -174,7 +174,7 @@ static int handle_e_add_target(int fd, const struct iscsi_kern_event *event)
|
||||
while (1) {
|
||||
rc = nl_read(fd, &buf[offs], event->param1_size, true);
|
||||
if (rc < 0) {
|
||||
if ((errno == EINTR) || (errno == EAGAIN))
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue;
|
||||
log_error("read netlink fd (%d) failed: %s", fd,
|
||||
strerror(errno));
|
||||
@@ -191,7 +191,7 @@ static int handle_e_add_target(int fd, const struct iscsi_kern_event *event)
|
||||
while (1) {
|
||||
rc = nl_read(fd, &buf[offs], event->param2_size, true);
|
||||
if (rc < 0) {
|
||||
if ((errno == EINTR) || (errno == EAGAIN))
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue;
|
||||
log_error("read netlink fd (%d) failed: %s", fd,
|
||||
strerror(errno));
|
||||
@@ -254,24 +254,24 @@ static int __handle_add_attr(const struct target *target, struct __qelem *attrs_
|
||||
key = config_sep_string(&p);
|
||||
val = config_sep_string(&p);
|
||||
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", name);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((key == NULL) || (*key == '\0')) {
|
||||
if (!key || (*key == '\0')) {
|
||||
log_error("Value expected for attr %s", name);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (val != NULL)
|
||||
if (val)
|
||||
if (*val == '\0')
|
||||
val = NULL;
|
||||
|
||||
if (single_param_only) {
|
||||
if (val != NULL) {
|
||||
if (val) {
|
||||
log_error("Only one value expected for attr %s", key);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
@@ -327,7 +327,7 @@ static int handle_del_user(const struct target *target, int dir, char *p, u32 co
|
||||
|
||||
name = config_sep_string(&p);
|
||||
|
||||
res = config_account_del((target != NULL) ? target->tid : 0, dir,
|
||||
res = config_account_del((target) ? target->tid : 0, dir,
|
||||
name, cookie);
|
||||
|
||||
return res;
|
||||
@@ -342,14 +342,14 @@ static int __handle_del_attr(const struct target *target, struct __qelem *attrs_
|
||||
|
||||
key = config_sep_string(&p);
|
||||
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", p);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
attr = iscsi_attr_lookup_by_key(attrs_list, key);
|
||||
if (attr == NULL) {
|
||||
if (!attr) {
|
||||
log_error("Unknown portal %s", key);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
@@ -405,7 +405,7 @@ static int handle_e_mgmt_cmd(int fd, const struct iscsi_kern_event *event)
|
||||
size = NLMSG_ALIGN(event->param1_size + 1);
|
||||
|
||||
buf = malloc(size);
|
||||
if (buf == NULL) {
|
||||
if (!buf) {
|
||||
log_error("Unable to allocate tmp buffer (size %d)", size);
|
||||
res = -ENOMEM;
|
||||
goto out;
|
||||
@@ -414,7 +414,7 @@ static int handle_e_mgmt_cmd(int fd, const struct iscsi_kern_event *event)
|
||||
while (1) {
|
||||
rc = nl_read(fd, buf, event->param1_size, true);
|
||||
if (rc < 0) {
|
||||
if ((errno == EINTR) || (errno == EAGAIN))
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue;
|
||||
log_error("read netlink fd (%d) failed: %s", fd,
|
||||
strerror(errno));
|
||||
@@ -437,7 +437,7 @@ static int handle_e_mgmt_cmd(int fd, const struct iscsi_kern_event *event)
|
||||
|
||||
pp = config_sep_string(&p);
|
||||
target = target_find_by_name(pp);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target %s not found", pp);
|
||||
res = -ENOENT;
|
||||
goto out_free;
|
||||
@@ -450,7 +450,7 @@ static int handle_e_mgmt_cmd(int fd, const struct iscsi_kern_event *event)
|
||||
|
||||
pp = config_sep_string(&p);
|
||||
target = target_find_by_name(pp);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target %s not found", pp);
|
||||
res = -ENOENT;
|
||||
goto out_free;
|
||||
@@ -498,7 +498,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
size = NLMSG_ALIGN(event->param1_size + 1);
|
||||
|
||||
buf = malloc(size);
|
||||
if (buf == NULL) {
|
||||
if (!buf) {
|
||||
log_error("Unable to allocate tmp buffer (size %d)", size);
|
||||
res = -ENOMEM;
|
||||
goto out;
|
||||
@@ -507,7 +507,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
while (1) {
|
||||
rc = nl_read(fd, buf, event->param1_size, true);
|
||||
if (rc < 0) {
|
||||
if ((errno == EINTR) || (errno == EAGAIN))
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue;
|
||||
log_error("read netlink fd (%d) failed: %s", fd,
|
||||
strerror(errno));
|
||||
@@ -527,7 +527,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
pp = config_sep_string(&p);
|
||||
idx = params_index_by_name(pp, target_keys);
|
||||
if (idx >= 0) {
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -538,8 +538,8 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
|
||||
if (target->target_params[idx] != target_keys[idx].local_def)
|
||||
add_key_mark(res_str, sizeof(res_str), 1);
|
||||
} else if (!((idx = params_index_by_name(pp, session_keys)) < 0)) {
|
||||
if (target == NULL) {
|
||||
} else if ((idx = params_index_by_name(pp, session_keys)) >= 0) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -550,11 +550,11 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
|
||||
if (target->session_params[idx] != session_keys[idx].local_def)
|
||||
add_key_mark(res_str, sizeof(res_str), 1);
|
||||
} else if (!((idx = params_index_by_name_numwild(pp, user_keys)) < 0)) {
|
||||
} else if ((idx = params_index_by_name_numwild(pp, user_keys)) >= 0) {
|
||||
const struct iscsi_attr *user;
|
||||
|
||||
user = account_lookup_by_sysfs_name(target, idx, pp);
|
||||
if (user == NULL) {
|
||||
if (!user) {
|
||||
log_error("Unknown user attribute %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -566,14 +566,14 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
} else if (strncasecmp_numwild(ISCSI_ALLOWED_PORTAL_ATTR_NAME, pp) == 0) {
|
||||
const struct iscsi_attr *portal;
|
||||
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
portal = iscsi_attr_lookup_by_sysfs_name(&target->allowed_portals, pp);
|
||||
if (portal == NULL) {
|
||||
if (!portal) {
|
||||
log_error("Unknown portal attribute %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -582,7 +582,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
snprintf(res_str, sizeof(res_str), "%s\n", portal->attr_key);
|
||||
add_key_mark(res_str, sizeof(res_str), 0);
|
||||
} else if (strcasecmp(ISCSI_ENABLED_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
@@ -590,7 +590,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
}
|
||||
snprintf(res_str, sizeof(res_str), "%d\n", iscsi_enabled);
|
||||
} else if (strcasecmp(ISCSI_PER_PORTAL_ACL_ATTR_NAME, pp) == 0) {
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -599,7 +599,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
if (target->per_portal_acl)
|
||||
add_key_mark(res_str, sizeof(res_str), 0);
|
||||
} else if (strcasecmp(ISCSI_TARGET_REDIRECTION_ATTR_NAME, pp) == 0) {
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -618,7 +618,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
} else
|
||||
*res_str = '\0';
|
||||
} else if (strcasecmp(ISCSI_TARGET_ALIAS_ATTR_NAME, pp) == 0) {
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -629,21 +629,21 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
} else
|
||||
*res_str = '\0';
|
||||
} else if (strcasecmp(ISCSI_ISNS_SERVER_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (isns_server != NULL) {
|
||||
if (isns_server) {
|
||||
snprintf(res_str, sizeof(res_str), "%s %s\n", isns_server,
|
||||
isns_access_control ? ISCSI_ISNS_SYSFS_ACCESS_CONTROL_ENABLED : "");
|
||||
add_key_mark(res_str, sizeof(res_str), 0);
|
||||
} else
|
||||
snprintf(res_str, sizeof(res_str), "\n");
|
||||
} else if (strcasecmp(ISCSI_ISNS_ENTITY_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
@@ -651,7 +651,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
}
|
||||
snprintf(res_str, sizeof(res_str), "%s", isns_entity_target_name);
|
||||
} else if (strcasecmp(ISCSI_LINK_LOCAL_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
@@ -661,7 +661,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
if (send_targets_link_local != DEFAULT_SEND_TARGETS_LINK_LOCAL)
|
||||
add_key_mark(res_str, sizeof(res_str), 0);
|
||||
} else if (strcasecmp(ISCSI_INTERNAL_PORTAL_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
@@ -729,15 +729,15 @@ static int handle_target_redirect(struct target *target, char *p)
|
||||
}
|
||||
|
||||
t = strrchr(addr, ']');
|
||||
if (t != NULL)
|
||||
if (t)
|
||||
port = strchr(t, ':');
|
||||
else
|
||||
port = strrchr(addr, ':');
|
||||
if (port != NULL) {
|
||||
if (port) {
|
||||
*port = '\0';
|
||||
port++;
|
||||
port_num = strtol(port, (char **) NULL, 10);
|
||||
if ((port_num <= 0) || (errno == EINVAL)) {
|
||||
if (port_num <= 0 || errno == EINVAL) {
|
||||
log_error("Invalid port %s", port);
|
||||
res = -EINVAL;
|
||||
goto out;
|
||||
@@ -816,7 +816,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
NLMSG_ALIGNTO - 1;
|
||||
|
||||
buf = malloc(size);
|
||||
if (buf == NULL) {
|
||||
if (!buf) {
|
||||
log_error("Unable to allocate tmp buffer (size %d)", size);
|
||||
res = -ENOMEM;
|
||||
goto out;
|
||||
@@ -825,7 +825,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
while (1) {
|
||||
rc = nl_read(fd, buf, event->param1_size, true);
|
||||
if (rc < 0) {
|
||||
if ((errno == EINTR) || (errno == EAGAIN))
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue;
|
||||
log_error("read netlink fd (%d) failed: %s", fd,
|
||||
strerror(errno));
|
||||
@@ -841,7 +841,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
while (1) {
|
||||
rc = nl_read(fd, &buf[offs], event->param2_size, true);
|
||||
if (rc < 0) {
|
||||
if ((errno == EINTR) || (errno == EAGAIN))
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue;
|
||||
log_error("read netlink fd (%d) failed: %s", fd,
|
||||
strerror(errno));
|
||||
@@ -865,7 +865,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
struct iscsi_param params[target_key_last];
|
||||
struct session *session;
|
||||
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -902,8 +902,8 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
kernel_params_set(event->tid, session->sid.id64,
|
||||
key_target, 1 << idx, params);
|
||||
}
|
||||
} else if (!((idx = params_index_by_name(pp, session_keys)) < 0)) {
|
||||
if (target == NULL) {
|
||||
} else if ((idx = params_index_by_name(pp, session_keys)) >= 0) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -933,11 +933,11 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
}
|
||||
|
||||
target->session_params[idx] = val;
|
||||
} else if (!((idx = params_index_by_name_numwild(pp, user_keys)) < 0)) {
|
||||
} else if ((idx = params_index_by_name_numwild(pp, user_keys)) >= 0) {
|
||||
const struct iscsi_attr *user;
|
||||
|
||||
user = account_lookup_by_sysfs_name(target, idx, pp);
|
||||
if (user == NULL) {
|
||||
if (!user) {
|
||||
log_error("Unknown user attribute %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -949,14 +949,14 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
} else if (strncasecmp_numwild(ISCSI_ALLOWED_PORTAL_ATTR_NAME, pp) == 0) {
|
||||
const struct iscsi_attr *portal;
|
||||
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
portal = iscsi_attr_lookup_by_sysfs_name(&target->allowed_portals, pp);
|
||||
if (portal == NULL) {
|
||||
if (!portal) {
|
||||
log_error("Unknown portal attribute %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -966,7 +966,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
if (res != 0)
|
||||
goto out_free;
|
||||
} else if (strcasecmp(ISCSI_ENABLED_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
@@ -983,7 +983,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
goto out_free;
|
||||
}
|
||||
} else if (strcasecmp(ISCSI_PER_PORTAL_ACL_ATTR_NAME, pp) == 0) {
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -999,7 +999,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
goto out_free;
|
||||
}
|
||||
} else if (strcasecmp(ISCSI_TARGET_REDIRECTION_ATTR_NAME, pp) == 0) {
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -1010,7 +1010,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
} else if (strcasecmp(ISCSI_TARGET_ALIAS_ATTR_NAME, pp) == 0) {
|
||||
bool alias_changed = false;
|
||||
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target expected for attr %s", pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
@@ -1025,7 +1025,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
} else {
|
||||
char *newval = strdup(p);
|
||||
|
||||
if (newval == NULL) {
|
||||
if (!newval) {
|
||||
log_error("Unable to duplicate alias name %s", p);
|
||||
res = -ENOMEM;
|
||||
goto out_free;
|
||||
@@ -1050,14 +1050,14 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
}
|
||||
}
|
||||
} else if (strcasecmp(ISCSI_ISNS_SERVER_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (isns_server != NULL)
|
||||
if (isns_server)
|
||||
isns_exit();
|
||||
|
||||
pp = config_sep_string(&p);
|
||||
@@ -1067,7 +1067,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
|
||||
isns_access_control = 0;
|
||||
isns_server = strdup(pp);
|
||||
if (isns_server == NULL) {
|
||||
if (!isns_server) {
|
||||
log_error("Unable to duplicate iSNS server name %s", pp);
|
||||
res = -ENOMEM;
|
||||
goto out_free;
|
||||
@@ -1109,7 +1109,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
pp = config_sep_string(&p);
|
||||
iscsi_strscpy(isns_entity_target_name, pp, sizeof(isns_entity_target_name));
|
||||
} else if (strcasecmp(ISCSI_LINK_LOCAL_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
@@ -1126,7 +1126,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
goto out_free;
|
||||
}
|
||||
} else if (strcasecmp(ISCSI_INTERNAL_PORTAL_ATTR_NAME, pp) == 0) {
|
||||
if (target != NULL) {
|
||||
if (target) {
|
||||
log_error("Not NULL target %s for global attribute %s",
|
||||
target->name, pp);
|
||||
res = -EINVAL;
|
||||
@@ -1149,7 +1149,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
}
|
||||
|
||||
portal = strtok_r(portals, " ", &saveptr);
|
||||
while (portal != NULL) {
|
||||
while (portal) {
|
||||
if (!is_addr(portal)) {
|
||||
log_error("Invalid address supplied %s", portal);
|
||||
free(portals);
|
||||
@@ -1263,7 +1263,7 @@ retry:
|
||||
|
||||
case E_ENABLE_TARGET:
|
||||
target = target_find_by_id(event.tid);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target %d not found", event.tid);
|
||||
rc = -ENOENT;
|
||||
} else
|
||||
@@ -1277,7 +1277,7 @@ retry:
|
||||
|
||||
case E_DISABLE_TARGET:
|
||||
target = target_find_by_id(event.tid);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("Target %d not found", event.tid);
|
||||
rc = -ENOENT;
|
||||
} else
|
||||
@@ -1303,13 +1303,13 @@ retry:
|
||||
|
||||
case E_CONN_CLOSE:
|
||||
session = session_find_id(event.tid, event.sid);
|
||||
if (session == NULL) {
|
||||
if (!session) {
|
||||
log_error("Session %#" PRIx64 " not found", event.sid);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
conn = conn_find(session, event.cid);
|
||||
if (conn == NULL) {
|
||||
if (!conn) {
|
||||
log_error("Connection %x for session %#" PRIx64 " not "
|
||||
"found", event.cid, event.sid);
|
||||
goto retry;
|
||||
|
||||
@@ -118,7 +118,7 @@ static void create_listen_socket(struct pollfd *array)
|
||||
int rc;
|
||||
|
||||
server_address = server_addresses[k];
|
||||
if (k > 0 && server_address == NULL)
|
||||
if (k > 0 && !server_address)
|
||||
break;
|
||||
|
||||
if (i == LISTEN_MAX) {
|
||||
@@ -279,7 +279,7 @@ static void create_iser_listen_socket(struct pollfd *array)
|
||||
|
||||
server_address = server_addresses[k];
|
||||
|
||||
if (k > 0 && server_address == NULL)
|
||||
if (k > 0 && !server_address)
|
||||
break;
|
||||
|
||||
if (i == ISERT_MAX_PORTALS) {
|
||||
@@ -383,7 +383,7 @@ static void iser_accept(int fd)
|
||||
goto out_close;
|
||||
|
||||
conn->target_portal = strdup(target_portal);
|
||||
if (conn->target_portal == NULL) {
|
||||
if (!conn->target_portal) {
|
||||
log_error("Unable to duplicate target portal %s", target_portal);
|
||||
goto out_free;
|
||||
}
|
||||
@@ -502,7 +502,7 @@ static void accept_connection(int listen)
|
||||
goto out_close;
|
||||
|
||||
conn->target_portal = strdup(target_portal);
|
||||
if (conn->target_portal == NULL) {
|
||||
if (!conn->target_portal) {
|
||||
log_error("Unable to duplicate target portal %s", target_portal);
|
||||
goto out_free;
|
||||
}
|
||||
@@ -921,7 +921,7 @@ int main(int argc, char **argv)
|
||||
int i = 0;
|
||||
|
||||
server_address = strdup(optarg);
|
||||
if (server_address == NULL) {
|
||||
if (!server_address) {
|
||||
perror("strdup failed");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
+30
-30
@@ -283,10 +283,10 @@ static int login_check_reinstatement(struct connection *conn)
|
||||
* reinstatement, if necessary, will be done in the kernel.
|
||||
*/
|
||||
|
||||
sBUG_ON(conn->sess != NULL);
|
||||
sBUG_ON(conn->sess);
|
||||
|
||||
session = session_find_name(conn->tid, conn->initiator, req->sid);
|
||||
if (session != NULL) {
|
||||
if (session) {
|
||||
if (req->sid.id.tsih == 0) {
|
||||
/* Kernel will do session reinstatement */
|
||||
log_debug(1, "Session sid %#" PRIx64 " reinstatement "
|
||||
@@ -305,7 +305,7 @@ static int login_check_reinstatement(struct connection *conn)
|
||||
} else {
|
||||
const struct connection *c = conn_find(session, conn->cid);
|
||||
|
||||
if (c != NULL) {
|
||||
if (c) {
|
||||
/* Kernel will do connection reinstatement */
|
||||
log_debug(1, "Conn %x reinstatement "
|
||||
"detected (tid %d, sid %#" PRIx64
|
||||
@@ -356,7 +356,7 @@ static void text_scan_login(struct connection *conn)
|
||||
;
|
||||
else if (!strcmp(key, "AuthMethod"))
|
||||
;
|
||||
else if (!((idx = params_index_by_name(key, session_keys)) < 0)) {
|
||||
else if ((idx = params_index_by_name(key, session_keys)) >= 0) {
|
||||
unsigned int val;
|
||||
char buf[32];
|
||||
|
||||
@@ -490,7 +490,7 @@ static int init_conn_session_params(struct connection *conn)
|
||||
struct target *target;
|
||||
|
||||
target = target_find_by_id(conn->tid);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
log_error("target %d not found", conn->tid);
|
||||
res = -ENOENT;
|
||||
goto out;
|
||||
@@ -581,26 +581,26 @@ static bool valid_utf8_name_char(long ch)
|
||||
|
||||
/* C.2.1 ASCII control characters */
|
||||
if ((ch >= 0x0000 && ch <= 0x001F) || /* CONTROL CHARACTERS */
|
||||
(ch == 0x007F)) { /* DELETE */
|
||||
ch == 0x007F) { /* DELETE */
|
||||
log_error("Invalid UTF-8: %lX (ASCII control characters)", ch);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* C.2.2 Non-ASCII control characters */
|
||||
if ((ch >= 0x0080 && ch <= 0x009F) || /* CONTROL CHARACTERS */
|
||||
(ch == 0x06DD) || /* ARABIC END OF AYAH */
|
||||
(ch == 0x070F) || /* SYRIAC ABBREVIATION MARK */
|
||||
(ch == 0x180E) || /* MONGOLIAN VOWEL SEPARATOR */
|
||||
(ch == 0x200C) || /* ZERO WIDTH NON-JOINER */
|
||||
(ch == 0x200D) || /* ZERO WIDTH JOINER */
|
||||
(ch == 0x2028) || /* LINE SEPARATOR */
|
||||
(ch == 0x2029) || /* PARAGRAPH SEPARATOR */
|
||||
(ch == 0x2060) || /* WORD JOINER */
|
||||
(ch == 0x2061) || /* FUNCTION APPLICATION */
|
||||
(ch == 0x2062) || /* INVISIBLE TIMES */
|
||||
(ch == 0x2063) || /* INVISIBLE SEPARATOR */
|
||||
(ch >= 0x206A && (ch <= 0x206F)) || /* [CONTROL CHARACTERS] */
|
||||
(ch == 0xFEFF) || /* ZERO WIDTH NO-BREAK SPACE */
|
||||
ch == 0x06DD || /* ARABIC END OF AYAH */
|
||||
ch == 0x070F || /* SYRIAC ABBREVIATION MARK */
|
||||
ch == 0x180E || /* MONGOLIAN VOWEL SEPARATOR */
|
||||
ch == 0x200C || /* ZERO WIDTH NON-JOINER */
|
||||
ch == 0x200D || /* ZERO WIDTH JOINER */
|
||||
ch == 0x2028 || /* LINE SEPARATOR */
|
||||
ch == 0x2029 || /* PARAGRAPH SEPARATOR */
|
||||
ch == 0x2060 || /* WORD JOINER */
|
||||
ch == 0x2061 || /* FUNCTION APPLICATION */
|
||||
ch == 0x2062 || /* INVISIBLE TIMES */
|
||||
ch == 0x2063 || /* INVISIBLE SEPARATOR */
|
||||
(ch >= 0x206A && ch <= 0x206F) || /* [CONTROL CHARACTERS] */
|
||||
ch == 0xFEFF || /* ZERO WIDTH NO-BREAK SPACE */
|
||||
(ch >= 0xFFF9 && ch <= 0xFFFC) || /* [CONTROL CHARACTERS] */
|
||||
(ch >= 0x1D173 && ch <= 0x1D17A)) { /* [MUSICAL CONTROL CHARACTERS] */
|
||||
log_error("Invalid UTF-8: %lX (Non-ASCII control characters)", ch);
|
||||
@@ -645,11 +645,11 @@ static bool valid_utf8_name_char(long ch)
|
||||
}
|
||||
|
||||
/* C.6 Inappropriate for plain text */
|
||||
if ((ch == 0xFFF9) || /* INTERLINEAR ANNOTATION ANCHOR */
|
||||
(ch == 0xFFFA) || /* INTERLINEAR ANNOTATION SEPARATOR */
|
||||
(ch == 0xFFFB) || /* INTERLINEAR ANNOTATION TERMINATOR */
|
||||
(ch == 0xFFFC) || /* OBJECT REPLACEMENT CHARACTER */
|
||||
(ch == 0xFFFD)) { /* REPLACEMENT CHARACTER */
|
||||
if (ch == 0xFFF9 || /* INTERLINEAR ANNOTATION ANCHOR */
|
||||
ch == 0xFFFA || /* INTERLINEAR ANNOTATION SEPARATOR */
|
||||
ch == 0xFFFB || /* INTERLINEAR ANNOTATION TERMINATOR */
|
||||
ch == 0xFFFC || /* OBJECT REPLACEMENT CHARACTER */
|
||||
ch == 0xFFFD) { /* REPLACEMENT CHARACTER */
|
||||
log_error("Invalid UTF-8: %lX (Inappropriate for plain text)", ch);
|
||||
return false;
|
||||
}
|
||||
@@ -682,7 +682,7 @@ static bool valid_utf8_name_char(long ch)
|
||||
}
|
||||
|
||||
/* C.9 Tagging characters */
|
||||
if ((ch == 0xE0001) || /* LANGUAGE TAG */
|
||||
if (ch == 0xE0001 || /* LANGUAGE TAG */
|
||||
(ch >= 0xE0020 && ch <= 0xE007F)) { /* [TAGGING CHARACTERS] */
|
||||
log_error("Invalid UTF-8: %lX (Tagging characters)", ch);
|
||||
return false;
|
||||
@@ -810,7 +810,7 @@ static void login_start(struct connection *conn)
|
||||
}
|
||||
|
||||
conn->initiator = strdup(name);
|
||||
if (conn->initiator == NULL) {
|
||||
if (!conn->initiator) {
|
||||
log_error("Unable to duplicate initiator's name %s", name);
|
||||
login_rsp_tgt_err(conn, ISCSI_STATUS_NO_RESOURCES);
|
||||
return;
|
||||
@@ -854,7 +854,7 @@ static void login_start(struct connection *conn)
|
||||
}
|
||||
|
||||
target = target_find_by_name(target_name);
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
login_rsp_ini_err(conn, ISCSI_STATUS_TGT_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
@@ -920,8 +920,8 @@ static void login_start(struct connection *conn)
|
||||
target->sessions_count++;
|
||||
conn->sessions_count_incremented = 1;
|
||||
} else if (rc != ISCSI_CONN_REINSTATEMENT) {
|
||||
if ((target->target_params[key_max_sessions] == 0) ||
|
||||
(target->sessions_count < target->target_params[key_max_sessions])) {
|
||||
if (target->target_params[key_max_sessions] == 0 ||
|
||||
target->sessions_count < target->target_params[key_max_sessions]) {
|
||||
target->sessions_count++;
|
||||
conn->sessions_count_incremented = 1;
|
||||
} else {
|
||||
@@ -1036,7 +1036,7 @@ static bool on_internal_portal(const struct connection *conn)
|
||||
char *saveptr;
|
||||
const char *portal = strtok_r(portals, " ", &saveptr);
|
||||
|
||||
while (portal != NULL) {
|
||||
while (portal) {
|
||||
if (!strcmp(portal, conn->target_portal)) {
|
||||
free(portals);
|
||||
return true;
|
||||
|
||||
@@ -73,7 +73,7 @@ int isns_scn_access_allowed(uint32_t tid, const char *name)
|
||||
struct isns_initiator *ini;
|
||||
struct target *target = target_find_by_id(tid);
|
||||
|
||||
if ((isns_server == NULL) || !isns_access_control)
|
||||
if (!isns_server || !isns_access_control)
|
||||
return 1;
|
||||
|
||||
if (!target)
|
||||
@@ -486,7 +486,7 @@ int isns_target_register(const char *name)
|
||||
int err, initial = list_length_is_one(&targets_list);
|
||||
int max_buf;
|
||||
|
||||
if (isns_server == NULL)
|
||||
if (!isns_server)
|
||||
return 0;
|
||||
|
||||
if (!isns_fd) {
|
||||
@@ -625,7 +625,7 @@ int isns_target_deregister(const char *name)
|
||||
if (target)
|
||||
free_all_acl(target);
|
||||
|
||||
if (isns_server == NULL)
|
||||
if (!isns_server)
|
||||
return 0;
|
||||
|
||||
if (!isns_fd) {
|
||||
@@ -909,7 +909,7 @@ found:
|
||||
name = (char *)tlv->value;
|
||||
break;
|
||||
case ISNS_ATTR_ISCSI_NODE_TYPE:
|
||||
if (ntohl(*(tlv->value)) == ISNS_NODE_INITIATOR && name) {
|
||||
if (ntohl(*tlv->value) == ISNS_NODE_INITIATOR && name) {
|
||||
log_debug(3, "%s %d: %s", __func__, __LINE__,
|
||||
(char *)name);
|
||||
ini = malloc(sizeof(*ini));
|
||||
@@ -943,7 +943,7 @@ int isns_handle(int is_timeout)
|
||||
uint16_t function;
|
||||
char *name = NULL;
|
||||
|
||||
if (isns_server == NULL)
|
||||
if (!isns_server)
|
||||
return 0;
|
||||
|
||||
if (is_timeout)
|
||||
@@ -997,7 +997,7 @@ static int scn_accept_connection(void)
|
||||
socklen_t slen;
|
||||
int fd, err, opt = 1;
|
||||
|
||||
if (isns_server == NULL) {
|
||||
if (!isns_server) {
|
||||
/*
|
||||
* Sometimes we have (leftover?) events after disable iSNS
|
||||
* server, so ignore them
|
||||
@@ -1214,7 +1214,7 @@ void isns_exit(void)
|
||||
{
|
||||
struct target *target;
|
||||
|
||||
if (isns_server == NULL)
|
||||
if (!isns_server)
|
||||
goto out;
|
||||
|
||||
if (!isns_fd)
|
||||
|
||||
@@ -109,7 +109,7 @@ static bool session_id_exists(u32 tid, u64 sid, const struct session *exclude)
|
||||
log_debug(1, "Searching for sid %#" PRIx64, sid);
|
||||
|
||||
list_for_each_entry(session, &target->sessions_list, slist) {
|
||||
if ((session->sid.id64 == sid) && (session != exclude))
|
||||
if (session->sid.id64 == sid && session != exclude)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ int session_create(struct connection *conn)
|
||||
conn->sess = session;
|
||||
|
||||
conn->sess->initiator = strdup(conn->initiator);
|
||||
if (conn->sess->initiator == NULL) {
|
||||
if (!conn->sess->initiator) {
|
||||
res = -errno;
|
||||
log_error("strdup() failed: %d", res);
|
||||
goto out_free;
|
||||
|
||||
@@ -67,7 +67,7 @@ static int __wildcmp(const char *wild, const char *string, int recursion_level)
|
||||
const char *cp = NULL, *mp = NULL;
|
||||
|
||||
while ((*string) && (*wild != '*')) {
|
||||
if ((*wild == '!') && (recursion_level == 0))
|
||||
if ((*wild == '!') && recursion_level == 0)
|
||||
return !__wildcmp(++wild, string, ++recursion_level);
|
||||
|
||||
if ((tolower(*wild) != tolower(*string)) && (*wild != '?'))
|
||||
@@ -78,7 +78,7 @@ static int __wildcmp(const char *wild, const char *string, int recursion_level)
|
||||
}
|
||||
|
||||
while (*string) {
|
||||
if ((*wild == '!') && (recursion_level == 0))
|
||||
if ((*wild == '!') && recursion_level == 0)
|
||||
return !__wildcmp(++wild, string, ++recursion_level);
|
||||
|
||||
if (*wild == '*') {
|
||||
@@ -233,7 +233,7 @@ static void target_list_build_ifaddrs(struct connection *conn,
|
||||
int sa_family = ifa->ifa_addr->sa_family;
|
||||
|
||||
if (sa_family == family) {
|
||||
if (getnameinfo(ifa->ifa_addr, (family == AF_INET) ?
|
||||
if (getnameinfo(ifa->ifa_addr, family == AF_INET ?
|
||||
sizeof(struct sockaddr_in) :
|
||||
sizeof(struct sockaddr_in6),
|
||||
if_addr, sizeof(if_addr),
|
||||
@@ -411,13 +411,13 @@ int target_create(const char *name, struct target **out_target)
|
||||
int res = 0;
|
||||
struct target *target;
|
||||
|
||||
if (name == NULL) {
|
||||
if (!name) {
|
||||
res = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
target = malloc(sizeof(*target));
|
||||
if (target == NULL) {
|
||||
if (!target) {
|
||||
res = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#define cpu_to_be32(x) bswap_32(x)
|
||||
#define be32_to_cpu(x) bswap_32(x)
|
||||
#else
|
||||
#error "unknown endianess!"
|
||||
#error "unknown endianness!"
|
||||
#endif
|
||||
|
||||
typedef u_int8_t u8;
|
||||
|
||||
@@ -114,8 +114,8 @@ size_t qlt_del_vtarget(u64 port_name)
|
||||
spin_lock_irqsave(shost->host_lock, flags);
|
||||
/* We only allow support on Channel 0 !!! */
|
||||
list_for_each_entry(vport, &fc_host->vports, peers) {
|
||||
if ((vport->channel == 0) &&
|
||||
(vport->port_name == port_name)) {
|
||||
if (vport->channel == 0 &&
|
||||
vport->port_name == port_name) {
|
||||
match = 1;
|
||||
dev_info(&vha->hw->pdev->dev,
|
||||
"%s: port_name %llx\n",
|
||||
|
||||
@@ -353,7 +353,7 @@ static inline void qla_tgt_set_cmd_prot_op(struct qla_tgt_cmd *cmd,
|
||||
return;
|
||||
}
|
||||
|
||||
if (scst_cmd->status && (dir == SCST_DATA_NONE)) {
|
||||
if (scst_cmd->status && dir == SCST_DATA_NONE) {
|
||||
/* scst_set_cmd_error() will over ride the data direction
|
||||
* in the error case at the back end. Need to figure out
|
||||
* the
|
||||
@@ -562,7 +562,7 @@ static int sqa_qla2xxx_handle_cmd(scsi_qla_host_t *vha,
|
||||
cmd->cdb_len,
|
||||
SCST_ATOMIC);
|
||||
|
||||
if (cmd->scst_cmd == NULL) {
|
||||
if (!cmd->scst_cmd) {
|
||||
PRINT_ERROR("sqatgt(%ld/%d): scst_rx_cmd function failed.",
|
||||
vha->host_no, vha->vp_idx);
|
||||
res = -EFAULT;
|
||||
@@ -920,7 +920,7 @@ static int sqa_qla2xxx_check_initiator_node_acl(scsi_qla_host_t *vha,
|
||||
res = -ESRCH;
|
||||
scst_sess = scst_register_session(sqa_tgt->scst_tgt, 0,
|
||||
ini_name, fcport, NULL, NULL);
|
||||
if (scst_sess == NULL) {
|
||||
if (!scst_sess) {
|
||||
PRINT_ERROR("sqatgt(%ld/%d): SCST session registration failed, all commands will be refused: pwwn=%s",
|
||||
vha->host_no, vha->vp_idx, ini_name);
|
||||
goto free_sess;
|
||||
@@ -1360,7 +1360,7 @@ static int sqa_parse_wwn(const char *ns, u64 *nm)
|
||||
if (i % 2) {
|
||||
wwn[i/2] = j & 0xff;
|
||||
j = 0;
|
||||
if ((i < 15) && (':' != *ns++))
|
||||
if (i < 15 && (':' != *ns++))
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -1700,7 +1700,7 @@ static int sqa_xmit_response(struct scst_cmd *scst_cmd)
|
||||
scst_cmd->cdb_buf[0], cmd->prot_sg, cmd->prot_sg_cnt,
|
||||
cmd->se_cmd.prot_type, cmd->se_cmd.prot_op);
|
||||
|
||||
if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) &&
|
||||
if (cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT &&
|
||||
(!cmd->prot_sg_cnt || !cmd->prot_sg)) {
|
||||
PRINT_ERROR("qla2x00t(%ld): %s: DIN Insert w/out DIF buf[%p:%d]",
|
||||
cmd->vha->host_no, __func__, cmd->prot_sg,
|
||||
@@ -1875,7 +1875,7 @@ static void sqa_task_mgmt_fn_done(struct scst_mgmt_cmd *scst_mcmd)
|
||||
TRACE_ENTRY();
|
||||
|
||||
mcmd = scst_mgmt_cmd_get_tgt_priv(scst_mcmd);
|
||||
if (unlikely(mcmd == NULL)) {
|
||||
if (unlikely(!mcmd)) {
|
||||
PRINT_ERROR("sqatgt: Null target pointer for SCST task management, command=%p",
|
||||
scst_mcmd);
|
||||
goto out;
|
||||
@@ -1909,13 +1909,13 @@ static int sqa_get_initiator_port_transport_id(struct scst_tgt *tgt,
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
if (scst_sess == NULL) {
|
||||
if (!scst_sess) {
|
||||
res = SCSI_TRANSPORTID_PROTOCOLID_FCP2;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sess = scst_sess_get_tgt_priv(scst_sess);
|
||||
if (sess == NULL) {
|
||||
if (!sess) {
|
||||
res = SCSI_TRANSPORTID_PROTOCOLID_FCP2;
|
||||
goto out;
|
||||
}
|
||||
@@ -1926,7 +1926,7 @@ static int sqa_get_initiator_port_transport_id(struct scst_tgt *tgt,
|
||||
|
||||
tr_id_size = 24;
|
||||
tr_id = kzalloc(tr_id_size, GFP_KERNEL);
|
||||
if (tr_id == NULL) {
|
||||
if (!tr_id) {
|
||||
PRINT_ERROR("sqatgt(%ld/%d): Allocation of TransportID size=%d failed.",
|
||||
sess->vha->host_no, sess->vha->vp_idx, tr_id_size);
|
||||
res = -ENOMEM;
|
||||
@@ -2300,7 +2300,7 @@ static ssize_t sqa_add_vtarget(const char *target_name, char *params)
|
||||
|
||||
while (1) {
|
||||
param = scst_get_next_token_str(¶ms);
|
||||
if (param == NULL)
|
||||
if (!param)
|
||||
break;
|
||||
|
||||
p = scst_get_next_lexem(¶m);
|
||||
|
||||
+4
-4
@@ -426,8 +426,8 @@ static int scst_copy_from_dlm(struct scst_device *dev, dlm_lockspace_t *ls,
|
||||
}
|
||||
|
||||
/* Does the registrant have UAs that need to be delivered here? */
|
||||
if (unlikely((reg->registered_by_nodeid == pr_dlm->local_nodeid) &&
|
||||
(reg->next_rem_ua_idx))) {
|
||||
if (unlikely(reg->registered_by_nodeid == pr_dlm->local_nodeid &&
|
||||
reg->next_rem_ua_idx)) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < reg->next_rem_ua_idx; j++) {
|
||||
@@ -1683,7 +1683,7 @@ static struct scst_dlm_rem_ua *scst_dlm_alloc_rem_ua(void)
|
||||
struct scst_dlm_rem_ua *ua = NULL;
|
||||
|
||||
ua = kzalloc_obj(struct scst_dlm_rem_ua);
|
||||
if (ua == NULL) {
|
||||
if (!ua) {
|
||||
PRINT_ERROR("Unable to allocate unit attention");
|
||||
goto out;
|
||||
}
|
||||
@@ -1716,7 +1716,7 @@ static void scst_dlm_pr_reg_queue_rem_ua(struct scst_device *dev,
|
||||
TRACE_ENTRY();
|
||||
|
||||
ua = scst_dlm_alloc_rem_ua();
|
||||
if (ua == NULL) {
|
||||
if (!ua) {
|
||||
PRINT_ERROR("Unable to allocate unit attention for dlm registrant");
|
||||
return;
|
||||
}
|
||||
|
||||
+222
-222
File diff suppressed because it is too large
Load Diff
@@ -84,14 +84,14 @@ static void scst_no_dlm_res_unlock(struct scst_device *dev,
|
||||
static bool scst_no_dlm_is_rsv_holder(struct scst_device *dev,
|
||||
struct scst_session *sess)
|
||||
{
|
||||
EXTRACHECKS_BUG_ON(sess == NULL);
|
||||
EXTRACHECKS_BUG_ON(!sess);
|
||||
return dev->reserved_by == sess;
|
||||
}
|
||||
|
||||
static bool scst_no_dlm_is_not_rsv_holder(struct scst_device *dev,
|
||||
struct scst_session *sess)
|
||||
{
|
||||
EXTRACHECKS_BUG_ON(sess == NULL);
|
||||
EXTRACHECKS_BUG_ON(!sess);
|
||||
return dev->reserved_by && dev->reserved_by != sess;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (allowed_events_num == 0) {
|
||||
if ((allowed_events[0].event_code == 0) &&
|
||||
if (allowed_events[0].event_code == 0 &&
|
||||
(allowed_events[0].issuer_name[0] == '\0'))
|
||||
allowed_events[0].issuer_name[0] = '*';
|
||||
}
|
||||
|
||||
+30
-30
@@ -75,7 +75,7 @@ static void set_resp_data_len(struct vdisk_cmd *vcmd, int32_t resp_data_len)
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
if (vcmd->may_need_to_free_pbuf && (resp_data_len == 0)) {
|
||||
if (vcmd->may_need_to_free_pbuf && resp_data_len == 0) {
|
||||
struct scst_user_scsi_cmd_exec *cmd = &vcmd->cmd->exec_cmd;
|
||||
free((void *)(unsigned long)cmd->pbuf);
|
||||
cmd->pbuf = 0;
|
||||
@@ -267,7 +267,7 @@ static int do_exec(struct vdisk_cmd *vcmd)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((cmd->pbuf == 0) && (cmd->alloc_len != 0)) {
|
||||
if (cmd->pbuf == 0 && cmd->alloc_len != 0) {
|
||||
#ifdef DEBUG_NOMEM
|
||||
if ((random() % 100) == 75)
|
||||
cmd->pbuf = 0;
|
||||
@@ -295,7 +295,7 @@ static int do_exec(struct vdisk_cmd *vcmd)
|
||||
TRACE_DBG("cmd %d, buf %"PRIx64", lba_start %"PRId64", loff %"PRId64
|
||||
", data_len %"PRId64, vcmd->cmd->cmd_h, cmd->pbuf, lba_start,
|
||||
(uint64_t)loff, data_len);
|
||||
if ((loff < 0) || (data_len < 0) || ((loff + data_len) > dev->file_size)) {
|
||||
if (loff < 0 || data_len < 0 || ((loff + data_len) > dev->file_size)) {
|
||||
PRINT_INFO("Access beyond the end of the device "
|
||||
"(%"PRId64" of %"PRId64", len %"PRId64")", (uint64_t)loff,
|
||||
(uint64_t)dev->file_size, data_len);
|
||||
@@ -332,7 +332,7 @@ static int do_exec(struct vdisk_cmd *vcmd)
|
||||
const struct vdisk_tgt_dev *tgt_dev;
|
||||
|
||||
tgt_dev = find_tgt_dev(dev, cmd->sess_h);
|
||||
if (tgt_dev == NULL) {
|
||||
if (!tgt_dev) {
|
||||
PRINT_ERROR("Session %"PRIx64" not found",
|
||||
cmd->sess_h);
|
||||
set_cmd_error(vcmd,
|
||||
@@ -358,7 +358,7 @@ static int do_exec(struct vdisk_cmd *vcmd)
|
||||
const struct vdisk_tgt_dev *tgt_dev;
|
||||
|
||||
tgt_dev = find_tgt_dev(dev, cmd->sess_h);
|
||||
if (tgt_dev == NULL) {
|
||||
if (!tgt_dev) {
|
||||
PRINT_ERROR("Session %"PRIx64" not found",
|
||||
cmd->sess_h);
|
||||
set_cmd_error(vcmd,
|
||||
@@ -530,7 +530,7 @@ static int do_on_free_cmd(struct vdisk_cmd *vcmd)
|
||||
cmd->cmd_h, cmd->on_free_cmd.pbuf,
|
||||
cmd->on_free_cmd.buffer_cached);
|
||||
|
||||
if (!cmd->on_free_cmd.buffer_cached && (cmd->on_free_cmd.pbuf != 0)) {
|
||||
if (!cmd->on_free_cmd.buffer_cached && cmd->on_free_cmd.pbuf != 0) {
|
||||
TRACE_MEM("Freeing buf %"PRIx64, cmd->on_free_cmd.pbuf);
|
||||
free((void *)(unsigned long)cmd->on_free_cmd.pbuf);
|
||||
}
|
||||
@@ -644,7 +644,7 @@ static int do_sess(struct vdisk_cmd *vcmd)
|
||||
tgt_dev = find_tgt_dev(vcmd->dev, cmd->sess.sess_h);
|
||||
|
||||
if (cmd->subcode == SCST_USER_ATTACH_SESS) {
|
||||
if (tgt_dev != NULL) {
|
||||
if (tgt_dev) {
|
||||
PRINT_ERROR("Session %"PRIx64" already exists)",
|
||||
cmd->sess.sess_h);
|
||||
res = EEXIST;
|
||||
@@ -652,7 +652,7 @@ static int do_sess(struct vdisk_cmd *vcmd)
|
||||
}
|
||||
|
||||
tgt_dev = find_empty_tgt_dev(vcmd->dev);
|
||||
if (tgt_dev == NULL) {
|
||||
if (!tgt_dev) {
|
||||
PRINT_ERROR("Too many initiators, session %"PRIx64
|
||||
" refused)", cmd->sess.sess_h);
|
||||
res = ENOMEM;
|
||||
@@ -668,7 +668,7 @@ static int do_sess(struct vdisk_cmd *vcmd)
|
||||
cmd->sess.threads_num, cmd->sess.rd_only,
|
||||
cmd->sess.sess_h);
|
||||
} else {
|
||||
if (tgt_dev == NULL) {
|
||||
if (!tgt_dev) {
|
||||
PRINT_ERROR("Session %"PRIx64" not found)",
|
||||
cmd->sess.sess_h);
|
||||
res = ESRCH;
|
||||
@@ -707,7 +707,7 @@ static int process_cmd(struct vdisk_cmd *vcmd)
|
||||
cmd->exec_cmd.bufflen);
|
||||
}
|
||||
res = do_exec(vcmd);
|
||||
if ((reply->exec_reply.resp_data_len != 0) && (res != 150)) {
|
||||
if (reply->exec_reply.resp_data_len != 0 && res != 150) {
|
||||
TRACE_BUFFER("Reply data",
|
||||
(void *)(unsigned long)reply->exec_reply.pbuf,
|
||||
reply->exec_reply.resp_data_len);
|
||||
@@ -989,7 +989,7 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
|
||||
if (cmd->cdb[1] & EVPD) {
|
||||
uint64_t dev_id_num = gen_dev_id_num(dev);
|
||||
|
||||
if (0 == cmd->cdb[2]) { /* supported vital product data pages */
|
||||
if (cmd->cdb[2] == 0) { /* supported vital product data pages */
|
||||
buf[3] = 5;
|
||||
buf[4] = 0x0; /* this page */
|
||||
buf[5] = 0x80; /* unit serial number */
|
||||
@@ -997,7 +997,7 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
|
||||
buf[7] = 0xB0; /* block limits */
|
||||
buf[8] = 0xB1; /* block device characteristics */
|
||||
resp_len = buf[3] + 6;
|
||||
} else if (0x80 == cmd->cdb[2]) { /* unit serial number */
|
||||
} else if (cmd->cdb[2] == 0x80) { /* unit serial number */
|
||||
unsigned int usn_len = strlen(dev->usn);
|
||||
|
||||
buf[1] = 0x80;
|
||||
@@ -1005,7 +1005,7 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
|
||||
assert(4 + usn_len <= sizeof(buf));
|
||||
memcpy(&buf[4], dev->usn, usn_len);
|
||||
resp_len = buf[3] + 4;
|
||||
} else if (0x83 == cmd->cdb[2]) { /* device identification */
|
||||
} else if (cmd->cdb[2] == 0x83) { /* device identification */
|
||||
int num = 4;
|
||||
char *t10_id = (char *)&buf[num + 12];
|
||||
|
||||
@@ -1045,7 +1045,7 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
|
||||
buf[2] = (resp_len >> 8) & 0xFF;
|
||||
buf[3] = resp_len & 0xFF;
|
||||
resp_len += 4;
|
||||
} else if (0xB0 == cmd->cdb[2]) {
|
||||
} else if (cmd->cdb[2] == 0xB0) {
|
||||
/* Block Limits */
|
||||
int max_transfer;
|
||||
buf[1] = 0xB0;
|
||||
@@ -1077,7 +1077,7 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
|
||||
buf[14] = (max_transfer >> 8) & 0xff;
|
||||
buf[15] = max_transfer & 0xff;
|
||||
resp_len = buf[3] + 4;
|
||||
} else if (0xB1 == cmd->cdb[2]) {
|
||||
} else if (cmd->cdb[2] == 0xB1) {
|
||||
int r;
|
||||
/* Block Device Characteristics */
|
||||
buf[1] = 0xB1;
|
||||
@@ -1179,7 +1179,7 @@ static int err_recov_pg(unsigned char *p, int pcontrol)
|
||||
5, 0, 0xff, 0xff};
|
||||
|
||||
memcpy(p, err_recov_pg, sizeof(err_recov_pg));
|
||||
if (1 == pcontrol)
|
||||
if (pcontrol == 1)
|
||||
memset(p + 2, 0, sizeof(err_recov_pg) - 2);
|
||||
return sizeof(err_recov_pg);
|
||||
}
|
||||
@@ -1190,7 +1190,7 @@ static int disconnect_pg(unsigned char *p, int pcontrol)
|
||||
0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
memcpy(p, disconnect_pg, sizeof(disconnect_pg));
|
||||
if (1 == pcontrol)
|
||||
if (pcontrol == 1)
|
||||
memset(p + 2, 0, sizeof(disconnect_pg) - 2);
|
||||
return sizeof(disconnect_pg);
|
||||
}
|
||||
@@ -1210,7 +1210,7 @@ static int rigid_geo_pg(unsigned char *p, int pcontrol,
|
||||
memcpy(&n, p + 2, sizeof(uint32_t));
|
||||
n = n | (htonl(ncyl) >> 8);
|
||||
memcpy(p + 2, &n, sizeof(uint32_t));
|
||||
if (1 == pcontrol)
|
||||
if (pcontrol == 1)
|
||||
memset(p + 2, 0, sizeof(geo_m_pg) - 2);
|
||||
return sizeof(geo_m_pg);
|
||||
}
|
||||
@@ -1227,7 +1227,7 @@ static int format_pg(unsigned char *p, int pcontrol,
|
||||
p[11] = DEF_SECTORS & 0xff;
|
||||
p[12] = (dev->block_size >> 8) & 0xff;
|
||||
p[13] = dev->block_size & 0xff;
|
||||
if (1 == pcontrol)
|
||||
if (pcontrol == 1)
|
||||
memset(p + 2, 0, sizeof(format_pg) - 2);
|
||||
return sizeof(format_pg);
|
||||
}
|
||||
@@ -1240,7 +1240,7 @@ static int caching_pg(unsigned char *p, int pcontrol,
|
||||
|
||||
memcpy(p, caching_pg, sizeof(caching_pg));
|
||||
p[2] |= !(dev->wt_flag) ? WCE : 0;
|
||||
if (1 == pcontrol)
|
||||
if (pcontrol == 1)
|
||||
memset(p + 2, 0, sizeof(caching_pg) - 2);
|
||||
return sizeof(caching_pg);
|
||||
}
|
||||
@@ -1254,7 +1254,7 @@ static int ctrl_m_pg(unsigned char *p, int pcontrol,
|
||||
memcpy(p, ctrl_m_pg, sizeof(ctrl_m_pg));
|
||||
if (!dev->wt_flag && !dev->nv_cache)
|
||||
p[3] |= 0x10; /* Enable unrestricted reordering */
|
||||
if (1 == pcontrol)
|
||||
if (pcontrol == 1)
|
||||
memset(p + 2, 0, sizeof(ctrl_m_pg) - 2);
|
||||
return sizeof(ctrl_m_pg);
|
||||
}
|
||||
@@ -1264,7 +1264,7 @@ static int iec_m_pg(unsigned char *p, int pcontrol)
|
||||
const unsigned char iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
|
||||
0, 0, 0x0, 0x0};
|
||||
memcpy(p, iec_m_pg, sizeof(iec_m_pg));
|
||||
if (1 == pcontrol)
|
||||
if (pcontrol == 1)
|
||||
memset(p + 2, 0, sizeof(iec_m_pg) - 2);
|
||||
return sizeof(iec_m_pg);
|
||||
}
|
||||
@@ -1295,12 +1295,12 @@ static void exec_mode_sense(struct vdisk_cmd *vcmd)
|
||||
pcontrol = (cmd->cdb[2] & 0xc0) >> 6;
|
||||
pcode = cmd->cdb[2] & 0x3f;
|
||||
subpcode = cmd->cdb[3];
|
||||
msense_6 = (MODE_SENSE == cmd->cdb[0]);
|
||||
msense_6 = (cmd->cdb[0] == MODE_SENSE);
|
||||
dev_spec = (dev->rd_only_flag ? WP : 0) | DPOFUA;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (0x3 == pcontrol) {
|
||||
if (pcontrol == 0x3) {
|
||||
TRACE_DBG("%s", "MODE SENSE: Saving values not supported");
|
||||
set_cmd_error(vcmd,
|
||||
SCST_LOAD_SENSE(scst_sense_saving_params_unsup));
|
||||
@@ -1317,7 +1317,7 @@ static void exec_mode_sense(struct vdisk_cmd *vcmd)
|
||||
offset = 8;
|
||||
}
|
||||
|
||||
if (0 != subpcode) { /* TODO: Control Extension page */
|
||||
if (subpcode != 0) { /* TODO: Control Extension page */
|
||||
TRACE_DBG("%s", "MODE SENSE: Only subpage 0 is supported");
|
||||
set_cmd_error(vcmd,
|
||||
SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb));
|
||||
@@ -1415,7 +1415,7 @@ static int set_wt(struct vdisk_dev *dev, int wt)
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
if ((dev->wt_flag == wt) || dev->nullio)
|
||||
if (dev->wt_flag == wt || dev->nullio)
|
||||
goto out;
|
||||
|
||||
pthread_mutex_lock(&dev->dev_mutex);
|
||||
@@ -1437,7 +1437,7 @@ static void exec_mode_select(struct vdisk_cmd *vcmd)
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
mselect_6 = (MODE_SELECT == cmd->cdb[0]);
|
||||
mselect_6 = (cmd->cdb[0] == MODE_SELECT);
|
||||
|
||||
if (!(cmd->cdb[1] & PF) || (cmd->cdb[1] & SP)) {
|
||||
PRINT_ERROR("MODE SELECT: PF and/or SP are wrongly set "
|
||||
@@ -1738,7 +1738,7 @@ static void exec_read(struct vdisk_cmd *vcmd, loff_t loff)
|
||||
err = read(fd, address, length);
|
||||
}
|
||||
|
||||
if ((err < 0) || (err < length)) {
|
||||
if (err < 0 || err < length) {
|
||||
PRINT_ERROR("read() returned %"PRId64" from %d (errno %d)",
|
||||
(uint64_t)err, length, errno);
|
||||
if (err == -EAGAIN)
|
||||
@@ -1854,7 +1854,7 @@ static void exec_verify(struct vdisk_cmd *vcmd, loff_t loff)
|
||||
}
|
||||
}
|
||||
|
||||
if ((length == 0) && (cmd->data_len != 0)) {
|
||||
if (length == 0 && cmd->data_len != 0) {
|
||||
length = cmd->data_len;
|
||||
compare = 0;
|
||||
} else
|
||||
@@ -1870,7 +1870,7 @@ static void exec_verify(struct vdisk_cmd *vcmd, loff_t loff)
|
||||
err = read(fd, (char *)mem_verify, len_mem);
|
||||
else
|
||||
err = len_mem;
|
||||
if ((err < 0) || (err < len_mem)) {
|
||||
if (err < 0 || err < len_mem) {
|
||||
PRINT_ERROR("read() returned %"PRId64" from %"PRId64" "
|
||||
"(errno %d)", (uint64_t)err, len_mem, errno);
|
||||
if (err == -EAGAIN)
|
||||
|
||||
+5
-5
@@ -411,7 +411,7 @@ static int start(int argc, char **argv)
|
||||
goto out_unreg;
|
||||
}
|
||||
|
||||
if ((prealloc_buffers_num > 0) && (prealloc_buffer_size > 0)) {
|
||||
if (prealloc_buffers_num > 0 && prealloc_buffer_size > 0) {
|
||||
res = prealloc_buffers(&devs[i]);
|
||||
if (res != 0)
|
||||
goto out_unreg;
|
||||
@@ -475,7 +475,7 @@ static int start(int argc, char **argv)
|
||||
res = errno;
|
||||
PRINT_ERROR("pthread_join() failed: %s",
|
||||
strerror(res));
|
||||
} else if (rc1 != NULL) {
|
||||
} else if (rc1) {
|
||||
res = (long)rc1;
|
||||
PRINT_INFO("Thread %d exited (dev %s), res %lx", j,
|
||||
devs[i].name, (long)rc1);
|
||||
@@ -643,7 +643,7 @@ int main(int argc, char **argv)
|
||||
goto out_usage;
|
||||
|
||||
if (!on_free_cmd_type_set &&
|
||||
(memory_reuse_type != SCST_USER_MEM_REUSE_ALL))
|
||||
memory_reuse_type != SCST_USER_MEM_REUSE_ALL)
|
||||
on_free_cmd_type = SCST_USER_ON_FREE_CMD_CALL;
|
||||
|
||||
PRINT_INFO("%s", "Options:");
|
||||
@@ -721,11 +721,11 @@ int main(int argc, char **argv)
|
||||
if (sgv_disable_clustered_pool)
|
||||
PRINT_INFO(" %s", "Disable clustered SGV pool");
|
||||
|
||||
if ((prealloc_buffers_num > 0) && (prealloc_buffer_size > 0))
|
||||
if (prealloc_buffers_num > 0 && prealloc_buffer_size > 0)
|
||||
PRINT_INFO(" Prealloc %d buffers of %dKB",
|
||||
prealloc_buffers_num, prealloc_buffer_size / 1024);
|
||||
|
||||
if (!o_direct_flag && (memory_reuse_type == SCST_USER_MEM_NO_REUSE)) {
|
||||
if (!o_direct_flag && memory_reuse_type == SCST_USER_MEM_NO_REUSE) {
|
||||
PRINT_INFO(" %s", "Using unaligned buffers");
|
||||
alloc_fn = malloc;
|
||||
}
|
||||
|
||||
+5
-5
@@ -59,7 +59,7 @@ int debug_print_prefix(unsigned long flags, const char *prefix,
|
||||
if (flags & TRACE_PID)
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "[%d]: ",
|
||||
gettid());
|
||||
if (prefix != NULL)
|
||||
if (prefix)
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%s:", prefix);
|
||||
if (flags & TRACE_FUNCTION)
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%s:", func);
|
||||
@@ -79,7 +79,7 @@ void debug_print_buffer(const void *data, int len)
|
||||
int z, z1, i;
|
||||
const unsigned char *buf = (const unsigned char *) data;
|
||||
|
||||
if (buf == NULL)
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
pthread_spin_lock(&trace_buf_lock);
|
||||
@@ -92,8 +92,8 @@ void debug_print_buffer(const void *data, int len)
|
||||
" ");
|
||||
for (; (z1 < z) && (i < TRACE_BUF_SIZE - 1);
|
||||
z1++) {
|
||||
if ((buf[z1] >= 0x20) &&
|
||||
(buf[z1] < 0x80))
|
||||
if (buf[z1] >= 0x20 &&
|
||||
buf[z1] < 0x80)
|
||||
trace_buf[i++] = buf[z1];
|
||||
else
|
||||
trace_buf[i++] = '.';
|
||||
@@ -110,7 +110,7 @@ void debug_print_buffer(const void *data, int len)
|
||||
}
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, " ");
|
||||
for (; (z1 < z) && (i < TRACE_BUF_SIZE - 1); z1++) {
|
||||
if ((buf[z1] > 0x20) && (buf[z1] < 0x80))
|
||||
if (buf[z1] > 0x20 && buf[z1] < 0x80)
|
||||
trace_buf[i++] = buf[z1];
|
||||
else
|
||||
trace_buf[i++] = '.';
|
||||
|
||||
Reference in New Issue
Block a user