staging: lustre: obdclass: Use !x to check for kzalloc failure
authorJulia Lawall <Julia.Lawall@lip6.fr>
Sat, 20 Jun 2015 16:59:07 +0000 (18:59 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jul 2015 02:35:53 +0000 (19:35 -0700)
!x is more normal for kzalloc failure in the kernel.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x;
statement S1, S2;
@@

x = kzalloc(...);
if (
- x == NULL
+ !x
 ) S1 else S2
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/obdclass/class_obd.c
drivers/staging/lustre/lustre/obdclass/genops.c
drivers/staging/lustre/lustre/obdclass/llog.c
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
drivers/staging/lustre/lustre/obdclass/lustre_peer.c
drivers/staging/lustre/lustre/obdclass/obd_config.c
drivers/staging/lustre/lustre/obdclass/obd_mount.c

index 1bc37566b3a50a3dbe106b26a7eb1793346aa9f1..8ebe2e6c1696e91f8bd88dd68da62fcea086ba88 100644 (file)
@@ -232,7 +232,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
                        goto out;
                }
                lcfg = kzalloc(data->ioc_plen1, GFP_NOFS);
-               if (lcfg == NULL) {
+               if (!lcfg) {
                        err = -ENOMEM;
                        goto out;
                }
index 978c3c5c460a15b25d06bcabe96e19f4077ab344..a42c9f9209c52d4270218ba27325ba67903043c7 100644 (file)
@@ -172,7 +172,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
 
        rc = -ENOMEM;
        type = kzalloc(sizeof(*type), GFP_NOFS);
-       if (type == NULL)
+       if (!type)
                return rc;
 
        type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS);
@@ -1016,7 +1016,7 @@ struct obd_import *class_new_import(struct obd_device *obd)
        struct obd_import *imp;
 
        imp = kzalloc(sizeof(*imp), GFP_NOFS);
-       if (imp == NULL)
+       if (!imp)
                return NULL;
 
        INIT_LIST_HEAD(&imp->imp_pinger_chain);
@@ -1819,7 +1819,7 @@ void *kuc_alloc(int payload_len, int transport, int type)
        int len = kuc_len(payload_len);
 
        lh = kzalloc(len, GFP_NOFS);
-       if (lh == NULL)
+       if (!lh)
                return ERR_PTR(-ENOMEM);
 
        lh->kuc_magic = KUC_MAGIC;
index 4fa52d1b79d1221b569fa8a0c6520bbcce084747..9af2da618a4db5331d0dfab78203cc93a664b72c 100644 (file)
@@ -61,7 +61,7 @@ static struct llog_handle *llog_alloc_handle(void)
        struct llog_handle *loghandle;
 
        loghandle = kzalloc(sizeof(*loghandle), GFP_NOFS);
-       if (loghandle == NULL)
+       if (!loghandle)
                return NULL;
 
        init_rwsem(&loghandle->lgh_lock);
@@ -208,7 +208,7 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
        LASSERT(handle->lgh_hdr == NULL);
 
        llh = kzalloc(sizeof(*llh), GFP_NOFS);
-       if (llh == NULL)
+       if (!llh)
                return -ENOMEM;
        handle->lgh_hdr = llh;
        /* first assign flags to use llog_client_ops */
