<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-10-18 11:26 GMT+03:00 Cristina Georgiana Opriceana <span dir="ltr"><<a href="mailto:cristina.opriceana@gmail.com" target="_blank">cristina.opriceana@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>On Sun, Oct 18, 2015 at 2:00 AM, Cristina Moraru<br>
<<a href="mailto:cristina.moraru09@gmail.com" target="_blank">cristina.moraru09@gmail.com</a>> wrote:<br>
><br>
> Remove explicit comparisons with 0 or NULL in order to<br>
> provide efficiency.<br>
<br>
</span>Did you do this with coccinelle? In case you did not, you might<br>
consider something like this to do the replacement:<br>
<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
@replace_rule@<br>
identifier e;<br>
@@<br>
<br>
(<br>
- e == 0<br>
+ !e<br>
|<br>
- e == NULL<br>
+ !e<br>
)<br>
<div><div><br></div></div></blockquote><div><br>I wrote a similar script but with 'expression' keyword instead of 
'identifier' and could not be applied because of one line 
in file: int stopped = !!(rq_state & RQ_STOP); that confused 
coccinelle parsing and produced an error. Now it works. Thanks !<br> <br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>
> Signed-off-by: Cristina Moraru <<a href="mailto:cristina.moraru09@gmail.com" target="_blank">cristina.moraru09@gmail.com</a>><br>
> ---<br>
>  drivers/staging/lustre/lustre/mgc/mgc_request.c | 60 ++++++++++++-------------<br>
>  1 file changed, 30 insertions(+), 30 deletions(-)<br>
><br>
> diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c<br>
> index 780ea81..ab8c5fa 100644<br>
> --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c<br>
> +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c<br>
> @@ -172,7 +172,7 @@ struct config_llog_data *config_log_find(char *logname,<br>
>                         continue;<br>
><br>
>                 /* instance may be NULL, should check name */<br>
> -               if (strcmp(logname, cld->cld_logname) == 0) {<br>
> +               if (!strcmp(logname, cld->cld_logname)) {<br>
>                         found = cld;<br>
>                         break;<br>
>                 }<br>
> @@ -300,7 +300,7 @@ static int config_log_add(struct obd_device *obd, char *logname,<br>
>          * <fsname>-sptlrpc. multiple regular logs may share one sptlrpc log.<br>
>          */<br>
>         ptr = strrchr(logname, '-');<br>
> -       if (ptr == NULL || ptr - logname > 8) {<br>
> +       if (!ptr || ptr - logname > 8) {<br>
>                 CERROR("logname %s is too long\n", logname);<br>
>                 return -EINVAL;<br>
>         }<br>
> @@ -309,7 +309,7 @@ static int config_log_add(struct obd_device *obd, char *logname,<br>
>         strcpy(seclogname + (ptr - logname), "-sptlrpc");<br>
><br>
>         sptlrpc_cld = config_log_find(seclogname, NULL);<br>
> -       if (sptlrpc_cld == NULL) {<br>
> +       if (!sptlrpc_cld) {<br>
>                 sptlrpc_cld = do_config_log_add(obd, seclogname,<br>
>                                                 CONFIG_T_SPTLRPC, NULL, NULL);<br>
>                 if (IS_ERR(sptlrpc_cld)) {<br>
> @@ -376,7 +376,7 @@ static int config_log_end(char *logname, struct config_llog_instance *cfg)<br>
>         int rc = 0;<br>
><br>
>         cld = config_log_find(logname, cfg);<br>
> -       if (cld == NULL)<br>
> +       if (!cld)<br>
>                 return -ENOENT;<br>
><br>
>         mutex_lock(&cld->cld_lock);<br>
> @@ -451,7 +451,7 @@ int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)<br>
><br>
>         spin_lock(&config_list_lock);<br>
>         list_for_each_entry(cld, &config_llog_list, cld_list_chain) {<br>
> -               if (cld->cld_recover == NULL)<br>
> +               if (!cld->cld_recover)<br>
>                         continue;<br>
>                 seq_printf(m,  "    - { client: %s, nidtbl_version: %u }\n",<br>
>                                cld->cld_logname,<br>
> @@ -482,7 +482,7 @@ static void do_requeue(struct config_llog_data *cld)<br>
>            export which is being disconnected. Take the client<br>
>            semaphore to make the check non-racy. */<br>
>         down_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);<br>
> -       if (cld->cld_mgcexp->exp_obd->u.cli.cl_conn_count != 0) {<br>
> +       if (cld->cld_mgcexp->exp_obd->u.cli.cl_conn_count) {<br>
>                 CDEBUG(D_MGC, "updating log %s\n", cld->cld_logname);<br>
>                 mgc_process_log(cld->cld_mgcexp->exp_obd, cld);<br>
>         } else {<br>
> @@ -683,7 +683,7 @@ static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)<br>
>                         wait_for_completion(&rq_exit);<br>
>                 obd_cleanup_client_import(obd);<br>
>                 rc = mgc_llog_fini(NULL, obd);<br>
> -               if (rc != 0)<br>
> +               if (rc)<br>
>                         CERROR("failed to cleanup llogging subsystems\n");<br>
>                 break;<br>
>         }<br>
> @@ -879,7 +879,7 @@ static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,<br>
>         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),<br>
>                                         &RQF_LDLM_ENQUEUE, LUSTRE_DLM_VERSION,<br>
>                                         LDLM_ENQUEUE);<br>
> -       if (req == NULL)<br>
> +       if (!req)<br>
>                 return -ENOMEM;<br>
><br>
>         req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER, 0);<br>
> @@ -917,7 +917,7 @@ static int mgc_target_register(struct obd_export *exp,<br>
>         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),<br>
>                                         &RQF_MGS_TARGET_REG, LUSTRE_MGS_VERSION,<br>
>                                         MGS_TARGET_REG);<br>
> -       if (req == NULL)<br>
> +       if (!req)<br>
>                 return -ENOMEM;<br>
><br>
>         req_mti = req_capsule_client_get(&req->rq_pill, &RMF_MGS_TARGET_INFO);<br>
> @@ -988,7 +988,7 @@ static int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,<br>
>                  * if flavor has been set previously, check the asking flavor<br>
>                  * must match the existing one.<br>
>                  */<br>
> -               if (vallen == 0) {<br>
> +               if (!vallen) {<br>
>                         if (cli->cl_flvr_mgc.sf_rpc != SPTLRPC_FLVR_INVALID)<br>
>                                 return 0;<br>
>                         val = "null";<br>
> @@ -1008,7 +1008,7 @@ static int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,<br>
>                 if (cli->cl_flvr_mgc.sf_rpc == SPTLRPC_FLVR_INVALID) {<br>
>                         cli->cl_flvr_mgc = flvr;<br>
>                 } else if (memcmp(&cli->cl_flvr_mgc, &flvr,<br>
> -                                 sizeof(flvr)) != 0) {<br>
> +                                 sizeof(flvr))) {<br>
>                         char    str[20];<br>
><br>
>                         sptlrpc_flavor2name(&cli->cl_flvr_mgc,<br>
> @@ -1138,9 +1138,9 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,<br>
>                 entry = (typeof(entry))(data + off);<br>
><br>
>                 /* sanity check */<br>
> -               if (entry->mne_nid_type != 0) /* only support type 0 for ipv4 */<br>
> +               if (entry->mne_nid_type) /* only support type 0 for ipv4 */<br>
>                         break;<br>
> -               if (entry->mne_nid_count == 0) /* at least one nid entry */<br>
> +               if (!entry->mne_nid_count) /* at least one nid entry */<br>
>                         break;<br>
>                 if (entry->mne_nid_size != sizeof(lnet_nid_t))<br>
>                         break;<br>
> @@ -1191,7 +1191,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,<br>
>                 /* lustre-OST0001-osc-<instance #> */<br>
>                 strcpy(obdname, cld->cld_logname);<br>
>                 cname = strrchr(obdname, '-');<br>
> -               if (cname == NULL) {<br>
> +               if (!cname) {<br>
>                         CERROR("mgc %s: invalid logname %s\n",<br>
>                                mgc->obd_name, obdname);<br>
>                         break;<br>
> @@ -1208,7 +1208,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,<br>
><br>
>                 /* find the obd by obdname */<br>
>                 obd = class_name2obd(obdname);<br>
> -               if (obd == NULL) {<br>
> +               if (!obd) {<br>
>                         CDEBUG(D_INFO, "mgc %s: cannot find obdname %s\n",<br>
>                                mgc->obd_name, obdname);<br>
>                         rc = 0;<br>
> @@ -1223,7 +1223,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,<br>
>                 uuid = buf + pos;<br>
><br>
>                 down_read(&obd->u.cli.cl_sem);<br>
> -               if (obd->u.cli.cl_import == NULL) {<br>
> +               if (!obd->u.cli.cl_import) {<br>
>                         /* client does not connect to the OST yet */<br>
>                         up_read(&obd->u.cli.cl_sem);<br>
>                         rc = 0;<br>
> @@ -1253,7 +1253,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,<br>
><br>
>                 rc = -ENOMEM;<br>
>                 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);<br>
> -               if (lcfg == NULL) {<br>
> +               if (!lcfg) {<br>
>                         CERROR("mgc: cannot allocate memory\n");<br>
>                         break;<br>
>                 }<br>
> @@ -1301,18 +1301,18 @@ static int mgc_process_recover_log(struct obd_device *obd,<br>
>          * small and CONFIG_READ_NRPAGES will be used.<br>
>          */<br>
>         nrpages = CONFIG_READ_NRPAGES;<br>
> -       if (cfg->cfg_last_idx == 0) /* the first time */<br>
> +       if (!cfg->cfg_last_idx) /* the first time */<br>
>                 nrpages = CONFIG_READ_NRPAGES_INIT;<br>
><br>
>         pages = kcalloc(nrpages, sizeof(*pages), GFP_NOFS);<br>
> -       if (pages == NULL) {<br>
> +       if (!pages) {<br>
>                 rc = -ENOMEM;<br>
>                 goto out;<br>
>         }<br>
><br>
>         for (i = 0; i < nrpages; i++) {<br>
>                 pages[i] = alloc_page(GFP_IOFS);<br>
> -               if (pages[i] == NULL) {<br>
> +               if (!pages[i]) {<br>
>                         rc = -ENOMEM;<br>
>                         goto out;<br>
>                 }<br>
> @@ -1323,7 +1323,7 @@ again:<br>
>         LASSERT(mutex_is_locked(&cld->cld_lock));<br>
>         req = ptlrpc_request_alloc(class_exp2cliimp(cld->cld_mgcexp),<br>
>                                    &RQF_MGS_CONFIG_READ);<br>
> -       if (req == NULL) {<br>
> +       if (!req) {<br>
>                 rc = -ENOMEM;<br>
>                 goto out;<br>
>         }<br>
> @@ -1349,7 +1349,7 @@ again:<br>
>         /* allocate bulk transfer descriptor */<br>
>         desc = ptlrpc_prep_bulk_imp(req, nrpages, 1, BULK_PUT_SINK,<br>
>                                     MGS_BULK_PORTAL);<br>
> -       if (desc == NULL) {<br>
> +       if (!desc) {<br>
>                 rc = -ENOMEM;<br>
>                 goto out;<br>
>         }<br>
> @@ -1387,7 +1387,7 @@ again:<br>
>                 goto out;<br>
>         }<br>
><br>
> -       if (ealen == 0) { /* no logs transferred */<br>
> +       if (!ealen) { /* no logs transferred */<br>
>                 if (!eof)<br>
>                         rc = -EINVAL;<br>
>                 goto out;<br>
> @@ -1425,12 +1425,12 @@ out:<br>
>         if (req)<br>
>                 ptlrpc_req_finished(req);<br>
><br>
> -       if (rc == 0 && !eof)<br>
> +       if (!rc && !eof)<br>
>                 goto again;<br>
><br>
>         if (pages) {<br>
>                 for (i = 0; i < nrpages; i++) {<br>
> -                       if (pages[i] == NULL)<br>
> +                       if (!pages[i])<br>
>                                 break;<br>
>                         __free_page(pages[i]);<br>
>                 }<br>
> @@ -1543,7 +1543,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)<br>
>         rcl = mgc_enqueue(mgc->u.cli.cl_mgc_mgsexp, NULL, LDLM_PLAIN, NULL,<br>
>                           LCK_CR, &flags, NULL, NULL, NULL,<br>
>                           cld, 0, NULL, &lockh);<br>
> -       if (rcl == 0) {<br>
> +       if (!rcl) {<br>
>                 /* Get the cld, it will be released in mgc_blocking_ast. */<br>
>                 config_log_get(cld);<br>
>                 rc = ldlm_lock_set_data(&lockh, (void *)cld);<br>
> @@ -1560,7 +1560,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)<br>
><br>
>         if (cld_is_recover(cld)) {<br>
>                 rc = 0; /* this is not a fatal error for recover log */<br>
> -               if (rcl == 0)<br>
> +               if (!rcl)<br>
>                         rc = mgc_process_recover_log(mgc, cld);<br>
>         } else {<br>
>                 rc = mgc_process_cfg_log(mgc, cld, rcl != 0);<br>
> @@ -1631,7 +1631,7 @@ static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)<br>
>                 if (rc)<br>
>                         break;<br>
>                 cld = config_log_find(logname, cfg);<br>
> -               if (cld == NULL) {<br>
> +               if (!cld) {<br>
>                         rc = -ENOENT;<br>
>                         break;<br>
>                 }<br>
> @@ -1642,7 +1642,7 @@ static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)<br>
>                 cld->cld_cfg.cfg_flags |= CFG_F_COMPAT146;<br>
><br>
>                 rc = mgc_process_log(obd, cld);<br>
> -               if (rc == 0 && cld->cld_recover != NULL) {<br>
> +               if (!rc && cld->cld_recover) {<br>
>                         if (OCD_HAS_FLAG(&obd->u.cli.cl_import-><br>
>                                          imp_connect_data, IMP_RECOV)) {<br>
>                                 rc = mgc_process_log(obd, cld->cld_recover);<br>
> @@ -1656,7 +1656,7 @@ static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)<br>
>                                 CERROR("Cannot process recover llog %d\n", rc);<br>
>                 }<br>
><br>
> -               if (rc == 0 && cld->cld_params != NULL) {<br>
> +               if (!rc && cld->cld_params) {<br>
>                         rc = mgc_process_log(obd, cld->cld_params);<br>
>                         if (rc == -ENOENT) {<br>
>                                 CDEBUG(D_MGC,<br>
> --<br>
> 1.9.1<br>
><br>
></div></div></blockquote></div></div></div>