From: Chi Pham Date: Sun, 9 Mar 2014 11:51:19 +0000 (+0100) Subject: staging:lustre: Removed assignments from if statements. X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=4a87df3ef82f4eda9a36e2af8494607d6a830a81;p=linux-beck.git staging:lustre: Removed assignments from if statements. Fixed some minor checkpatch warnings such as whitespace. Coccinelle was used for this patch (NOTE: some of the changes were made by hand). The script is not complete (semantically) and might raise some checkpatch warnings in terms of indentation depending on existing code. *** IFASSIGNMENT.COCCI START *** /* Coccinelle script to handle assignments in if statements * For compound statements, can so far only handle statements with the * assignment on either extreme */ /* This rule is for simple cases * e.g. just an assignment in if, possibly with unary operator */ @simple@ expression E1, E2; statement S1, S2; @@ + E1 = E2; if ( - (E1 = E2) + E1 ) S1 else S2 /* This rule is for compound statements where the assignment is on the right.*/ @right@ expression E, E1, E2; statement S1, S2; @@ ( /* and */ - if (E && (E1 = E2)) + if (E) { + E1 = E2; + if (E1) S1 else S2 + } else S2 | - if (E && (E1 = E2)) + if (E) { + E1 = E2; + if (E1) S1 + } /* or */ | - if (E || (E1 = E2)) + if (!E) { + E1 = E2; + if (E1) S1 else S2 + } + else S1 | - if (E || (E1 = E2)) + if (!E) { + E1 = E2; + if (E1) S1 + } else S1 /* not equal */ | - if (E != (E1 = E2)) + E1 = E2; + if (E != E1) S1 else S2 | - if (E != (E1 = E2)) + E1 = E2; + if (E != E1) S1 /* equal */ | - if (E == (E1 = E2)) + E1 = E2; + if (E == E1) S1 else S2 | - if (E == (E1 = E2)) + E1 = E2; + if (E == E1) S1 /* greater than */ | - if (E > (E1 = E2)) + E1 = E2; + if (E > E1) S1 else S2 | - if (E > (E1 = E2)) + E1 = E2; + if (E > E1) S1 /* less than */ | - if (E < (E1 = E2)) + E1 = E2; + if (E < E1) S1 else S2 | - if (E < (E1 = E2)) + E1 = E2; + if (E < E1) S1 /* lesser than or equal to */ | - if (E <= (E1 = E2)) + E1 = E2; + if (E <= E1) S1 else S2 | - if (E <= (E1 = E2)) + E1 = E2; + if (E <= E1) S1 /* greater than or equal to */ | - if (E >= (E1 = E2)) + E1 = E2; + if (E >= E1) S1 else S2 | - if (E >= (E1 = E2)) + E1 = E2; + if (E >= E1) S1 ) /* This rule is for compound statements where the assignment is on the left.*/ @left@ expression E, E1, E2; statement S1, S2; @@ ( /* and */ - if ((E1 = E2) && E) + E1 = E2; + if (E1 && E) S1 else S2 | - if ((E1 = E2) && E) + E1 = E2; + if (E1 && E) S1 | /* or */ - if ((E1 = E2) || E) + E1 = E2; + if (E1 || E) S1 | - if ((E1 = E2) || E) + E1 = E2; + if (E1 || E) S1 else S2 | /* not equal */ - if ((E1 = E2) != E) + E1 = E2; + if (E1 != E) S1 | - if ((E1 = E2) != E) + E1 = E2; + if (E1 != E) S1 else S2 | /* equal */ - if ((E1 = E2) == E) + E1 = E2; + if (E1 == E) S1 | - if ((E1 = E2) == E) + E1 = E2; + if (E1 == E) S1 else S2 | /* greater */ - if ((E1 = E2) > E) + E1 = E2; + if (E1 > E) S1 | - if ((E1 = E2) > E) + E1 = E2; + if (E1 > E) S1 else S2 | /* less */ - if ((E1 = E2) < E) + E1 = E2; + if (E1 < E) S1 | - if ((E1 = E2) < E) + E1 = E2; + if (E1 < E) S1 else S2 /* lesser than or equal to */ - if ((E1 = E2) <= E) + E1 = E2; + if (E1 <= E) S1 | - if ((E1 = E2) <= E) + E1 = E2; + if (E1 <= E) S1 else S2 /* greater than or equal to */ - if ((E1 = E2) >= E) + E1 = E2; + if (E1 >= E) S1 | - if ((E1 = E2) >= E) + E1 = E2; + if (E1 >= E) S1 else S2 ) *** IFASSIGNMENT.COCCI END *** Signed-off-by: Chi Pham Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib-linux.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib-linux.c index 80141aa32c21..a54b506ba7ca 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib-linux.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib-linux.c @@ -373,7 +373,8 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn) /* NB we can't trust socket ops to either consume our iovs * or leave them alone. */ - if ((addr = ksocknal_lib_kiov_vmap(kiov, niov, scratchiov, pages)) != NULL) { + addr = ksocknal_lib_kiov_vmap(kiov, niov, scratchiov, pages); + if (addr != NULL) { nob = scratchiov[0].iov_len; msg.msg_iovlen = 1; diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c index 71205e2015ce..2d91571cbab2 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c @@ -165,7 +165,8 @@ ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn, LASSERT (tx_ack == NULL || tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP); - if ((tx = conn->ksnc_tx_carrier) == NULL) { + tx = conn->ksnc_tx_carrier; + if (tx == NULL) { if (tx_ack != NULL) { list_add_tail(&tx_ack->tx_list, &conn->ksnc_tx_queue); @@ -392,7 +393,8 @@ ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote) if (tx == NULL) return -ENOMEM; - if ((rc = ksocknal_launch_packet(peer->ksnp_ni, tx, peer->ksnp_id)) == 0) + rc = ksocknal_launch_packet(peer->ksnp_ni, tx, peer->ksnp_id); + if (rc == 0) return 0; ksocknal_free_tx(tx); diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c index 6d0bd220d53d..77e10384c0d0 100644 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c @@ -58,7 +58,8 @@ void cfs_cap_raise(cfs_cap_t cap) { struct cred *cred; - if ((cred = prepare_creds())) { + cred = prepare_creds(); + if (cred) { cap_raise(cred->cap_effective, cap); commit_creds(cred); } @@ -67,7 +68,8 @@ void cfs_cap_raise(cfs_cap_t cap) void cfs_cap_lower(cfs_cap_t cap) { struct cred *cred; - if ((cred = prepare_creds())) { + cred = prepare_creds(); + if (cred) { cap_lower(cred->cap_effective, cap); commit_creds(cred); } diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 05e6cd65142b..26003d3c1be7 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -734,7 +734,8 @@ char *ll_read_opt(const char *opt, char *data) CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data); if (strncmp(opt, data, strlen(opt))) return NULL; - if ((value = strchr(data, '=')) == NULL) + value = strchr(data, '='); + if (value == NULL) return NULL; value++; diff --git a/drivers/staging/lustre/lustre/lov/lov_pack.c b/drivers/staging/lustre/lustre/lov/lov_pack.c index 27ed27e6fa6a..74200cf1b331 100644 --- a/drivers/staging/lustre/lustre/lov/lov_pack.c +++ b/drivers/staging/lustre/lustre/lov/lov_pack.c @@ -339,7 +339,8 @@ int lov_free_memmd(struct lov_stripe_md **lsmp) *lsmp = NULL; LASSERT(atomic_read(&lsm->lsm_refc) > 0); - if ((refc = atomic_dec_return(&lsm->lsm_refc)) == 0) { + refc = atomic_dec_return(&lsm->lsm_refc); + if (refc == 0) { LASSERT(lsm_op_find(lsm->lsm_magic) != NULL); lsm_op_find(lsm->lsm_magic)->lsm_free(lsm); } diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c index d9ddb3934919..bde9f93c149b 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c @@ -1574,8 +1574,8 @@ static int mdc_changelog_send_thread(void *csdata) rc = llog_cat_process(NULL, llh, changelog_kkuc_cb, cs, 0, 0); /* Send EOF no matter what our result */ - if ((kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch), - cs->cs_flags))) { + kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch), cs->cs_flags); + if (kuch) { kuch->kuc_msgtype = CL_EOF; libcfs_kkuc_msg_put(cs->cs_fp, kuch); } @@ -1697,11 +1697,16 @@ static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp, if (rc) CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc); - if (req->rq_repmsg && - (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) { - *oqctl = *oqc; + if (req->rq_repmsg) { + oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL); + if (oqc) { + *oqctl = *oqc; + } else if (!rc) { + CERROR ("Can't unpack obd_quotactl\n"); + rc = -EPROTO; + } } else if (!rc) { - CERROR ("Can't unpack obd_quotactl\n"); + CERROR("Can't unpack obd_quotactl\n"); rc = -EPROTO; } ptlrpc_req_finished(req); diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c index 2cdfa21638e2..2d5777699f47 100644 --- a/drivers/staging/lustre/lustre/obdclass/obd_config.c +++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c @@ -61,7 +61,8 @@ int class_find_param(char *buf, char *key, char **valp) if (!buf) return 1; - if ((ptr = strstr(buf, key)) == NULL) + ptr = strstr(buf, key); + if (ptr == NULL) return 1; if (valp) diff --git a/drivers/staging/lustre/lustre/osc/osc_quota.c b/drivers/staging/lustre/lustre/osc/osc_quota.c index f395ae4ec944..0235fabaaffe 100644 --- a/drivers/staging/lustre/lustre/osc/osc_quota.c +++ b/drivers/staging/lustre/lustre/osc/osc_quota.c @@ -265,11 +265,16 @@ int osc_quotactl(struct obd_device *unused, struct obd_export *exp, if (rc) CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc); - if (req->rq_repmsg && - (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) { - *oqctl = *oqc; + if (req->rq_repmsg) { + oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL); + if (oqc) { + *oqctl = *oqc; + } else if (!rc) { + CERROR("Can't unpack obd_quotactl\n"); + rc = -EPROTO; + } } else if (!rc) { - CERROR ("Can't unpack obd_quotactl\n"); + CERROR("Can't unpack obd_quotactl\n"); rc = -EPROTO; } ptlrpc_req_finished(req); diff --git a/drivers/staging/lustre/lustre/ptlrpc/gss/gss_generic_token.c b/drivers/staging/lustre/lustre/ptlrpc/gss/gss_generic_token.c index 56c28286c9c1..8dc5c724958d 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/gss/gss_generic_token.c +++ b/drivers/staging/lustre/lustre/ptlrpc/gss/gss_generic_token.c @@ -144,7 +144,8 @@ int der_read_length(unsigned char **buf, int *bufsize) sf = *(*buf)++; (*bufsize)--; if (sf & 0x80) { - if ((sf &= 0x7f) > ((*bufsize) - 1)) + sf &= 0x7f; + if (((*bufsize) - 1) < sf) return -1; if (sf > SIZEOF_INT) return -1; @@ -199,27 +200,32 @@ __u32 g_verify_token_header(rawobj_t *mech, int *body_size, rawobj_t toid; int ret = 0; - if ((toksize -= 1) < 0) + toksize -= 1; + if (0 > toksize) return (G_BAD_TOK_HEADER); if (*buf++ != 0x60) return (G_BAD_TOK_HEADER); - if ((seqsize = der_read_length(&buf, &toksize)) < 0) + seqsize = der_read_length(&buf, &toksize); + if (seqsize < 0) return(G_BAD_TOK_HEADER); if (seqsize != toksize) return (G_BAD_TOK_HEADER); - if ((toksize -= 1) < 0) + toksize -= 1; + if (0 > toksize) return (G_BAD_TOK_HEADER); if (*buf++ != 0x06) return (G_BAD_TOK_HEADER); - if ((toksize -= 1) < 0) + toksize -= 1; + if (0 > toksize) return (G_BAD_TOK_HEADER); toid.len = *buf++; - if ((toksize -= toid.len) < 0) + toksize -= toid.len; + if (0 > toksize) return (G_BAD_TOK_HEADER); toid.data = buf; buf += toid.len; @@ -231,7 +237,8 @@ __u32 g_verify_token_header(rawobj_t *mech, int *body_size, * important to return G_BAD_TOK_HEADER if the token header is * in fact bad */ - if ((toksize -= 2) < 0) + toksize -= 2; + if (0 > toksize) return (G_BAD_TOK_HEADER); if (ret) @@ -256,24 +263,29 @@ __u32 g_get_mech_oid(rawobj_t *mech, rawobj_t *in_buf) int ret = 0; int seqsize; - if ((len -= 1) < 0) + len -= 1; + if (0 > len) return (G_BAD_TOK_HEADER); if (*buf++ != 0x60) return (G_BAD_TOK_HEADER); - if ((seqsize = der_read_length(&buf, &len)) < 0) + seqsize = der_read_length(&buf, &len); + if (seqsize < 0) return (G_BAD_TOK_HEADER); - if ((len -= 1) < 0) + len -= 1; + if (0 > len) return (G_BAD_TOK_HEADER); if (*buf++ != 0x06) return (G_BAD_TOK_HEADER); - if ((len -= 1) < 0) + len -= 1; + if (0 > len) return (G_BAD_TOK_HEADER); mech->len = *buf++; - if ((len -= mech->len) < 0) + len -= mech->len; + if (0 > len) return (G_BAD_TOK_HEADER); OBD_ALLOC_LARGE(mech->data, mech->len); if (!mech->data)