@@ -435,7 +435,7 @@ int llog_process_or_fork(const struct lu_env *env,
        int                   rc;
 
        lpi = kzalloc(sizeof(*lpi), GFP_NOFS);
-       if (lpi == NULL) {
+       if (!lpi) {
                CERROR("cannot alloc pointer\n");
                return -ENOMEM;
        }
index 17e7c18078639d946f2a3ad7eb45d862358f5d81..c761dbf88278d520fcf92b6f5578aad5284ee1bd 100644 (file)
@@ -275,7 +275,7 @@ struct dentry *ldebugfs_add_symlink(const char *name, struct dentry *parent,
                return NULL;
 
        dest = kzalloc(MAX_STRING_SIZE + 1, GFP_KERNEL);
-       if (dest == NULL)
+       if (!dest)
                return NULL;
 
        va_start(ap, format);
index 5cc6435cc47a2ca8cd82a06211f686cae860b1c3..d6184f821cd0e919859f3e3cc14de2f12b3c5089 100644 (file)
@@ -105,7 +105,7 @@ int class_add_uuid(const char *uuid, __u64 nid)
                return -EOVERFLOW;
 
        data = kzalloc(sizeof(*data), GFP_NOFS);
-       if (data == NULL)
+       if (!data)
                return -ENOMEM;
 
        obd_str2uuid(&data->un_uuid, uuid);
index fbdb748a36b9e2f45c0b7b40f0ec06c0fd404f55..3435720c96bbda90a79682db7bc5b7c5140c03d9 100644 (file)
@@ -835,7 +835,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
        CDEBUG(D_CONFIG, "Add profile %s\n", prof);
 
        lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
-       if (lprof == NULL)
+       if (!lprof)
                return -ENOMEM;
        INIT_LIST_HEAD(&lprof->lp_list);
 
@@ -979,7 +979,7 @@ struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
        new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
 
        new_param = kzalloc(new_len, GFP_NOFS);
-       if (new_param == NULL)
+       if (!new_param)
                return ERR_PTR(-ENOMEM);
 
        strcpy(new_param, new_name);
@@ -987,7 +987,7 @@ struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
                strcat(new_param, value);
 
        bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
-       if (bufs == NULL) {
+       if (!bufs) {
                kfree(new_param);
                return ERR_PTR(-ENOMEM);
        }
@@ -1461,7 +1461,7 @@ int class_config_llog_handler(const struct lu_env *env,
                        inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
                                   sizeof(clli->cfg_instance) * 2 + 4;
                        inst_name = kzalloc(inst_len, GFP_NOFS);
-                       if (inst_name == NULL) {
+                       if (!inst_name) {
                                rc = -ENOMEM;
                                goto out;
                        }
@@ -1639,7 +1639,7 @@ int class_config_dump_handler(const struct lu_env *env,
        int      rc = 0;
 
        outstr = kzalloc(256, GFP_NOFS);
-       if (outstr == NULL)
+       if (!outstr)
                return -ENOMEM;
 
        if (rec->lrh_type == OBD_CFG_REC) {
index ce4a71f7171abb060679ad9d648f20481e07c0a5..3e0b8a4b64867c0f4d06df3a919b49c78028b049 100644 (file)
@@ -85,7 +85,7 @@ int lustre_process_log(struct super_block *sb, char *logname,
        LASSERT(cfg);
 
        bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
-       if (bufs == NULL)
+       if (!bufs)
                return -ENOMEM;
 
        /* mgc_process_config */
@@ -258,7 +258,7 @@ int lustre_start_mgc(struct super_block *sb)
        mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
 
        data = kzalloc(sizeof(*data), GFP_NOFS);
-       if (data == NULL) {
+       if (!data) {
                rc = -ENOMEM;
                goto out_free;
        }
@@ -885,7 +885,7 @@ static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
                length = tail - ptr;
 
        lmd->lmd_mgssec = kzalloc(length + 1, GFP_NOFS);
-       if (lmd->lmd_mgssec == NULL)
+       if (!lmd->lmd_mgssec)
                return -ENOMEM;
 
        memcpy(lmd->lmd_mgssec, ptr, length);
@@ -911,7 +911,7 @@ static int lmd_parse_string(char **handle, char *ptr)
                length = tail - ptr;
 
        *handle = kzalloc(length + 1, GFP_NOFS);
-       if (*handle == NULL)
+       if (!*handle)
                return -ENOMEM;
 
        memcpy(*handle, ptr, length);
@@ -941,7 +941,7 @@ static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
                oldlen = strlen(lmd->lmd_mgs) + 1;
 
        mgsnid = kzalloc(oldlen + length + 1, GFP_NOFS);
-       if (mgsnid == NULL)
+       if (!mgsnid)
                return -ENOMEM;
 
        if (lmd->lmd_mgs != NULL) {
@@ -983,7 +983,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
        lmd->lmd_magic = LMD_MAGIC;
 
        lmd->lmd_params = kzalloc(4096, GFP_NOFS);
-       if (lmd->lmd_params == NULL)
+       if (!lmd->lmd_params)
                return -ENOMEM;
        lmd->lmd_params[0] = '\0';