Skip to content

Commit

Permalink
target: remove useless casts
Browse files Browse the repository at this point in the history
A reader should spend an extra moment whenever noticing a cast,
because either something special is going on that deserves extra
attention or, as is all too often the case, the code is wrong.

These casts, afaics, have all been useless.  They cast a foo* to a
foo*, cast a void* to the assigned type, cast a foo* to void*, before
assigning it to a void* variable, etc.

In a few cases I also removed an additional &...[0], which is equally
useless.

Lastly I added three FIXMEs where, to the best of my judgement, the
code appears to have a bug.  It would be good if someone could check
these.

Signed-off-by: Joern Engel <joern@logfs.org>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Jörn Engel authored and Nicholas Bellinger committed Dec 14, 2011
1 parent feae856 commit 8359cf4
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 101 deletions.
16 changes: 8 additions & 8 deletions drivers/target/iscsi/iscsi_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ static struct iscsi_np *iscsit_get_np(
sock_in6 = (struct sockaddr_in6 *)sockaddr;
sock_in6_e = (struct sockaddr_in6 *)&np->np_sockaddr;

if (!memcmp((void *)&sock_in6->sin6_addr.in6_u,
(void *)&sock_in6_e->sin6_addr.in6_u,
if (!memcmp(&sock_in6->sin6_addr.in6_u,
&sock_in6_e->sin6_addr.in6_u,
sizeof(struct in6_addr)))
ip_match = 1;

Expand Down Expand Up @@ -1224,7 +1224,7 @@ static void iscsit_do_crypto_hash_buf(

crypto_hash_init(hash);

sg_init_one(&sg, (u8 *)buf, payload_length);
sg_init_one(&sg, buf, payload_length);
crypto_hash_update(hash, &sg, payload_length);

if (padding) {
Expand Down Expand Up @@ -1602,7 +1602,7 @@ static int iscsit_handle_nop_out(
/*
* Attach ping data to struct iscsi_cmd->buf_ptr.
*/
cmd->buf_ptr = (void *)ping_data;
cmd->buf_ptr = ping_data;
cmd->buf_ptr_size = payload_length;

pr_debug("Got %u bytes of NOPOUT ping"
Expand Down Expand Up @@ -3196,7 +3196,7 @@ static int iscsit_build_sendtargets_response(struct iscsi_cmd *cmd)
end_of_buf = 1;
goto eob;
}
memcpy((void *)payload + payload_len, buf, len);
memcpy(payload + payload_len, buf, len);
payload_len += len;

spin_lock(&tiqn->tiqn_tpg_lock);
Expand Down Expand Up @@ -3228,7 +3228,7 @@ static int iscsit_build_sendtargets_response(struct iscsi_cmd *cmd)
end_of_buf = 1;
goto eob;
}
memcpy((void *)payload + payload_len, buf, len);
memcpy(payload + payload_len, buf, len);
payload_len += len;
}
spin_unlock(&tpg->tpg_np_lock);
Expand Down Expand Up @@ -3485,7 +3485,7 @@ int iscsi_target_tx_thread(void *arg)
struct iscsi_conn *conn;
struct iscsi_queue_req *qr = NULL;
struct se_cmd *se_cmd;
struct iscsi_thread_set *ts = (struct iscsi_thread_set *)arg;
struct iscsi_thread_set *ts = arg;
/*
* Allow ourselves to be interrupted by SIGINT so that a
* connection recovery / failure event can be triggered externally.
Expand Down Expand Up @@ -3774,7 +3774,7 @@ int iscsi_target_rx_thread(void *arg)
u8 buffer[ISCSI_HDR_LEN], opcode;
u32 checksum = 0, digest = 0;
struct iscsi_conn *conn = NULL;
struct iscsi_thread_set *ts = (struct iscsi_thread_set *)arg;
struct iscsi_thread_set *ts = arg;
struct kvec iov;
/*
* Allow ourselves to be interrupted by SIGINT so that a
Expand Down
28 changes: 14 additions & 14 deletions drivers/target/iscsi/iscsi_target_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static void chap_gen_challenge(
unsigned int *c_len)
{
unsigned char challenge_asciihex[CHAP_CHALLENGE_LENGTH * 2 + 1];
struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol;
struct iscsi_chap *chap = conn->auth_protocol;

memset(challenge_asciihex, 0, CHAP_CHALLENGE_LENGTH * 2 + 1);

Expand Down Expand Up @@ -120,7 +120,7 @@ static struct iscsi_chap *chap_server_open(
if (!conn->auth_protocol)
return NULL;

chap = (struct iscsi_chap *) conn->auth_protocol;
chap = conn->auth_protocol;
/*
* We only support MD5 MDA presently.
*/
Expand Down Expand Up @@ -172,7 +172,7 @@ static int chap_server_compute_md5(
unsigned char client_digest[MD5_SIGNATURE_SIZE];
unsigned char server_digest[MD5_SIGNATURE_SIZE];
unsigned char chap_n[MAX_CHAP_N_SIZE], chap_r[MAX_RESPONSE_LENGTH];
struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol;
struct iscsi_chap *chap = conn->auth_protocol;
struct crypto_hash *tfm;
struct hash_desc desc;
struct scatterlist sg;
Expand Down Expand Up @@ -246,23 +246,23 @@ static int chap_server_compute_md5(
goto out;
}

sg_init_one(&sg, (void *)&chap->id, 1);
sg_init_one(&sg, &chap->id, 1);
ret = crypto_hash_update(&desc, &sg, 1);
if (ret < 0) {
pr_err("crypto_hash_update() failed for id\n");
crypto_free_hash(tfm);
goto out;
}

sg_init_one(&sg, (void *)&auth->password, strlen(auth->password));
sg_init_one(&sg, &auth->password, strlen(auth->password));
ret = crypto_hash_update(&desc, &sg, strlen(auth->password));
if (ret < 0) {
pr_err("crypto_hash_update() failed for password\n");
crypto_free_hash(tfm);
goto out;
}

sg_init_one(&sg, (void *)chap->challenge, CHAP_CHALLENGE_LENGTH);
sg_init_one(&sg, chap->challenge, CHAP_CHALLENGE_LENGTH);
ret = crypto_hash_update(&desc, &sg, CHAP_CHALLENGE_LENGTH);
if (ret < 0) {
pr_err("crypto_hash_update() failed for challenge\n");
Expand Down Expand Up @@ -304,11 +304,11 @@ static int chap_server_compute_md5(
goto out;
}

/* FIXME: What happens when simple_strtoul() return 256, 257, etc.? */
if (type == HEX)
id = (unsigned char)simple_strtoul((char *)&identifier[2],
&endptr, 0);
id = simple_strtoul(&identifier[2], &endptr, 0);
else
id = (unsigned char)simple_strtoul(identifier, &endptr, 0);
id = simple_strtoul(identifier, &endptr, 0);
/*
* RFC 1994 says Identifier is no more than octet (8 bits).
*/
Expand Down Expand Up @@ -351,15 +351,15 @@ static int chap_server_compute_md5(
goto out;
}

sg_init_one(&sg, (void *)&id, 1);
sg_init_one(&sg, &id, 1);
ret = crypto_hash_update(&desc, &sg, 1);
if (ret < 0) {
pr_err("crypto_hash_update() failed for id\n");
crypto_free_hash(tfm);
goto out;
}

sg_init_one(&sg, (void *)auth->password_mutual,
sg_init_one(&sg, auth->password_mutual,
strlen(auth->password_mutual));
ret = crypto_hash_update(&desc, &sg, strlen(auth->password_mutual));
if (ret < 0) {
Expand All @@ -371,7 +371,7 @@ static int chap_server_compute_md5(
/*
* Convert received challenge to binary hex.
*/
sg_init_one(&sg, (void *)challenge_binhex, challenge_len);
sg_init_one(&sg, challenge_binhex, challenge_len);
ret = crypto_hash_update(&desc, &sg, challenge_len);
if (ret < 0) {
pr_err("crypto_hash_update() failed for ma challenge\n");
Expand Down Expand Up @@ -414,7 +414,7 @@ static int chap_got_response(
char *nr_out_ptr,
unsigned int *nr_out_len)
{
struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol;
struct iscsi_chap *chap = conn->auth_protocol;

switch (chap->digest_type) {
case CHAP_DIGEST_MD5:
Expand All @@ -437,7 +437,7 @@ u32 chap_main_loop(
int *in_len,
int *out_len)
{
struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol;
struct iscsi_chap *chap = conn->auth_protocol;

if (!chap) {
chap = chap_server_open(conn, auth, in_text, out_text, out_len);
Expand Down
5 changes: 2 additions & 3 deletions drivers/target/iscsi/iscsi_target_configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ struct iscsi_portal_group *lio_get_tpg_from_tpg_item(
{
struct se_portal_group *se_tpg = container_of(to_config_group(item),
struct se_portal_group, tpg_group);
struct iscsi_portal_group *tpg =
(struct iscsi_portal_group *)se_tpg->se_tpg_fabric_ptr;
struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
int ret;

if (!tpg) {
Expand Down Expand Up @@ -1221,7 +1220,7 @@ struct se_portal_group *lio_target_tiqn_addtpg(

ret = core_tpg_register(
&lio_target_fabric_configfs->tf_ops,
wwn, &tpg->tpg_se_tpg, (void *)tpg,
wwn, &tpg->tpg_se_tpg, tpg,
TRANSPORT_TPG_TYPE_NORMAL);
if (ret < 0)
return NULL;
Expand Down
21 changes: 11 additions & 10 deletions drivers/target/iscsi/iscsi_target_login.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ int iscsi_check_for_session_reinstatement(struct iscsi_conn *conn)
list_for_each_entry_safe(se_sess, se_sess_tmp, &se_tpg->tpg_sess_list,
sess_list) {

sess_p = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess_p = se_sess->fabric_sess_ptr;
spin_lock(&sess_p->conn_lock);
if (atomic_read(&sess_p->session_fall_back_to_erl0) ||
atomic_read(&sess_p->session_logout) ||
(sess_p->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
spin_unlock(&sess_p->conn_lock);
continue;
}
if (!memcmp((void *)sess_p->isid, (void *)conn->sess->isid, 6) &&
(!strcmp((void *)sess_p->sess_ops->InitiatorName,
(void *)initiatorname_param->value) &&
if (!memcmp(sess_p->isid, conn->sess->isid, 6) &&
(!strcmp(sess_p->sess_ops->InitiatorName,
initiatorname_param->value) &&
(sess_p->sess_ops->SessionType == sessiontype))) {
atomic_set(&sess_p->session_reinstatement, 1);
spin_unlock(&sess_p->conn_lock);
Expand Down Expand Up @@ -229,7 +229,7 @@ static int iscsi_login_zero_tsih_s1(

iscsi_login_set_conn_values(sess, conn, pdu->cid);
sess->init_task_tag = pdu->itt;
memcpy((void *)&sess->isid, (void *)pdu->isid, 6);
memcpy(&sess->isid, pdu->isid, 6);
sess->exp_cmd_sn = pdu->cmdsn;
INIT_LIST_HEAD(&sess->sess_conn_list);
INIT_LIST_HEAD(&sess->sess_ooo_cmdsn_list);
Expand Down Expand Up @@ -440,8 +440,7 @@ static int iscsi_login_non_zero_tsih_s2(
atomic_read(&sess_p->session_logout) ||
(sess_p->time2retain_timer_flags & ISCSI_TF_EXPIRED))
continue;
if (!memcmp((const void *)sess_p->isid,
(const void *)pdu->isid, 6) &&
if (!memcmp(sess_p->isid, pdu->isid, 6) &&
(sess_p->tsih == pdu->tsih)) {
iscsit_inc_session_usage_count(sess_p);
iscsit_stop_time2retain_timer(sess_p);
Expand Down Expand Up @@ -654,7 +653,7 @@ static int iscsi_post_login_handler(

spin_lock_bh(&se_tpg->session_lock);
__transport_register_session(&sess->tpg->tpg_se_tpg,
se_sess->se_node_acl, se_sess, (void *)sess);
se_sess->se_node_acl, se_sess, sess);
pr_debug("Moving to TARG_SESS_STATE_LOGGED_IN.\n");
sess->session_state = TARG_SESS_STATE_LOGGED_IN;

Expand Down Expand Up @@ -811,7 +810,7 @@ int iscsi_target_setup_login_socket(
* Setup the np->np_sockaddr from the passed sockaddr setup
* in iscsi_target_configfs.c code..
*/
memcpy((void *)&np->np_sockaddr, (void *)sockaddr,
memcpy(&np->np_sockaddr, sockaddr,
sizeof(struct __kernel_sockaddr_storage));

if (sockaddr->ss_family == AF_INET6)
Expand All @@ -821,6 +820,7 @@ int iscsi_target_setup_login_socket(
/*
* Set SO_REUSEADDR, and disable Nagel Algorithm with TCP_NODELAY.
*/
/* FIXME: Someone please explain why this is endian-safe */
opt = 1;
if (np->np_network_transport == ISCSI_TCP) {
ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
Expand All @@ -832,6 +832,7 @@ int iscsi_target_setup_login_socket(
}
}

/* FIXME: Someone please explain why this is endian-safe */
ret = kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char *)&opt, sizeof(opt));
if (ret < 0) {
Expand Down Expand Up @@ -1206,7 +1207,7 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)

int iscsi_target_login_thread(void *arg)
{
struct iscsi_np *np = (struct iscsi_np *)arg;
struct iscsi_np *np = arg;
int ret;

allow_signal(SIGINT);
Expand Down
2 changes: 1 addition & 1 deletion drivers/target/iscsi/iscsi_target_nego.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ static void iscsi_initiatorname_tolower(
u32 iqn_size = strlen(param_buf), i;

for (i = 0; i < iqn_size; i++) {
c = (char *)&param_buf[i];
c = &param_buf[i];
if (!isupper(*c))
continue;

Expand Down
2 changes: 1 addition & 1 deletion drivers/target/iscsi/iscsi_target_nodeattrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extern int iscsit_na_nopin_timeout(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;

spin_lock(&sess->conn_lock);
list_for_each_entry(conn, &sess->sess_conn_list,
Expand Down
16 changes: 8 additions & 8 deletions drivers/target/iscsi/iscsi_target_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ static ssize_t iscsi_stat_sess_show_attr_node(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%u\n",
sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
Expand All @@ -769,7 +769,7 @@ static ssize_t iscsi_stat_sess_show_attr_indx(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%u\n",
sess->session_index);
Expand All @@ -793,7 +793,7 @@ static ssize_t iscsi_stat_sess_show_attr_cmd_pdus(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%u\n", sess->cmd_pdus);
}
Expand All @@ -816,7 +816,7 @@ static ssize_t iscsi_stat_sess_show_attr_rsp_pdus(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%u\n", sess->rsp_pdus);
}
Expand All @@ -839,7 +839,7 @@ static ssize_t iscsi_stat_sess_show_attr_txdata_octs(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%llu\n",
(unsigned long long)sess->tx_data_octets);
Expand All @@ -863,7 +863,7 @@ static ssize_t iscsi_stat_sess_show_attr_rxdata_octs(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%llu\n",
(unsigned long long)sess->rx_data_octets);
Expand All @@ -887,7 +887,7 @@ static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%u\n",
sess->conn_digest_errors);
Expand All @@ -911,7 +911,7 @@ static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors(
spin_lock_bh(&se_nacl->nacl_sess_lock);
se_sess = se_nacl->nacl_sess;
if (se_sess) {
sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
sess = se_sess->fabric_sess_ptr;
if (sess)
ret = snprintf(page, PAGE_SIZE, "%u\n",
sess->conn_timeout_errors);
Expand Down
2 changes: 1 addition & 1 deletion drivers/target/iscsi/iscsi_target_tpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int iscsit_load_discovery_tpg(void)

ret = core_tpg_register(
&lio_target_fabric_configfs->tf_ops,
NULL, &tpg->tpg_se_tpg, (void *)tpg,
NULL, &tpg->tpg_se_tpg, tpg,
TRANSPORT_TPG_TYPE_DISCOVERY);
if (ret < 0) {
kfree(tpg);
Expand Down
4 changes: 2 additions & 2 deletions drivers/target/iscsi/iscsi_target_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ struct iscsi_cmd *iscsit_allocate_se_cmd_for_tmr(
}

se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd,
(void *)cmd->tmr_req, tcm_function,
cmd->tmr_req, tcm_function,
GFP_KERNEL);
if (!se_cmd->se_tmr_req)
goto out;
Expand Down Expand Up @@ -1064,7 +1064,7 @@ static void iscsit_handle_nopin_response_timeout(unsigned long data)
if (tiqn) {
spin_lock_bh(&tiqn->sess_err_stats.lock);
strcpy(tiqn->sess_err_stats.last_sess_fail_rem_name,
(void *)conn->sess->sess_ops->InitiatorName);
conn->sess->sess_ops->InitiatorName);
tiqn->sess_err_stats.last_sess_failure_type =
ISCSI_SESS_ERR_CXN_TIMEOUT;
tiqn->sess_err_stats.cxn_timeout_errors++;
Expand Down
Loading

0 comments on commit 8359cf4

Please sign in to comment.