From 8eea9263169d1082f4855286cbc7122eb4194f59 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 21 Oct 2026 14:59:44 +0300 Subject: [PATCH] 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 --- iscsi-scst/usr/chap.c | 10 +- iscsi-scst/usr/config.c | 80 ++-- iscsi-scst/usr/conn.c | 2 +- iscsi-scst/usr/ctldev.c | 16 +- iscsi-scst/usr/event.c | 122 ++--- iscsi-scst/usr/iscsi_scstd.c | 10 +- iscsi-scst/usr/iscsid.c | 60 +-- iscsi-scst/usr/isns.c | 14 +- iscsi-scst/usr/session.c | 4 +- iscsi-scst/usr/target.c | 10 +- iscsi-scst/usr/types.h | 2 +- qla2x00t-32gbit/qla2x00-target/qla_tgt.c | 4 +- qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c | 20 +- scst/src/scst_dlm.c | 8 +- scst/src/scst_lib.c | 444 +++++++++--------- scst/src/scst_no_dlm.c | 4 +- usr/events/events.c | 2 +- usr/fileio/common.c | 60 +-- usr/fileio/fileio.c | 10 +- usr/include/debug.c | 10 +- 20 files changed, 446 insertions(+), 446 deletions(-) diff --git a/iscsi-scst/usr/chap.c b/iscsi-scst/usr/chap.c index 98d14e46e..d4b242836 100644 --- a/iscsi-scst/usr/chap.c +++ b/iscsi-scst/usr/chap.c @@ -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; diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 0a815dba9..1fe35be7c 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -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; diff --git a/iscsi-scst/usr/conn.c b/iscsi-scst/usr/conn.c index ba61af5ad..ff17515be 100644 --- a/iscsi-scst/usr/conn.c +++ b/iscsi-scst/usr/conn.c @@ -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)); diff --git a/iscsi-scst/usr/ctldev.c b/iscsi-scst/usr/ctldev.c index 1906ec255..2c8488165 100644 --- a/iscsi-scst/usr/ctldev.c +++ b/iscsi-scst/usr/ctldev.c @@ -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; diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index bc98a3a53..71180a56a 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -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; diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index ca8d65c87..b83dd7661 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -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); } diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index 58dd14475..ffac694ca 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -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; diff --git a/iscsi-scst/usr/isns.c b/iscsi-scst/usr/isns.c index f04bc8450..a045ef0e9 100644 --- a/iscsi-scst/usr/isns.c +++ b/iscsi-scst/usr/isns.c @@ -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) diff --git a/iscsi-scst/usr/session.c b/iscsi-scst/usr/session.c index c8193a857..4f7867296 100644 --- a/iscsi-scst/usr/session.c +++ b/iscsi-scst/usr/session.c @@ -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; diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 9324358cf..649f0a1f8 100644 --- a/iscsi-scst/usr/target.c +++ b/iscsi-scst/usr/target.c @@ -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; } diff --git a/iscsi-scst/usr/types.h b/iscsi-scst/usr/types.h index 7836696a6..3f9a4742f 100644 --- a/iscsi-scst/usr/types.h +++ b/iscsi-scst/usr/types.h @@ -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; diff --git a/qla2x00t-32gbit/qla2x00-target/qla_tgt.c b/qla2x00t-32gbit/qla2x00-target/qla_tgt.c index cae875897..5c18d63bc 100644 --- a/qla2x00t-32gbit/qla2x00-target/qla_tgt.c +++ b/qla2x00t-32gbit/qla2x00-target/qla_tgt.c @@ -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", diff --git a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c index fa99df533..8fc8594da 100644 --- a/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c +++ b/qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c @@ -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); diff --git a/scst/src/scst_dlm.c b/scst/src/scst_dlm.c index cb1ed9765..0abd35923 100644 --- a/scst/src/scst_dlm.c +++ b/scst/src/scst_dlm.c @@ -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; } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index c7b072494..0b2458c1d 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1680,11 +1680,11 @@ int scst_alloc_sense(struct scst_cmd *cmd, int atomic) TRACE_ENTRY(); - if (cmd->sense != NULL) + if (cmd->sense) goto memzero; cmd->sense = mempool_alloc(scst_sense_mempool, gfp_mask); - if (cmd->sense == NULL) { + if (!cmd->sense) { PRINT_CRIT_ERROR("Sense memory allocation failed (op %s). The sense data will be lost!!", scst_get_opcode_name(cmd)); res = -ENOMEM; @@ -1808,13 +1808,13 @@ static int scst_set_lun_not_supported_request_sense(struct scst_cmd *cmd, goto out; } - if ((cmd->sg != NULL) && scst_sense_valid(sg_virt(cmd->sg))) { + if (cmd->sg && scst_sense_valid(sg_virt(cmd->sg))) { TRACE_MGMT_DBG("cmd %p already has sense set", cmd); res = -EEXIST; goto out; } - if (cmd->sg == NULL) { + if (!cmd->sg) { if (cmd->bufflen == 0) { int bufflen = cmd->cdb[4]; @@ -1826,7 +1826,7 @@ static int scst_set_lun_not_supported_request_sense(struct scst_cmd *cmd, * callback, it is responsible to copy the sense to its buffer * in xmit_response(). */ - if (cmd->tgt_i_data_buf_alloced && (cmd->tgt_i_sg != NULL)) { + if (cmd->tgt_i_data_buf_alloced && cmd->tgt_i_sg) { cmd->sg = cmd->tgt_i_sg; cmd->sg_cnt = cmd->tgt_i_sg_cnt; TRACE_MEM("Tgt sg used for sense for cmd %p", cmd); @@ -1834,7 +1834,7 @@ static int scst_set_lun_not_supported_request_sense(struct scst_cmd *cmd, } cmd->sg = scst_alloc_sg(cmd->bufflen, GFP_ATOMIC, &cmd->sg_cnt); - if (cmd->sg == NULL) { + if (!cmd->sg) { PRINT_ERROR("Unable to alloc sg for REQUEST SENSE (sense %x/%x/%x)", key, asc, ascq); res = 1; @@ -1884,7 +1884,7 @@ static int scst_set_lun_not_supported_inquiry(struct scst_cmd *cmd) goto out; } - if (cmd->sg == NULL) { + if (!cmd->sg) { if (cmd->bufflen == 0) { int bufflen = get_unaligned_be16(&cmd->cdb[3]); @@ -1896,7 +1896,7 @@ static int scst_set_lun_not_supported_inquiry(struct scst_cmd *cmd) * callback, it is responsible to copy the sense to its buffer * in xmit_response(). */ - if (cmd->tgt_i_data_buf_alloced && (cmd->tgt_i_sg != NULL)) { + if (cmd->tgt_i_data_buf_alloced && cmd->tgt_i_sg) { cmd->sg = cmd->tgt_i_sg; cmd->sg_cnt = cmd->tgt_i_sg_cnt; TRACE_MEM("Tgt used for INQUIRY (not supported LUN): cmd %p", @@ -1905,7 +1905,7 @@ static int scst_set_lun_not_supported_inquiry(struct scst_cmd *cmd) } cmd->sg = scst_alloc_sg(cmd->bufflen, GFP_ATOMIC, &cmd->sg_cnt); - if (cmd->sg == NULL) { + if (!cmd->sg) { PRINT_ERROR("Unable to alloc sg for INQUIRY (not supported LUN)"); res = 1; goto out; @@ -1931,7 +1931,7 @@ go: /* Set T10 Vendor identification */ if (len >= 16) - memcpy(&(buf[8]), SCST_NOLUN_VENDOR, 8); + memcpy(&buf[8], SCST_NOLUN_VENDOR, 8); TRACE_BUFFER("INQUIRY for not supported LUN set", buf, len); @@ -1966,7 +1966,7 @@ static int scst_set_lun_not_supported_report_luns(struct scst_cmd *cmd) goto out; } - if ((cmd->cdb[2] != 0) && (cmd->cdb[2] != 2)) { + if (cmd->cdb[2] != 0 && cmd->cdb[2] != 2) { TRACE(TRACE_MINOR, "Unsupported SELECT REPORT value %#x in REPORT LUNS command", cmd->cdb[2]); @@ -1974,7 +1974,7 @@ static int scst_set_lun_not_supported_report_luns(struct scst_cmd *cmd) goto out; } - if (cmd->sg == NULL) { + if (!cmd->sg) { if (cmd->bufflen == 0) { int bufflen = get_unaligned_be32(&cmd->cdb[6]); @@ -1986,7 +1986,7 @@ static int scst_set_lun_not_supported_report_luns(struct scst_cmd *cmd) * callback, it is responsible to copy the sense to its buffer * in xmit_response(). */ - if (cmd->tgt_i_data_buf_alloced && (cmd->tgt_i_sg != NULL)) { + if (cmd->tgt_i_data_buf_alloced && cmd->tgt_i_sg) { cmd->sg = cmd->tgt_i_sg; cmd->sg_cnt = cmd->tgt_i_sg_cnt; TRACE_MEM("Tgt used for REPORTS LUNS (not supported LUN): cmd %p", @@ -1995,7 +1995,7 @@ static int scst_set_lun_not_supported_report_luns(struct scst_cmd *cmd) } cmd->sg = scst_alloc_sg(cmd->bufflen, GFP_ATOMIC, &cmd->sg_cnt); - if (cmd->sg == NULL) { + if (!cmd->sg) { PRINT_ERROR("Unable to alloc sg for REPORTS LUNS (not supported LUN)"); res = 1; goto out; @@ -2097,7 +2097,7 @@ int scst_set_cmd_error(struct scst_cmd *cmd, int key, int asc, int ascq) * We need for LOGICAL UNIT NOT SUPPORTED special handling for * REQUEST SENSE and INQUIRY. */ - if ((key == ILLEGAL_REQUEST) && (asc == 0x25) && (ascq == 0)) { + if (key == ILLEGAL_REQUEST && asc == 0x25 && ascq == 0) { if (cmd->cdb[0] == REQUEST_SENSE) res = scst_set_lun_not_supported_request_sense(cmd, key, asc, ascq); @@ -2274,8 +2274,8 @@ int scst_set_sense(u8 *buffer, int len, bool d_sense, * a) the ADDITIONAL SENSE CODE field is set to 29h; or * b) the additional sense code is set to MODE PARAMETERS CHANGED. */ - if ((key == UNIT_ATTENTION) && - ((asc == 0x29) || ((asc == 0x2A) && (ascq == 1)))) + if (key == UNIT_ATTENTION && + (asc == 0x29 || (asc == 0x2A && ascq == 1))) d_sense = false; if (d_sense) { @@ -2445,7 +2445,7 @@ void scst_check_convert_sense(struct scst_cmd *cmd) TRACE_ENTRY(); - if ((cmd->sense == NULL) || (cmd->status != SAM_STAT_CHECK_CONDITION)) + if (!cmd->sense || cmd->status != SAM_STAT_CHECK_CONDITION) goto out; d_sense = scst_get_cmd_dev_d_sense(cmd); @@ -2457,11 +2457,11 @@ void scst_check_convert_sense(struct scst_cmd *cmd) * a) the ADDITIONAL SENSE CODE field is set to 29h; or * b) the additional sense code is set to MODE PARAMETERS CHANGED. */ - !((cmd->sense[2] == UNIT_ATTENTION) && - ((cmd->sense[12] == 0x29) || - ((cmd->sense[12] == 0x2A) && (cmd->sense[13] == 1))))) { + !(cmd->sense[2] == UNIT_ATTENTION && + (cmd->sense[12] == 0x29 || + (cmd->sense[12] == 0x2A && cmd->sense[13] == 1)))) { TRACE_MGMT_DBG("Converting fixed sense to descriptor (cmd %p)", cmd); - if ((cmd->sense_valid_len < 18)) { + if (cmd->sense_valid_len < 18) { PRINT_ERROR("Sense too small to convert (%d, type: fixed)", cmd->sense_buflen); goto out; @@ -2472,7 +2472,7 @@ void scst_check_convert_sense(struct scst_cmd *cmd) (scst_sense_response_code(cmd->sense) == 0x73))) { TRACE_MGMT_DBG("Converting descriptor sense to fixed (cmd %p)", cmd); - if ((cmd->sense_buflen < 18) || (cmd->sense_valid_len < 8)) { + if (cmd->sense_buflen < 18 || cmd->sense_valid_len < 8) { PRINT_ERROR("Sense too small to convert (%d, type: descriptor, valid %d)", cmd->sense_buflen, cmd->sense_valid_len); goto out; @@ -2517,7 +2517,7 @@ void scst_set_busy(struct scst_cmd *cmd) TRACE_ENTRY(); - if ((c <= 1) || (cmd->sess->init_phase != SCST_SESS_IPH_READY)) { + if (c <= 1 || cmd->sess->init_phase != SCST_SESS_IPH_READY) { scst_set_cmd_error_status(cmd, SAM_STAT_BUSY); TRACE(TRACE_FLOW_CONTROL, "Sending BUSY status to initiator %s (cmds count %d, queue_type %x, sess->init_phase %d)", cmd->sess->initiator_name, c, @@ -2593,7 +2593,7 @@ struct scst_aen *scst_alloc_aen(struct scst_session *sess, TRACE_ENTRY(); aen = mempool_alloc(scst_aen_mempool, GFP_KERNEL); - if (aen == NULL) { + if (!aen) { PRINT_ERROR("AEN memory allocation failed. Corresponding event notification will not be performed (initiator %s)", sess->initiator_name); goto out; @@ -2660,12 +2660,12 @@ void scst_gen_aen_or_ua(struct scst_tgt_dev *tgt_dev, goto queue_ua; } - if (tgtt->report_aen != NULL) { + if (tgtt->report_aen) { struct scst_aen *aen; int rc; aen = scst_alloc_aen(sess, tgt_dev->lun); - if (aen == NULL) + if (!aen) goto queue_ua; aen->event_fn = SCST_AEN_SCSI; @@ -2825,8 +2825,8 @@ static void scst_report_luns_changed_sess(struct scst_session *sess) TRACE_ENTRY(); - if ((sess->init_phase != SCST_SESS_IPH_READY) || - (sess->shut_phase != SCST_SESS_SPH_READY)) + if (sess->init_phase != SCST_SESS_IPH_READY || + sess->shut_phase != SCST_SESS_SPH_READY) goto out; TRACE_DBG("REPORTED LUNS DATA CHANGED (sess %p)", sess); @@ -2852,12 +2852,12 @@ static void scst_report_luns_changed_sess(struct scst_session *sess) found: rcu_read_unlock(); - if (tgtt->report_aen != NULL) { + if (tgtt->report_aen) { struct scst_aen *aen; int rc; aen = scst_alloc_aen(sess, lun); - if (aen == NULL) + if (!aen) goto queue_ua; aen->event_fn = SCST_AEN_SCSI; @@ -2961,7 +2961,7 @@ void scst_requeue_ua(struct scst_cmd *cmd, const u8 *buf, int size) { TRACE_ENTRY(); - if (buf == NULL) { + if (!buf) { buf = cmd->sense; size = cmd->sense_valid_len; } @@ -3047,9 +3047,9 @@ retry_add: list_for_each_entry_rcu(tgt_dev, head, sess_tgt_dev_list_entry) { - if ((tgt_dev->dev == acg_dev->dev) && - (tgt_dev->lun == acg_dev->lun) && - (tgt_dev->acg_dev->acg_dev_rd_only == acg_dev->acg_dev_rd_only)) { + if (tgt_dev->dev == acg_dev->dev && + tgt_dev->lun == acg_dev->lun && + tgt_dev->acg_dev->acg_dev_rd_only == acg_dev->acg_dev_rd_only) { TRACE_MGMT_DBG("sess %p: tgt_dev %p for LUN %lld stays the same", sess, tgt_dev, (unsigned long long)tgt_dev->lun); @@ -3219,7 +3219,7 @@ int scst_get_cmd_abnormal_done_state(struct scst_cmd *cmd) case SCST_CMD_STATE_PREPROCESSING_DONE: case SCST_CMD_STATE_PREPROCESSING_DONE_CALLED: - if (cmd->tgt_dev == NULL) { + if (!cmd->tgt_dev) { trace = true; res = SCST_CMD_STATE_PRE_XMIT_RESP1; } else @@ -3330,9 +3330,9 @@ void scst_set_cmd_abnormal_done_state(struct scst_cmd *cmd) } #ifdef CONFIG_SCST_EXTRACHECKS - if (((cmd->state != SCST_CMD_STATE_PRE_XMIT_RESP1) && - (cmd->state != SCST_CMD_STATE_PREPROCESSING_DONE)) && - (cmd->tgt_dev == NULL) && !cmd->internal) { + if ((cmd->state != SCST_CMD_STATE_PRE_XMIT_RESP1 && + cmd->state != SCST_CMD_STATE_PREPROCESSING_DONE) && + !cmd->tgt_dev && !cmd->internal) { PRINT_CRIT_ERROR("Wrong not inited cmd state %d (cmd %p, op %s)", cmd->state, cmd, scst_get_opcode_name(cmd)); sBUG(); @@ -3459,12 +3459,12 @@ static void scst_adjust_sg(struct scst_cmd *cmd, bool reg_sg, if (reg_sg) { sg = cmd->sg; sg_cnt = &cmd->sg_cnt; - adjust_dif = (cmd->dif_sg != NULL); + adjust_dif = (cmd->dif_sg); } else { sg = *cmd->write_sg; sg_cnt = cmd->write_sg_cnt; if (sg == cmd->sg) - adjust_dif = (cmd->dif_sg != NULL); + adjust_dif = (cmd->dif_sg); else adjust_dif = false; } @@ -3613,7 +3613,7 @@ static int scst_adjust_sg_get_tail(struct scst_cmd *cmd, cmd->sg_buff_modified = 1; - if (cmd->dif_sg != NULL) { + if (cmd->dif_sg) { adjust_len >>= (cmd->dev->block_shift - SCST_DIF_TAG_SHIFT); must_left >>= (cmd->dev->block_shift - SCST_DIF_TAG_SHIFT); @@ -3902,7 +3902,7 @@ bool __scst_get_resid(struct scst_cmd *cmd, int *resid, int *bidi_out_resid) TRACE_ENTRY(); *resid = 0; - if (bidi_out_resid != NULL) + if (bidi_out_resid) *bidi_out_resid = 0; if (!cmd->expected_values_set) { @@ -4132,7 +4132,7 @@ bool __scst_is_relative_target_port_id_unique(u16 id, const struct scst_tgt *t) list_for_each_entry(tgt, &tgtt->tgt_list, tgt_list_entry) { if (tgt == t) continue; - if ((tgt->tgtt->is_target_enabled != NULL) && + if (tgt->tgtt->is_target_enabled && !tgt->tgtt->is_target_enabled(tgt)) continue; if (id == tgt->rel_tgt_id) { @@ -4215,7 +4215,7 @@ int scst_alloc_tgt(struct scst_tgt_template *tgtt, struct scst_tgt **tgt) TRACE_ENTRY(); t = kmem_cache_zalloc(scst_tgt_cachep, GFP_KERNEL); - if (t == NULL) { + if (!t) { PRINT_ERROR("%s", "Allocation of tgt failed"); res = -ENOMEM; goto out; @@ -4339,7 +4339,7 @@ int scst_alloc_device(gfp_t gfp_mask, int nodeid, struct scst_device **out_dev) lockdep_assert_held(&scst_mutex); dev = kmem_cache_alloc_node(scst_dev_cachep, gfp_mask, nodeid); - if (dev == NULL) { + if (!dev) { PRINT_ERROR("%s", "Allocation of scst_device failed"); res = -ENOMEM; goto out; @@ -4422,7 +4422,7 @@ static struct scst_acg_dev *scst_alloc_acg_dev(struct scst_acg *acg, TRACE_ENTRY(); res = kmem_cache_zalloc(scst_acgd_cachep, GFP_KERNEL); - if (res == NULL) { + if (!res) { PRINT_ERROR("%s", "Allocation of scst_acg_dev failed"); goto out; } @@ -4502,21 +4502,21 @@ static int scst_check_dif_compatibility(const struct scst_acg *acg, } if (dev->dev_dif_mode & SCST_DIF_MODE_TGT) { - if ((dev->dev_dif_type == 1) && !tgt->tgt_hw_dif_type1_supported) { + if (dev->dev_dif_type == 1 && !tgt->tgt_hw_dif_type1_supported) { PRINT_ERROR("Target %s doesn't support type 1 protection TGT mode (device %s)", tgt->tgt_name, dev->virt_name); goto out; } - if ((dev->dev_dif_type == 2) && !tgt->tgt_hw_dif_type2_supported) { + if (dev->dev_dif_type == 2 && !tgt->tgt_hw_dif_type2_supported) { PRINT_ERROR("Target %s doesn't support type 2 protection TGT mode (device %s)", tgt->tgt_name, dev->virt_name); goto out; } - if ((dev->dev_dif_type == 3) && !tgt->tgt_hw_dif_type3_supported) { + if (dev->dev_dif_type == 3 && !tgt->tgt_hw_dif_type3_supported) { PRINT_ERROR("Target %s doesn't support type 3 protection TGT mode (device %s)", tgt->tgt_name, dev->virt_name); @@ -4524,7 +4524,7 @@ static int scst_check_dif_compatibility(const struct scst_acg *acg, } } - if (tgt->tgt_supported_dif_block_sizes == NULL) + if (!tgt->tgt_supported_dif_block_sizes) goto out_ok; p = tgt->tgt_supported_dif_block_sizes; @@ -4606,7 +4606,7 @@ int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, goto out; acg_dev = scst_alloc_acg_dev(acg, dev, lun); - if (acg_dev == NULL) { + if (!acg_dev) { res = -ENOMEM; goto out; } @@ -4653,7 +4653,7 @@ int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, dev->virt_name, acg->acg_name, lun, flags, acg->tgt->tgt_name); - if (out_acg_dev != NULL) + if (out_acg_dev) *out_acg_dev = acg_dev; out: @@ -4701,7 +4701,7 @@ static struct scst_acg_dev *__scst_acg_del_lun(struct scst_acg *acg, break; } } - if (acg_dev == NULL) + if (!acg_dev) goto out; *report_luns_changed = scst_cm_on_del_lun(acg_dev, @@ -4761,7 +4761,7 @@ int scst_acg_del_lun(struct scst_acg *acg, u64 lun, acg_dev = __scst_acg_del_lun(acg, lun, &tgt_dev_list, &gen_report_luns_changed); - if (acg_dev == NULL) { + if (!acg_dev) { PRINT_ERROR("Device is not found in group %s", acg->acg_name); res = -EINVAL; goto out; @@ -4941,7 +4941,7 @@ int scst_alloc_add_acg(struct scst_tgt *tgt, const char *acg_name, lockdep_assert_held(&scst_mutex); acg = kzalloc_obj(*acg); - if (acg == NULL) { + if (!acg) { PRINT_ERROR("%s", "Allocation of acg failed"); res = -ENOMEM; goto out; @@ -4954,7 +4954,7 @@ int scst_alloc_add_acg(struct scst_tgt *tgt, const char *acg_name, INIT_LIST_HEAD(&acg->acn_list); cpumask_copy(&acg->acg_cpu_mask, &default_cpu_mask); acg->acg_name = kstrdup(acg_name, GFP_KERNEL); - if (acg->acg_name == NULL) { + if (!acg->acg_name) { PRINT_ERROR("%s", "Allocation of acg_name failed"); res = -ENOMEM; goto out_free; @@ -5206,14 +5206,14 @@ static struct scst_tgt_dev *scst_find_shared_io_tgt_dev( switch (acg->acg_io_grouping_type) { case SCST_IO_GROUPING_AUTO: - if (sess->initiator_name == NULL) + if (!sess->initiator_name) goto out; list_for_each_entry(t, &tgt_dev->dev->dev_tgt_dev_list, dev_tgt_dev_list_entry) { - if ((t == tgt_dev) || - (t->sess->initiator_name == NULL) || - (t->active_cmd_threads == NULL)) + if (t == tgt_dev || + !t->sess->initiator_name || + !t->active_cmd_threads) continue; TRACE_DBG("t %s", t->sess->initiator_name); @@ -5229,7 +5229,7 @@ static struct scst_tgt_dev *scst_find_shared_io_tgt_dev( case SCST_IO_GROUPING_THIS_GROUP_ONLY: list_for_each_entry(t, &tgt_dev->dev->dev_tgt_dev_list, dev_tgt_dev_list_entry) { - if ((t == tgt_dev) || (t->active_cmd_threads == NULL)) + if (t == tgt_dev || !t->active_cmd_threads) continue; TRACE_DBG("t %s (acg %p)", t->sess->initiator_name, @@ -5246,7 +5246,7 @@ static struct scst_tgt_dev *scst_find_shared_io_tgt_dev( default: list_for_each_entry(t, &tgt_dev->dev->dev_tgt_dev_list, dev_tgt_dev_list_entry) { - if ((t == tgt_dev) || (t->active_cmd_threads == NULL)) + if (t == tgt_dev || !t->active_cmd_threads) continue; TRACE_DBG("t %s (acg %p, io_grouping_type %d)", @@ -5316,7 +5316,7 @@ static int scst_ioc_keeper_thread(void *arg) current->flags |= PF_NOFREEZE; - sBUG_ON(aic_keeper->aic != NULL); + sBUG_ON(aic_keeper->aic); aic_keeper->aic = get_task_io_context(current, GFP_KERNEL, NUMA_NO_NODE); TRACE_DBG("Alloced new async IO context %p (aic %p)", @@ -5361,7 +5361,7 @@ int scst_tgt_dev_setup_threads(struct scst_tgt_dev *tgt_dev) tgt_dev->active_cmd_threads = &scst_main_cmd_threads; shared_io_tgt_dev = scst_find_shared_io_tgt_dev(tgt_dev); - if (shared_io_tgt_dev != NULL) { + if (shared_io_tgt_dev) { aic_keeper = shared_io_tgt_dev->aic_keeper; kref_get(&aic_keeper->aic_keeper_kref); @@ -5372,7 +5372,7 @@ int scst_tgt_dev_setup_threads(struct scst_tgt_dev *tgt_dev) /* Create new context */ aic_keeper = kzalloc_node(sizeof(*aic_keeper), GFP_KERNEL, dev->dev_numa_node_id); - if (aic_keeper == NULL) { + if (!aic_keeper) { PRINT_ERROR("Unable to alloc aic_keeper (size %zd)", sizeof(*aic_keeper)); res = -ENOMEM; @@ -5418,7 +5418,7 @@ int scst_tgt_dev_setup_threads(struct scst_tgt_dev *tgt_dev) tgt_dev->active_cmd_threads = &tgt_dev->tgt_dev_cmd_threads; shared_io_tgt_dev = scst_find_shared_io_tgt_dev(tgt_dev); - if (shared_io_tgt_dev != NULL) { + if (shared_io_tgt_dev) { TRACE_DBG("Linking io context %p for shared tgt_dev %p (cmd_threads %p)", shared_io_tgt_dev->active_cmd_threads->io_context, tgt_dev, tgt_dev->active_cmd_threads); @@ -5539,7 +5539,7 @@ int scst_alloc_add_tgt_dev(struct scst_session *sess, TRACE_ENTRY(); tgt_dev = kmem_cache_zalloc(scst_tgtd_cachep, GFP_KERNEL); - if (tgt_dev == NULL) { + if (!tgt_dev) { PRINT_ERROR("%s", "Allocation of scst_tgt_dev failed"); res = -ENOMEM; goto out; @@ -5586,7 +5586,7 @@ int scst_alloc_add_tgt_dev(struct scst_session *sess, scst_sgv_pool_use_norm(tgt_dev); - if (dev->scsi_dev != NULL) { + if (dev->scsi_dev) { const struct Scsi_Host *shost = dev->scsi_dev->host; ini_sg = shost->sg_tablesize; @@ -5609,7 +5609,7 @@ int scst_alloc_add_tgt_dev(struct scst_session *sess, if ((sess->tgt->tgtt->use_clustering || ini_use_clustering) && !sess->tgt->tgtt->no_clustering && !(sess->tgt->tgt_hw_dif_same_sg_layout_required && - (tgt_dev->dev->dev_dif_type != 0))) + tgt_dev->dev->dev_dif_type != 0)) scst_sgv_pool_use_norm_clust(tgt_dev); if (sess->tgt->tgtt->unchecked_isa_dma || ini_unchecked_isa_dma) @@ -5631,7 +5631,7 @@ int scst_alloc_add_tgt_dev(struct scst_session *sess, if (dev->handler->parse_atomic && dev->handler->dev_alloc_data_buf_atomic && - (sess->tgt->tgtt->preprocessing_done == NULL)) { + !sess->tgt->tgtt->preprocessing_done) { if (sess->tgt->tgtt->rdy_to_xfer_atomic) tgt_dev->tgt_dev_after_init_wr_atomic = 1; } @@ -5643,7 +5643,7 @@ int scst_alloc_add_tgt_dev(struct scst_session *sess, dev->d_sense, SCST_LOAD_SENSE(scst_sense_reset_UA)); scst_alloc_set_UA(tgt_dev, sense_buffer, sl, 0); - if (sess->tgt->tgtt->get_initiator_port_transport_id == NULL) { + if (!sess->tgt->tgtt->get_initiator_port_transport_id) { if (!list_empty(&dev->dev_registrants_list)) { PRINT_WARNING("Initiators from target %s can't connect to device %s, because the device has PR registrants and the target doesn't support Persistent Reservations", sess->tgt->tgtt->name, @@ -5711,7 +5711,7 @@ out_pr_clear: scst_pr_clear_tgt_dev(tgt_dev); out_dec_free: - if (tgtt->get_initiator_port_transport_id == NULL) + if (!tgtt->get_initiator_port_transport_id) dev->not_pr_supporting_tgt_devs_num--; out_free_ua: @@ -5783,7 +5783,7 @@ void scst_free_tgt_dev(struct scst_tgt_dev *tgt_dev) #endif WARN_ON_ONCE(atomic_read(&tgt_dev->tgt_dev_cmd_count) != 0); - if (tgtt->get_initiator_port_transport_id == NULL) + if (!tgtt->get_initiator_port_transport_id) dev->not_pr_supporting_tgt_devs_num--; scst_clear_reservation(tgt_dev); @@ -5888,7 +5888,7 @@ int scst_acg_add_acn(struct scst_acg *acg, const char *name) } acn = kzalloc_obj(*acn); - if (acn == NULL) { + if (!acn) { PRINT_ERROR("%s", "Unable to allocate scst_acn"); res = -ENOMEM; goto out; @@ -5897,7 +5897,7 @@ int scst_acg_add_acn(struct scst_acg *acg, const char *name) acn->acg = acg; nm = kstrdup(name, GFP_KERNEL); - if (nm == NULL) { + if (!nm) { PRINT_ERROR("%s", "Unable to allocate scst_acn->name"); res = -ENOMEM; goto out_free; @@ -5992,7 +5992,7 @@ struct scst_cmd *__scst_create_prepare_internal_cmd(const u8 *cdb, TRACE_ENTRY(); res = scst_alloc_cmd(cdb, cdb_len, gfp_mask); - if (res == NULL) + if (!res) goto out; res->cmd_threads = tgt_dev->active_cmd_threads; @@ -6051,7 +6051,7 @@ static struct scst_cmd *scst_create_prepare_internal_cmd( res = __scst_create_prepare_internal_cmd(cdb, cdb_len, queue_type, orig_cmd->tgt_dev, gfp_mask, false); - if (res == NULL) + if (!res) goto out; res->atomic = scst_cmd_atomic(orig_cmd); @@ -6103,7 +6103,7 @@ int scst_prepare_request_sense(struct scst_cmd *orig_cmd) priv->finish_fn = scst_complete_request_sense; priv->orig_cmd = orig_cmd; - if (orig_cmd->sense != NULL) { + if (orig_cmd->sense) { TRACE_MEM("Releasing sense %p (orig_cmd %p)", orig_cmd->sense, orig_cmd); mempool_free(orig_cmd->sense, scst_sense_mempool); @@ -6113,7 +6113,7 @@ int scst_prepare_request_sense(struct scst_cmd *orig_cmd) rs_cmd = scst_create_prepare_internal_cmd(orig_cmd, request_sense, sizeof(request_sense), SCST_CMD_QUEUE_HEAD_OF_QUEUE); - if (rs_cmd == NULL) + if (!rs_cmd) goto free_priv; rs_cmd->tgt_i_priv = priv; @@ -6152,11 +6152,11 @@ static void scst_complete_request_sense(struct scst_cmd *req_cmd) kfree(priv); - sBUG_ON(orig_cmd == NULL); + sBUG_ON(!orig_cmd); len = scst_get_buf_full(req_cmd, &buf, false); - if (scsi_status_is_good(req_cmd->status) && (len > 0) && + if (scsi_status_is_good(req_cmd->status) && len > 0 && scst_sense_valid(buf)) { TRACE(TRACE_SCSI | TRACE_MGMT_DEBUG, "REQUEST SENSE %p returned valid sense (orig cmd %s)", req_cmd, orig_cmd->op_name); @@ -6509,7 +6509,7 @@ static int scst_ws_push_single_write(struct scst_write_same_priv *wsp, cmd = scst_create_prepare_internal_cmd(ws_cmd, write_cdb, write_cdb_len, SCST_CMD_QUEUE_SIMPLE); - if (cmd == NULL) { + if (!cmd) { res = -ENOMEM; goto out_busy; } @@ -6534,7 +6534,7 @@ static int scst_ws_push_single_write(struct scst_write_same_priv *wsp, dif_sg = sgv_pool_alloc(ws_cmd->tgt_dev->pools[raw_smp_processor_id()], dif_bufflen, GFP_KERNEL, 0, &dif_sg_cnt, &dif_sgv, &cmd->dev->dev_mem_lim, NULL); - if (unlikely(dif_sg == NULL)) { + if (unlikely(!dif_sg)) { TRACE(TRACE_OUT_OF_MEM, "Unable to alloc DIF sg for %d blocks", blocks); res = -ENOMEM; @@ -6637,7 +6637,7 @@ static void scst_ws_write_cmd_finished(struct scst_cmd *cmd) TRACE_DBG("Write cmd %p finished (ws cmd %p, ws_cur_in_flight %d)", cmd, ws_cmd, wsp->ws_cur_in_flight); - if (cmd->out_sgv != NULL) + if (cmd->out_sgv) sgv_pool_free(cmd->out_sgv, &cmd->dev->dev_mem_lim); cmd->sg = NULL; @@ -6655,7 +6655,7 @@ static void scst_ws_write_cmd_finished(struct scst_cmd *cmd) rc = scst_set_cmd_error_sense(ws_cmd, cmd->sense, cmd->sense_valid_len); else { - sBUG_ON(cmd->sense != NULL); + sBUG_ON(cmd->sense); rc = scst_set_cmd_error_status(ws_cmd, cmd->status); } if (rc != 0) { @@ -6733,8 +6733,8 @@ again: cnt++; } - if ((wsp->ws_left_to_send == 0) && - (wsp->ws_descriptors[wsp->ws_cur_descr+1].sdd_blocks != 0)) { + if (wsp->ws_left_to_send == 0 && + wsp->ws_descriptors[wsp->ws_cur_descr+1].sdd_blocks != 0) { wsp->ws_cur_descr++; wsp->ws_cur_lba = wsp->ws_descriptors[wsp->ws_cur_descr].sdd_lba; wsp->ws_left_to_send = wsp->ws_descriptors[wsp->ws_cur_descr].sdd_blocks; @@ -6772,7 +6772,7 @@ static int scst_ws_sg_init(struct scatterlist **ws_sg, int ws_sg_cnt, int i; *ws_sg = kmalloc_objs(**ws_sg, ws_sg_cnt); - if (*ws_sg == NULL) { + if (!*ws_sg) { PRINT_ERROR("Unable to alloc sg for %d entries", ws_sg_cnt); return -ENOMEM; } @@ -6804,7 +6804,7 @@ static int scst_ws_sg_tails_get(struct scst_data_descriptor *where, struct scst_ i++; wsp->ws_sg_tails = kzalloc_objs(*wsp->ws_sg_tails, i + 1); - if (wsp->ws_sg_tails == NULL) { + if (!wsp->ws_sg_tails) { PRINT_ERROR("Unable to allocate ws_sg_tails (size %zd)", sizeof(*wsp->ws_sg_tails)*i); return -ENOMEM; @@ -6865,9 +6865,9 @@ void scst_write_same(struct scst_cmd *cmd, struct scst_data_descriptor *where) goto out_done; } - if (where == NULL) { + if (!where) { where = kzalloc(sizeof(*where) << 1, GFP_KERNEL); - if (where == NULL) { + if (!where) { PRINT_ERROR("Unable to allocate ws_priv (size %zd, cmd %p)", sizeof(*where) << 1, cmd); goto out_busy; @@ -6884,7 +6884,7 @@ void scst_write_same(struct scst_cmd *cmd, struct scst_data_descriptor *where) goto out_done; wsp = kzalloc_obj(*wsp); - if (wsp == NULL) { + if (!wsp) { PRINT_ERROR("Unable to allocate ws_priv (size %zd, cmd %p)", sizeof(*wsp), cmd); goto out_busy; @@ -7043,7 +7043,7 @@ static void scst_cwr_write_cmd_finished(struct scst_cmd *cmd) rc = scst_set_cmd_error_sense(cwr_cmd, cmd->sense, cmd->sense_valid_len); else { - sBUG_ON(cmd->sense != NULL); + sBUG_ON(cmd->sense); rc = scst_set_cmd_error_status(cwr_cmd, cmd->status); } if (rc != 0) { @@ -7079,7 +7079,7 @@ static void scst_cwr_read_cmd_finished(struct scst_cmd *cmd) rc = scst_set_cmd_error_sense(cwr_cmd, cmd->sense, cmd->sense_valid_len); else { - sBUG_ON(cmd->sense != NULL); + sBUG_ON(cmd->sense); rc = scst_set_cmd_error_status(cwr_cmd, cmd->status); } if (rc != 0) { @@ -7121,7 +7121,7 @@ static void scst_cwr_read_cmd_finished(struct scst_cmd *cmd) wcmd = scst_create_prepare_internal_cmd(cwr_cmd, write16_cdb, sizeof(write16_cdb), SCST_CMD_QUEUE_HEAD_OF_QUEUE); - if (wcmd == NULL) + if (!wcmd) goto out_busy; wcmd->expected_data_direction = SCST_DATA_WRITE; @@ -7219,7 +7219,7 @@ enum scst_exec_res scst_cmp_wr_local(struct scst_cmd *cmd) /* ToDo: HWALIGN'ed kmem_cache */ cwrp = kzalloc_obj(*cwrp); - if (cwrp == NULL) { + if (!cwrp) { PRINT_ERROR("Unable to allocate cwr_priv (size %zd, cmd %p)", sizeof(*cwrp), cmd); goto out_busy; @@ -7240,7 +7240,7 @@ enum scst_exec_res scst_cmp_wr_local(struct scst_cmd *cmd) rcmd = scst_create_prepare_internal_cmd(cmd, read16_cdb, sizeof(read16_cdb), SCST_CMD_QUEUE_HEAD_OF_QUEUE); - if (rcmd == NULL) { + if (!rcmd) { res = -ENOMEM; goto out_free; } @@ -7320,7 +7320,7 @@ static void scst_send_release(struct scst_device *dev) TRACE_ENTRY(); - if (dev->scsi_dev == NULL) + if (!dev->scsi_dev) goto out; scsi_dev = dev->scsi_dev; @@ -7390,7 +7390,7 @@ struct scst_session *scst_alloc_session(struct scst_tgt *tgt, gfp_t gfp_mask, TRACE_ENTRY(); sess = kmem_cache_zalloc(scst_sess_cachep, gfp_mask); - if (sess == NULL) { + if (!sess) { PRINT_ERROR("%s", "Allocation of scst_session failed"); goto out; } @@ -7418,7 +7418,7 @@ struct scst_session *scst_alloc_session(struct scst_tgt *tgt, gfp_t gfp_mask, spin_lock_init(&sess->lat_stats_lock); sess->initiator_name = kstrdup(initiator_name, gfp_mask); - if (sess->initiator_name == NULL) { + if (!sess->initiator_name) { PRINT_ERROR("%s", "Unable to dup sess->initiator_name"); goto out_free_refcnt; } @@ -7593,7 +7593,7 @@ void scst_cmd_set_ext_cdb(struct scst_cmd *cmd, /* It's read-mostly, so cache alignment isn't needed */ cmd->cdb = kmalloc(len, gfp_mask); - if (unlikely(cmd->cdb == NULL)) { + if (unlikely(!cmd->cdb)) { PRINT_ERROR("Unable to alloc extended CDB (size %d)", len); goto out_err; } @@ -7672,7 +7672,7 @@ int scst_pre_init_cmd(struct scst_cmd *cmd, const u8 *cdb, } /* It's read-mostly, so cache alignment isn't needed */ cmd->cdb = kmalloc(cdb_len, gfp_mask); - if (unlikely(cmd->cdb == NULL)) { + if (unlikely(!cmd->cdb)) { PRINT_ERROR("Unable to alloc extended CDB (size %d)", cdb_len); res = -ENOMEM; @@ -7699,7 +7699,7 @@ struct scst_cmd *scst_alloc_cmd(const u8 *cdb, TRACE_ENTRY(); cmd = kmem_cache_zalloc(scst_cmd_cachep, gfp_mask); - if (cmd == NULL) { + if (!cmd) { TRACE(TRACE_OUT_OF_MEM, "%s", "Allocation of scst_cmd failed"); goto out; } @@ -7733,7 +7733,7 @@ static void scst_destroy_cmd(struct scst_cmd *cmd) EXTRACHECKS_BUG_ON(cmd->pre_alloced && cmd->internal); - if ((cmd->tgtt->on_free_cmd != NULL) && likely(!cmd->internal)) { + if (cmd->tgtt->on_free_cmd && likely(!cmd->internal)) { TRACE_DBG("Calling target's on_free_cmd(%p)", cmd); cmd->tgtt->on_free_cmd(cmd); TRACE_DBG("%s", "Target's on_free_cmd() returned"); @@ -7824,10 +7824,10 @@ void scst_free_cmd(struct kref *ref) if (!cmd->tgt_i_data_buf_alloced) scst_check_restore_sg_buff(cmd); - if (likely(cmd->dev != NULL)) { + if (likely(cmd->dev)) { struct scst_dev_type *devt = cmd->devt; - if (devt->on_free_cmd != NULL) { + if (devt->on_free_cmd) { TRACE_DBG("Calling dev handler %s on_free_cmd(%p)", devt->name, cmd); devt->on_free_cmd(cmd); @@ -7838,13 +7838,13 @@ void scst_free_cmd(struct kref *ref) scst_release_space(cmd); - if (unlikely(cmd->sense != NULL)) { + if (unlikely(cmd->sense)) { TRACE_MEM("Releasing sense %p (cmd %p)", cmd->sense, cmd); mempool_free(cmd->sense, scst_sense_mempool); cmd->sense = NULL; } - if (likely(cmd->tgt_dev != NULL)) { + if (likely(cmd->tgt_dev)) { EXTRACHECKS_BUG_ON(cmd->sn_set && !cmd->out_of_sn && !test_bit(SCST_CMD_INC_EXPECTED_SN_PASSED, &cmd->cmd_flags)); if (unlikely(cmd->out_of_sn)) { @@ -7919,7 +7919,7 @@ static void scst_tgt_retry_timer_fn(struct timer_list *timer) scst_check_retries(tgt); spin_lock_irqsave(&tgt->tgt_lock, flags); - if ((tgt->retry_cmds > 0) && !tgt->retry_timer_active) { + if (tgt->retry_cmds > 0 && !tgt->retry_timer_active) { TRACE_DBG("Reactivating retry timer for tgt %p", tgt); tgt->retry_timer.expires = jiffies + SCST_TGT_RETRY_TIMEOUT; add_timer(&tgt->retry_timer); @@ -7937,7 +7937,7 @@ struct scst_mgmt_cmd *scst_alloc_mgmt_cmd(gfp_t gfp_mask) TRACE_ENTRY(); mcmd = mempool_alloc(scst_mgmt_mempool, gfp_mask); - if (mcmd == NULL) { + if (!mcmd) { PRINT_CRIT_ERROR("%s", "Allocation of management command failed, some commands and their data could leak"); goto out; } @@ -7984,7 +7984,7 @@ static bool scst_on_sg_tablesize_low(struct scst_cmd *cmd, bool out) goto failed; } - if (cmd->devt->on_sg_tablesize_low == NULL) + if (!cmd->devt->on_sg_tablesize_low) goto failed; res = cmd->devt->on_sg_tablesize_low(cmd); @@ -7997,7 +7997,7 @@ out: failed: res = false; - if ((ll < 10) || TRACING_MINOR()) { + if (ll < 10 || TRACING_MINOR()) { PRINT_INFO("Unable to complete command due to SG IO count limitation (%srequested %d, available %d, tgt lim %d)", out ? "OUT buffer, " : "", cmd->sg_cnt, tgt_dev->max_sg_cnt, cmd->tgt->sg_tablesize); @@ -8048,7 +8048,7 @@ int scst_alloc_space(struct scst_cmd *cmd) cmd->sg = sgv_pool_alloc(tgt_dev->pools[raw_smp_processor_id()], cmd->bufflen, gfp_mask, flags, &cmd->sg_cnt, &cmd->sgv, &cmd->dev->dev_mem_lim, NULL); - if (unlikely(cmd->sg == NULL)) + if (unlikely(!cmd->sg)) goto out; if (unlikely(cmd->sg_cnt > tgt_dev->max_sg_cnt)) @@ -8069,7 +8069,7 @@ int scst_alloc_space(struct scst_cmd *cmd) cmd->dif_sg = sgv_pool_alloc(tgt_dev->pools[raw_smp_processor_id()], dif_bufflen, gfp_mask, flags, &cmd->dif_sg_cnt, &cmd->dif_sgv, &cmd->dev->dev_mem_lim, NULL); - if (unlikely(cmd->dif_sg == NULL)) + if (unlikely(!cmd->dif_sg)) goto out_sg_free; if (same_layout) { @@ -8099,7 +8099,7 @@ int scst_alloc_space(struct scst_cmd *cmd) cmd->out_sg = sgv_pool_alloc(tgt_dev->pools[raw_smp_processor_id()], cmd->out_bufflen, gfp_mask, flags, &cmd->out_sg_cnt, &cmd->out_sgv, &cmd->dev->dev_mem_lim, NULL); - if (unlikely(cmd->out_sg == NULL)) + if (unlikely(!cmd->out_sg)) goto out_dif_sg_free; if (unlikely(cmd->out_sg_cnt > tgt_dev->max_sg_cnt)) @@ -8120,7 +8120,7 @@ out_out_sg_free: cmd->out_sg_cnt = 0; out_dif_sg_free: - if (cmd->dif_sgv != NULL) { + if (cmd->dif_sgv) { scst_restore_dif_sg(cmd); sgv_pool_free(cmd->dif_sgv, &cmd->dev->dev_mem_lim); cmd->dif_sgv = NULL; @@ -8140,8 +8140,8 @@ static void scst_release_space(struct scst_cmd *cmd) { TRACE_ENTRY(); - if (cmd->sgv == NULL) { - if ((cmd->sg != NULL) && + if (!cmd->sgv) { + if (cmd->sg && !(cmd->tgt_i_data_buf_alloced || cmd->dh_data_buf_alloced)) { TRACE_MEM("Freeing sg %p for cmd %p (cnt %d)", cmd->sg, cmd, cmd->sg_cnt); @@ -8156,7 +8156,7 @@ static void scst_release_space(struct scst_cmd *cmd) goto out; } - if (cmd->out_sgv != NULL) { + if (cmd->out_sgv) { sgv_pool_free(cmd->out_sgv, &cmd->dev->dev_mem_lim); cmd->out_sgv = NULL; cmd->out_sg_cnt = 0; @@ -8164,7 +8164,7 @@ static void scst_release_space(struct scst_cmd *cmd) cmd->out_bufflen = 0; } - if (cmd->dif_sgv != NULL) { + if (cmd->dif_sgv) { scst_restore_dif_sg(cmd); sgv_pool_free(cmd->dif_sgv, &cmd->dev->dev_mem_lim); } @@ -8200,7 +8200,7 @@ static void blk_free_kern_sg_work(struct blk_kern_sg_work *bw) for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) { struct page *pg = sg_page(sg); - if (pg == NULL) + if (!pg) break; __free_page(pg); } @@ -8227,7 +8227,7 @@ static void blk_bio_map_kern_endio(struct bio *bio) #endif struct blk_kern_sg_work *bw = bio->bi_private; - if (bw != NULL) { + if (bw) { /* Decrement the bios in processing and, if zero, free */ BUG_ON(atomic_read(&bw->bios_inflight) <= 0); if (atomic_dec_and_test(&bw->bios_inflight)) { @@ -8261,7 +8261,7 @@ static struct blk_kern_sg_work *blk_copy_kern_sg(struct request_queue *q, res = -ENOMEM; bw = kzalloc_obj(*bw, gfp_mask); - if (bw == NULL) + if (!bw) goto err; bw->src_sgl = sgl; @@ -8287,7 +8287,7 @@ static struct blk_kern_sg_work *blk_copy_kern_sg(struct request_queue *q, #else pg = alloc_page(gfp_mask); #endif - if (pg == NULL) + if (!pg) goto err_free_table; sg_assign_page(sg, pg); @@ -8533,7 +8533,7 @@ static struct request *__blk_map_kern_sg(struct request_queue *q, struct bio *bio = NULL, *hbio = NULL, *tbio = NULL; int bios; - if (unlikely(sgl == NULL || sgl->length == 0 || nents <= 0)) { + if (unlikely(!sgl || sgl->length == 0 || nents <= 0)) { WARN_ON_ONCE(true); rq = ERR_PTR(-EINVAL); goto out; @@ -8587,7 +8587,7 @@ static struct request *__blk_map_kern_sg(struct request_queue *q, if (need_new_bio) { bio = scst_alloc_bio(max_nr_vecs, gfp_mask); - if (bio == NULL) { + if (!bio) { rq = ERR_PTR(-ENOMEM); goto out_free_bios; } @@ -8606,7 +8606,7 @@ static struct request *__blk_map_kern_sg(struct request_queue *q, TRACE_DBG("new bio %p, bios %d", bio, bios); - if (hbio == NULL) + if (!hbio) hbio = bio; else tbio->bi_next = bio; @@ -8651,7 +8651,7 @@ static struct request *__blk_map_kern_sg(struct request_queue *q, } } - if (hbio == NULL) { + if (!hbio) { rq = ERR_PTR(-EINVAL); goto out_free_bios; } @@ -8681,7 +8681,7 @@ out: return rq; out_free_bios: - while (hbio != NULL) { + while (hbio) { bio = hbio; hbio = hbio->bi_next; scst_free_bio(bio); @@ -8785,8 +8785,8 @@ int sg_copy_elem(struct scatterlist **pdst_sg, size_t *pdst_len, if (((src_offs & ~PAGE_MASK) == 0) && ((dst_offs & ~PAGE_MASK) == 0) && - (src_len >= PAGE_SIZE) && (dst_len >= PAGE_SIZE) && - (copy_len >= PAGE_SIZE)) { + src_len >= PAGE_SIZE && dst_len >= PAGE_SIZE && + copy_len >= PAGE_SIZE) { copy_page(daddr, saddr); n = PAGE_SIZE; } else { @@ -8813,7 +8813,7 @@ int sg_copy_elem(struct scatterlist **pdst_sg, size_t *pdst_len, dst_len -= n; if (dst_len == 0) { dst_sg = sg_next_inline(dst_sg); - if (dst_sg == NULL) + if (!dst_sg) goto out; dst_page = sg_page(dst_sg); dst_len = dst_sg->length; @@ -8862,7 +8862,7 @@ static int sg_copy(struct scatterlist *dst_sg, struct scatterlist *src_sg, src_sg, copy_len); copy_len -= copied; res += copied; - if ((copy_len == 0) || (dst_sg == NULL)) + if (copy_len == 0 || !dst_sg) goto out; nents_to_copy--; @@ -8870,7 +8870,7 @@ static int sg_copy(struct scatterlist *dst_sg, struct scatterlist *src_sg, goto out; src_sg = sg_next_inline(src_sg); - } while (src_sg != NULL); + } while (src_sg); out: return res; @@ -8988,7 +8988,7 @@ int scst_scsi_exec_async(struct scst_cmd *cmd, void *data, int cmd_len = cmd->cdb_len; sioc = kmem_cache_zalloc(scsi_io_context_cache, gfp); - if (sioc == NULL) { + if (!sioc) { res = -ENOMEM; goto out; } @@ -9182,8 +9182,8 @@ int sg_cmp_elem(struct scatterlist **pdst_sg, size_t *pdst_len, if (((src_offs & ~PAGE_MASK) == 0) && ((dst_offs & ~PAGE_MASK) == 0) && - (src_len >= PAGE_SIZE) && (dst_len >= PAGE_SIZE) && - (cmp_len >= PAGE_SIZE)) + src_len >= PAGE_SIZE && dst_len >= PAGE_SIZE && + cmp_len >= PAGE_SIZE) n = PAGE_SIZE; else { n = min_t(size_t, PAGE_SIZE - (dst_offs & ~PAGE_MASK), @@ -9221,7 +9221,7 @@ int sg_cmp_elem(struct scatterlist **pdst_sg, size_t *pdst_len, dst_len -= n; if (dst_len == 0) { dst_sg = sg_next_inline(dst_sg); - if (dst_sg == NULL) + if (!dst_sg) goto out; dst_page = sg_page(dst_sg); dst_len = dst_sg->length; @@ -9289,7 +9289,7 @@ static bool sg_cmp(struct scatterlist *dst_sg, struct scatterlist *src_sg, src_sg, cmp_len, miscompare_offs, &res); if (!res) { - if (miscompare_offs != NULL) { + if (miscompare_offs) { *miscompare_offs += compared_all; TRACE_DBG("miscompare_offs %d", *miscompare_offs); @@ -9298,7 +9298,7 @@ static bool sg_cmp(struct scatterlist *dst_sg, struct scatterlist *src_sg, } cmp_len -= compared; compared_all += compared; - if ((cmp_len == 0) || (dst_sg == NULL)) + if (cmp_len == 0 || !dst_sg) goto out; nents_to_cmp--; @@ -9306,7 +9306,7 @@ static bool sg_cmp(struct scatterlist *dst_sg, struct scatterlist *src_sg, goto out; src_sg = sg_next_inline(src_sg); - } while (src_sg != NULL); + } while (src_sg); out: TRACE_EXIT_RES(res); @@ -9358,7 +9358,7 @@ void scst_copy_sg(struct scst_cmd *cmd, enum scst_sg_copy_dir copy_dir) cmd, copy_dir, src_sg, dst_sg, (long long)to_copy, src_sg_dif, dst_sg_dif, (long long)to_copy_dif); - if (unlikely(src_sg == NULL) || unlikely(dst_sg == NULL) || + if (unlikely(!src_sg) || unlikely(!dst_sg) || unlikely(to_copy == 0)) { /* * It can happened, e.g., with scst_user for cmd with delay @@ -9369,7 +9369,7 @@ void scst_copy_sg(struct scst_cmd *cmd, enum scst_sg_copy_dir copy_dir) sg_copy(dst_sg, src_sg, 0, to_copy); - if ((src_sg_dif == NULL) || (dst_sg_dif == NULL) || (to_copy_dif == 0)) + if (!src_sg_dif || !dst_sg_dif || to_copy_dif == 0) goto out; sg_copy(dst_sg_dif, src_sg_dif, 0, to_copy_dif); @@ -9416,7 +9416,7 @@ int scst_get_buf_full(struct scst_cmd *cmd, u8 **buf, bool always_copy) #else *buf = vmalloc(full_size); #endif - if (*buf == NULL) { + if (!*buf) { TRACE(TRACE_OUT_OF_MEM, "vmalloc() failed for opcode %s", scst_get_opcode_name(cmd)); res = -ENOMEM; @@ -9492,7 +9492,7 @@ void scst_put_buf_full(struct scst_cmd *cmd, u8 *buf) { TRACE_ENTRY(); - if (buf == NULL) + if (!buf) goto out; if (cmd->sg_buff_vmallocated) { @@ -9571,7 +9571,7 @@ static int scst_verify_dif_type1(struct scst_cmd *cmd) u8 *cur_buf = buf; for (i = 0; i < (len >> block_shift); i++) { - if (tags_buf == NULL) { + if (!tags_buf) { tags_buf = scst_get_dif_buf(cmd, &tags_sg, &tags_len); EXTRACHECKS_BUG_ON(tags_len <= 0); TRACE_DBG("tags_buf %p", tags_buf); @@ -9648,7 +9648,7 @@ next: len = scst_get_buf_next(cmd, &buf); } - EXTRACHECKS_BUG_ON(tags_buf != NULL); + EXTRACHECKS_BUG_ON(tags_buf); out: TRACE_EXIT_RES(res); @@ -9728,7 +9728,7 @@ static int scst_generate_dif_type1(struct scst_cmd *cmd) for (i = 0; i < (len >> block_shift); i++) { TRACE_DBG("lba %lld, tags_len %d", (long long)lba, tags_len); - if (tags_buf == NULL) { + if (!tags_buf) { tags_buf = scst_get_dif_buf(cmd, &tags_sg, &tags_len); TRACE_DBG("tags_sg %p, tags_buf %p, tags_len %d", tags_sg, tags_buf, tags_len); @@ -9894,7 +9894,7 @@ static int scst_generate_dif_type1(struct scst_cmd *cmd) len = scst_get_buf_next(cmd, &buf); } - EXTRACHECKS_BUG_ON(tags_buf != NULL); + EXTRACHECKS_BUG_ON(tags_buf); TRACE_EXIT_RES(res); return res; @@ -10007,7 +10007,7 @@ static int scst_verify_dif_type2(struct scst_cmd *cmd) u8 *cur_buf = buf; for (i = 0; i < (len >> block_shift); i++) { - if (tags_buf == NULL) { + if (!tags_buf) { tags_buf = scst_get_dif_buf(cmd, &tags_sg, &tags_len); EXTRACHECKS_BUG_ON(tags_len <= 0); t = (struct t10_pi_tuple *)tags_buf; @@ -10080,7 +10080,7 @@ next: len = scst_get_buf_next(cmd, &buf); } - EXTRACHECKS_BUG_ON(tags_buf != NULL); + EXTRACHECKS_BUG_ON(tags_buf); out: TRACE_EXIT_RES(res); @@ -10133,7 +10133,7 @@ static int scst_generate_dif_type2(struct scst_cmd *cmd) for (i = 0; i < (len >> block_shift); i++) { TRACE_DBG("tags_len %d", tags_len); - if (tags_buf == NULL) { + if (!tags_buf) { tags_buf = scst_get_dif_buf(cmd, &tags_sg, &tags_len); TRACE_DBG("tags_sg %p, tags_buf %p, tags_len %d", tags_sg, tags_buf, tags_len); @@ -10160,7 +10160,7 @@ static int scst_generate_dif_type2(struct scst_cmd *cmd) len = scst_get_buf_next(cmd, &buf); } - EXTRACHECKS_BUG_ON(tags_buf != NULL); + EXTRACHECKS_BUG_ON(tags_buf); TRACE_EXIT_RES(res); return res; @@ -10217,14 +10217,14 @@ static int scst_verify_dif_type3(struct scst_cmd *cmd) u8 *cur_buf = buf; for (i = 0; i < (len >> block_shift); i++) { - if (tags_buf == NULL) { + if (!tags_buf) { tags_buf = scst_get_dif_buf(cmd, &tags_sg, &tags_len); EXTRACHECKS_BUG_ON(tags_len <= 0); t = (struct t10_pi_tuple *)tags_buf; } - if ((t->app_tag == SCST_DIF_NO_CHECK_ALL_APP_TAG) && - (t->ref_tag == SCST_DIF_NO_CHECK_ALL_REF_TAG)) { + if (t->app_tag == SCST_DIF_NO_CHECK_ALL_APP_TAG && + t->ref_tag == SCST_DIF_NO_CHECK_ALL_REF_TAG) { TRACE_DBG("Skipping tag (cmd %p)", cmd); goto next; } @@ -10291,7 +10291,7 @@ next: len = scst_get_buf_next(cmd, &buf); } - EXTRACHECKS_BUG_ON(tags_buf != NULL); + EXTRACHECKS_BUG_ON(tags_buf); out: TRACE_EXIT_RES(res); @@ -10340,7 +10340,7 @@ static int scst_generate_dif_type3(struct scst_cmd *cmd) for (i = 0; i < (len >> block_shift); i++) { TRACE_DBG("tags_len %d", tags_len); - if (tags_buf == NULL) { + if (!tags_buf) { tags_buf = scst_get_dif_buf(cmd, &tags_sg, &tags_len); TRACE_DBG("tags_sg %p, tags_buf %p, tags_len %d", tags_sg, tags_buf, tags_len); @@ -10366,7 +10366,7 @@ static int scst_generate_dif_type3(struct scst_cmd *cmd) len = scst_get_buf_next(cmd, &buf); } - EXTRACHECKS_BUG_ON(tags_buf != NULL); + EXTRACHECKS_BUG_ON(tags_buf); TRACE_EXIT_RES(res); return res; @@ -10445,7 +10445,7 @@ static int scst_init_dif_actions(struct scst_device *dev) BUILD_BUG_ON(SCST_DIF_ACTION_NONE != 0); - if ((dev->dev_dif_type == 0) || (dev->dev_dif_mode == 0)) { + if (dev->dev_dif_type == 0 || dev->dev_dif_mode == 0) { dev->dev_dif_rd_actions = SCST_DIF_ACTION_NONE; dev->dev_dif_wr_actions = SCST_DIF_ACTION_NONE; dev->dev_dif_rd_prot0_actions = SCST_DIF_ACTION_NONE; @@ -10740,12 +10740,12 @@ int scst_set_dif_params(struct scst_device *dev, enum scst_dif_mode dif_mode, goto out; } - if ((dif_type < 0) || (dif_type > 3)) { + if (dif_type < 0 || dif_type > 3) { PRINT_ERROR("DIF type %d not supported", dif_type); goto out; } - if ((dif_mode == 0) && (dif_type != 0)) { + if (dif_mode == 0 && dif_type != 0) { PRINT_ERROR("With DIF mode 0 DIF type must be 0 (dev %s)", dev->virt_name); goto out; @@ -10782,7 +10782,7 @@ int scst_set_dif_params(struct scst_device *dev, enum scst_dif_mode dif_mode, break; } } else { - if ((dif_type == 1) && !(dif_mode & SCST_DIF_MODE_TGT)) + if (dif_type == 1 && !(dif_mode & SCST_DIF_MODE_TGT)) dev->dev_dif_fn = scst_dif_type1; else if ((dif_type == 1) && (dif_mode & SCST_DIF_MODE_TGT)) dev->dev_dif_fn = scst_dif_none_type1; @@ -10932,7 +10932,7 @@ static int scst_parse_rdprotect(struct scst_cmd *cmd) goto out; } - if (unlikely((dev->dev_dif_type == 2) && (rdprotect != 0))) { + if (unlikely(dev->dev_dif_type == 2 && rdprotect != 0)) { TRACE(TRACE_SCSI | TRACE_MINOR, "Non-32-byte CDBs with non-zero rdprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", rdprotect, dev->virt_name, cmd, scst_get_opcode_name(cmd)); @@ -10944,7 +10944,7 @@ static int scst_parse_rdprotect(struct scst_cmd *cmd) #ifdef CONFIG_SCST_DIF_INJECT_CORRUPTED_TAGS if (unlikely(cmd->cmd_corrupt_dif_tag != 0)) { - if ((cmd->dev->dev_dif_type == 1) && + if (cmd->dev->dev_dif_type == 1 && ((dev->dev_dif_mode & SCST_DIF_MODE_DEV_STORE) == 0)) { TRACE_DBG("cmd_corrupt_dif_tag %x, rdprotect %x, cmd %p", cmd->cmd_corrupt_dif_tag, rdprotect, cmd); @@ -11103,7 +11103,7 @@ static int scst_parse_wrprotect(struct scst_cmd *cmd) goto out; } - if (unlikely((dev->dev_dif_type == 2) && (wrprotect != 0))) { + if (unlikely(dev->dev_dif_type == 2 && wrprotect != 0)) { TRACE(TRACE_SCSI | TRACE_MINOR, "Non-32-byte CDBs with non-zero wrprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", wrprotect, dev->virt_name, cmd, scst_get_opcode_name(cmd)); @@ -11264,7 +11264,7 @@ static int scst_parse_vrprotect(struct scst_cmd *cmd) goto out; } - if (unlikely((dev->dev_dif_type == 2) && (vrprotect != 0))) { + if (unlikely(dev->dev_dif_type == 2 && vrprotect != 0)) { TRACE(TRACE_SCSI | TRACE_MINOR, "Non-32-byte CDBs with non-zero vrprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", vrprotect, dev->virt_name, cmd, scst_get_opcode_name(cmd)); @@ -11671,7 +11671,7 @@ static int get_cdb_info_lba_3_len_1_256_read(struct scst_cmd *cmd, else { const struct scst_device *dev = cmd->dev; - if ((dev->dev_dif_mode != SCST_DIF_MODE_NONE) && !dev->dpicz) + if (dev->dev_dif_mode != SCST_DIF_MODE_NONE && !dev->dpicz) cmd->cmd_dif_actions = dev->dev_dif_rd_prot0_actions | SCST_DIF_CHECK_GUARD_TAG | dev->dif_app_chk | SCST_DIF_CHECK_REF_TAG; @@ -12075,7 +12075,7 @@ static int get_cdb_info_var_len(struct scst_cmd *cmd, ptr = &scst_scsi_op32_table[i]; #if 0 /* not possible */ - if (unlikely(ptr == NULL)) + if (unlikely(!ptr)) goto out_unknown; #endif @@ -12237,7 +12237,7 @@ static int get_cdb_info_min(struct scst_cmd *cmd, case MI_REPORT_SUPPORTED_OPERATION_CODES: cmd->op_name = "REPORT SUPPORTED OPERATION CODES"; cmd->op_flags |= SCST_WRITE_EXCL_ALLOWED; - if (cmd->devt->get_supported_opcodes != NULL) + if (cmd->devt->get_supported_opcodes) cmd->op_flags |= SCST_LOCAL_CMD | SCST_FULLY_LOCAL_CMD; break; case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS: @@ -12327,7 +12327,7 @@ int scst_get_cdb_info(struct scst_cmd *cmd) i++; } - if (unlikely(ptr == NULL)) { + if (unlikely(!ptr)) { /* opcode not found or now not used */ TRACE(TRACE_MINOR, "Unknown opcode 0x%x for type %d", op, dev_type); @@ -13154,9 +13154,9 @@ void scst_process_reset(struct scst_device *dev, sess_cmd_list_entry) { if (cmd == exclude_cmd) continue; - if ((cmd->tgt_dev == tgt_dev) || - ((cmd->tgt_dev == NULL) && - (cmd->lun == tgt_dev->lun))) { + if (cmd->tgt_dev == tgt_dev || + (!cmd->tgt_dev && + cmd->lun == tgt_dev->lun)) { scst_abort_cmd(cmd, mcmd, (tgt_dev->sess != originator), 0); } @@ -13274,7 +13274,7 @@ again: goto again; } - if (buf == NULL) { + if (!buf) { if (scst_set_cmd_error_sense(cmd, UA_entry->UA_sense_buffer, UA_entry->UA_valid_sense_len) != 0) goto out_unlock; @@ -13366,7 +13366,7 @@ static void scst_alloc_set_UA(struct scst_tgt_dev *tgt_dev, TRACE_ENTRY(); UA_entry = mempool_alloc(scst_ua_mempool, GFP_ATOMIC); - if (UA_entry == NULL) { + if (!UA_entry) { PRINT_CRIT_ERROR("%s", "UNIT ATTENTION memory allocation failed. The UNIT ATTENTION on some sessions will be missed"); PRINT_BUFFER("Lost UA", sense, sense_len); goto out; @@ -13450,7 +13450,7 @@ void scst_dev_check_set_local_UA(struct scst_device *dev, TRACE_ENTRY(); - if (exclude != NULL) + if (exclude) exclude_tgt_dev = exclude->tgt_dev; list_for_each_entry(tgt_dev, &dev->dev_tgt_dev_list, @@ -13479,7 +13479,7 @@ static bool __scst_dev_check_set_UA(struct scst_device *dev, if (scst_analyze_sense(sense, sense_len, SCST_SENSE_ASC_VALID, 0, SCST_SENSE_ASC_UA_RESET, 0)) { scst_process_reset(dev, - (exclude != NULL) ? exclude->sess : NULL, + (exclude) ? exclude->sess : NULL, exclude, NULL, false); res = true; } @@ -13582,7 +13582,7 @@ restart: wake_up(&cmd->cmd_threads->cmd_list_waitQ); spin_unlock(&cmd->cmd_threads->cmd_list_lock); } else if ((cmd->sn == expected_sn) || !cmd->sn_set) { - bool stop = (cmd->sn_slot == NULL); + bool stop = (!cmd->sn_slot); TRACE_SN("Deferred command %p (sn %d, set %d) found", cmd, cmd->sn, cmd->sn_set); @@ -13737,7 +13737,7 @@ bool __scst_check_blocked_dev(struct scst_cmd *cmd) cmd, (unsigned long long)cmd->tag, scst_get_opcode_name(cmd), dev->virt_name); - if ((cmd->cdb[0] == MAINTENANCE_OUT) && + if (cmd->cdb[0] == MAINTENANCE_OUT && ((cmd->cdb[1] & 0x1f) == MO_SET_TARGET_PGS)) { const struct scst_cmd *c; /* @@ -13860,9 +13860,9 @@ int scst_obtain_device_parameters(struct scst_device *dev, TRACE_ENTRY(); - EXTRACHECKS_BUG_ON(dev->scsi_dev == NULL); + EXTRACHECKS_BUG_ON(!dev->scsi_dev); - if (mode_select_cdb != NULL) { + if (mode_select_cdb) { if ((mode_select_cdb[2] & 0x3F) != 0x0A) { TRACE_DBG("Not control mode page (%x) change requested, skipping", mode_select_cdb[2] & 0x3F); @@ -14041,9 +14041,9 @@ static void scst_abort_cmds_tgt_dev(struct scst_tgt_dev *tgt_dev, list_for_each_entry(cmd, &sess->sess_cmd_list, sess_cmd_list_entry) { if (cmd == exclude_cmd) continue; - if ((cmd->tgt_dev == tgt_dev) || - ((cmd->tgt_dev == NULL) && - (cmd->lun == tgt_dev->lun))) { + if (cmd->tgt_dev == tgt_dev || + (!cmd->tgt_dev && + cmd->lun == tgt_dev->lun)) { scst_abort_cmd(cmd, NULL, (tgt_dev != exclude_cmd->tgt_dev), 0); } } @@ -14083,7 +14083,7 @@ static void scst_abort_cmds_dev(struct scst_device *dev, * executed in parallel, you can't control exact order of UA * delivery anyway. */ - if (set_ua && (tgt_dev != exclude_cmd->tgt_dev)) + if (set_ua && tgt_dev != exclude_cmd->tgt_dev) scst_check_set_UA(tgt_dev, sense_buffer, sl, 0); } @@ -14163,9 +14163,9 @@ int scst_process_check_condition(struct scst_cmd *cmd) spin_lock_irq(&order_data->sn_lock); if (order_data->aca_tgt_dev != 0) { - if (((cmd->queue_type == SCST_CMD_QUEUE_ACA) && - (order_data->aca_tgt_dev == (unsigned long)cmd->tgt_dev)) || - ((cmd->cdb[0] == PERSISTENT_RESERVE_OUT) && + if ((cmd->queue_type == SCST_CMD_QUEUE_ACA && + order_data->aca_tgt_dev == (unsigned long)cmd->tgt_dev) || + (cmd->cdb[0] == PERSISTENT_RESERVE_OUT && ((cmd->cdb[1] & 0x1f) == PR_PREEMPT_AND_ABORT))) { if (!cmd->cmd_naca) { if (order_data->aca_cmd == cmd) { @@ -14292,7 +14292,7 @@ int scst_get_max_lun_commands(struct scst_session *sess, u64 lun) TRACE_ENTRY(); - if (sess == NULL) { + if (!sess) { struct scst_device *dev; mutex_lock(&scst_mutex); @@ -14366,7 +14366,7 @@ void scst_reassign_retained_sess_states(struct scst_session *new_sess, TRACE_MGMT_DBG("Reassigning retained states from old_sess %p to new_sess %p", old_sess, new_sess); - if ((new_sess == NULL) || (old_sess == NULL)) { + if (!new_sess || !old_sess) { TRACE_DBG("%s", "new_sess or old_sess is NULL"); goto out; } @@ -14376,8 +14376,8 @@ void scst_reassign_retained_sess_states(struct scst_session *new_sess, goto out; } - if ((new_sess->transport_id == NULL) || - (old_sess->transport_id == NULL)) { + if (!new_sess->transport_id || + !old_sess->transport_id) { TRACE_DBG("%s", "new_sess or old_sess doesn't support PRs"); goto out; } @@ -14395,17 +14395,17 @@ void scst_reassign_retained_sess_states(struct scst_session *new_sess, dev_tgt_dev_list_entry) { if (tgt_dev->sess == new_sess) { new_tgt_dev = tgt_dev; - if (old_tgt_dev != NULL) + if (old_tgt_dev) break; } if (tgt_dev->sess == old_sess) { old_tgt_dev = tgt_dev; - if (new_tgt_dev != NULL) + if (new_tgt_dev) break; } } - if ((new_tgt_dev == NULL) || (old_tgt_dev == NULL)) { + if (!new_tgt_dev || !old_tgt_dev) { TRACE_DBG("new_tgt_dev %p or old_sess %p is NULL, skipping (dev %s)", new_tgt_dev, old_tgt_dev, dev->virt_name); @@ -14424,20 +14424,20 @@ void scst_reassign_retained_sess_states(struct scst_session *new_sess, /** Reassign PRs **/ - if ((new_sess->transport_id == NULL) || - (old_sess->transport_id == NULL)) { + if (!new_sess->transport_id || + !old_sess->transport_id) { TRACE_DBG("%s", "new_sess or old_sess doesn't support PRs"); goto next; } scst_pr_write_lock(dev); - if (old_tgt_dev->registrant != NULL) { + if (old_tgt_dev->registrant) { TRACE_PR("Reassigning reg %p from tgt_dev %p to %p", old_tgt_dev->registrant, old_tgt_dev, new_tgt_dev); - if (new_tgt_dev->registrant != NULL) + if (new_tgt_dev->registrant) new_tgt_dev->registrant->tgt_dev = NULL; new_tgt_dev->registrant = old_tgt_dev->registrant; @@ -14450,7 +14450,7 @@ void scst_reassign_retained_sess_states(struct scst_session *new_sess, next: /** Reassign other DH specific states **/ - if (dev->handler->reassign_retained_states != NULL) { + if (dev->handler->reassign_retained_states) { TRACE_DBG("Calling dev's %s reassign_retained_states(%p, %p)", dev->virt_name, new_tgt_dev, old_tgt_dev); dev->handler->reassign_retained_states(new_tgt_dev, old_tgt_dev); @@ -14478,7 +14478,7 @@ char *scst_get_next_lexem(char **token_str) char *p, *q; static char blank = '\0'; - if ((token_str == NULL) || (*token_str == NULL)) + if (!token_str || (!*token_str)) return ␣ for (p = *token_str; (*p != '\0') && (isspace(*p) || (*p == '=')); p++) @@ -14548,7 +14548,7 @@ static int scst_parse_unmap_descriptors(struct scst_cmd *cmd) TRACE_ENTRY(); - EXTRACHECKS_BUG_ON(cmd->cmd_data_descriptors != NULL); + EXTRACHECKS_BUG_ON(cmd->cmd_data_descriptors); EXTRACHECKS_BUG_ON(cmd->cmd_data_descriptors_cnt != 0); total_len = get_unaligned_be16(&cmd->cdb[7]); @@ -14575,7 +14575,7 @@ static int scst_parse_unmap_descriptors(struct scst_cmd *cmd) goto out_put; pd = kzalloc_objs(*pd, cnt); - if (pd == NULL) { + if (!pd) { PRINT_ERROR("Unable to kmalloc UNMAP %d descriptors", cnt+1); scst_set_busy(cmd); goto out_abn_put; @@ -14777,8 +14777,8 @@ static int scst_restore_qerr(struct scst_device *dev, unsigned int val) TRACE_ENTRY(); - if ((val == SCST_QERR_2_RESERVED) || - (val > SCST_QERR_3_ABORT_THIS_NEXUS_ONLY)) { + if (val == SCST_QERR_2_RESERVED || + val > SCST_QERR_3_ABORT_THIS_NEXUS_ONLY) { PRINT_ERROR("Invalid value %d for parameter %s (device %s)", val, SCST_QERR_LABEL, dev->virt_name); res = -EINVAL; @@ -14908,8 +14908,8 @@ static int scst_restore_queue_alg(struct scst_device *dev, unsigned int val) TRACE_ENTRY(); - if ((val != SCST_QUEUE_ALG_0_RESTRICTED_REORDER) && - (val != SCST_QUEUE_ALG_1_UNRESTRICTED_REORDER)) { + if (val != SCST_QUEUE_ALG_0_RESTRICTED_REORDER && + val != SCST_QUEUE_ALG_1_UNRESTRICTED_REORDER) { PRINT_ERROR("Invalid value %d for parameter %s (device %s)", val, SCST_QUEUE_ALG_LABEL, dev->virt_name); res = -EINVAL; @@ -14941,7 +14941,7 @@ int scst_restore_global_mode_pages(struct scst_device *dev, char *params, while (1) { param = scst_get_next_token_str(¶ms); - if (param == NULL) + if (!param) break; p = scst_get_next_lexem(¶m); @@ -15284,7 +15284,7 @@ void scst_ext_unblock_dev(struct scst_device *dev, bool stpg) goto out_unlock; } - if ((dev->ext_blocks_cnt == 1) && dev->stpg_ext_blocked && !stpg) { + if (dev->ext_blocks_cnt == 1 && dev->stpg_ext_blocked && !stpg) { /* * User space is sending too many unblock calls during * STPG processing @@ -15300,7 +15300,7 @@ void scst_ext_unblock_dev(struct scst_device *dev, bool stpg) dev->virt_name, dev->ext_blocks_cnt, dev->ext_blocking_pending); - if ((dev->ext_blocks_cnt == 0) && dev->ext_blocking_pending) { + if (dev->ext_blocks_cnt == 0 && dev->ext_blocking_pending) { int rc; /* Wait pending ext blocking to finish */ spin_unlock_bh(&dev->dev_lock); @@ -15366,7 +15366,7 @@ int scst_copy_file(const char *src, const char *dest) TRACE_ENTRY(); - if (src == NULL || dest == NULL) { + if (!src || !dest) { res = -EINVAL; PRINT_ERROR("%s", "Invalid persistent files path - backup skipped"); goto out; @@ -15396,7 +15396,7 @@ int scst_copy_file(const char *src, const char *dest) } buf = vmalloc(file_size); - if (buf == NULL) { + if (!buf) { res = -ENOMEM; PRINT_ERROR("%s", "Unable to allocate temporary buffer"); goto out_skip; @@ -15466,7 +15466,7 @@ int scst_write_file_transactional(const char *name, const char *name1, TRACE_ENTRY(); res = scst_copy_file(name, name1); - if ((res != 0) && (res != -ENOENT)) + if (res != 0 && (res != -ENOENT)) goto out; file = filp_open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644); @@ -15809,7 +15809,7 @@ static void tm_dbg_init_tgt_dev(struct scst_tgt_dev *tgt_dev) if (tgt_dev->lun == 15) { unsigned long flags; - if (tm_dbg_tgt_dev != NULL) + if (tm_dbg_tgt_dev) tm_dbg_deinit_tgt_dev(tm_dbg_tgt_dev); spin_lock_irqsave(&scst_tm_dbg_lock, flags); @@ -15961,8 +15961,8 @@ int tm_dbg_check_cmd(struct scst_cmd *cmd) cmd->tm_dbg_immut = 1; tm_dbg_delayed_cmds_count--; - if ((tm_dbg_delayed_cmds_count == 0) && - (tm_dbg_state == TM_DBG_STATE_ABORT)) + if (tm_dbg_delayed_cmds_count == 0 && + tm_dbg_state == TM_DBG_STATE_ABORT) tm_dbg_change_state(&flags); spin_unlock_irqrestore(&scst_tm_dbg_lock, flags); } else if (cmd->tgt_dev && (tm_dbg_tgt_dev == cmd->tgt_dev)) { @@ -16024,8 +16024,8 @@ void tm_dbg_task_mgmt(struct scst_device *dev, const char *fn, int force) { unsigned long flags; - if (dev != NULL) { - if (tm_dbg_tgt_dev == NULL) + if (dev) { + if (!tm_dbg_tgt_dev) goto out; if (tm_dbg_tgt_dev->dev != dev) @@ -16033,7 +16033,7 @@ void tm_dbg_task_mgmt(struct scst_device *dev, const char *fn, int force) } spin_lock_irqsave(&scst_tm_dbg_lock, flags); - if ((tm_dbg_state != TM_DBG_STATE_OFFLINE) || force) { + if (tm_dbg_state != TM_DBG_STATE_OFFLINE || force) { TRACE_MGMT_DBG("%s: freeing %d delayed cmds", fn, tm_dbg_delayed_cmds_count); tm_dbg_change_state(&flags); @@ -16043,7 +16043,7 @@ void tm_dbg_task_mgmt(struct scst_device *dev, const char *fn, int force) * value. */ smp_wmb(); - if (tm_dbg_tgt_dev != NULL) + if (tm_dbg_tgt_dev) wake_up_all(&tm_dbg_tgt_dev->active_cmd_threads->cmd_list_waitQ); } else { TRACE_MGMT_DBG("%s: while OFFLINE state, doing nothing", fn); diff --git a/scst/src/scst_no_dlm.c b/scst/src/scst_no_dlm.c index 6bf7fc89e..4c82a275b 100644 --- a/scst/src/scst_no_dlm.c +++ b/scst/src/scst_no_dlm.c @@ -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; } diff --git a/usr/events/events.c b/usr/events/events.c index b6dad759c..788ac3eef 100644 --- a/usr/events/events.c +++ b/usr/events/events.c @@ -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] = '*'; } diff --git a/usr/fileio/common.c b/usr/fileio/common.c index f4063f673..8504f05f4 100644 --- a/usr/fileio/common.c +++ b/usr/fileio/common.c @@ -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) diff --git a/usr/fileio/fileio.c b/usr/fileio/fileio.c index 1725d9055..aefed300a 100644 --- a/usr/fileio/fileio.c +++ b/usr/fileio/fileio.c @@ -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; } diff --git a/usr/include/debug.c b/usr/include/debug.c index 1fa4c965b..d5d231429 100644 --- a/usr/include/debug.c +++ b/usr/include/debug.c @@ -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++] = '.';