Commit c5b89520 authored by Julia Lawall's avatar Julia Lawall Committed by Greg Kroah-Hartman

staging: lustre: obdecho: Use kzalloc and kfree

Replace OBD_ALLOC, OBD_ALLOC_WAIT, OBD_ALLOC_PTR, and OBD_ALLOC_PTR_WAIT by
kalloc/kcalloc, and OBD_FREE and OBD_FREE_PTR by kfree.

A simplified version of the semantic patch that makes these changes is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr,size; @@
- OBD_ALLOC(ptr,size)
+ ptr = kzalloc(size, GFP_NOFS)

@@ expression ptr, size; @@
- OBD_FREE(ptr, size);
+ kfree(ptr);
// </smpl>
Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d7279044
...@@ -479,13 +479,13 @@ static int echo_alloc_memmd(struct echo_device *ed, ...@@ -479,13 +479,13 @@ static int echo_alloc_memmd(struct echo_device *ed,
lsm_size = lov_stripe_md_size(1); lsm_size = lov_stripe_md_size(1);
LASSERT(*lsmp == NULL); LASSERT(*lsmp == NULL);
OBD_ALLOC(*lsmp, lsm_size); *lsmp = kzalloc(lsm_size, GFP_NOFS);
if (*lsmp == NULL) if (*lsmp == NULL)
return -ENOMEM; return -ENOMEM;
OBD_ALLOC((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo)); (*lsmp)->lsm_oinfo[0] = kzalloc(sizeof(struct lov_oinfo), GFP_NOFS);
if ((*lsmp)->lsm_oinfo[0] == NULL) { if ((*lsmp)->lsm_oinfo[0] == NULL) {
OBD_FREE(*lsmp, lsm_size); kfree(*lsmp);
return -ENOMEM; return -ENOMEM;
} }
...@@ -507,8 +507,8 @@ static int echo_free_memmd(struct echo_device *ed, struct lov_stripe_md **lsmp) ...@@ -507,8 +507,8 @@ static int echo_free_memmd(struct echo_device *ed, struct lov_stripe_md **lsmp)
lsm_size = lov_stripe_md_size(1); lsm_size = lov_stripe_md_size(1);
LASSERT(*lsmp != NULL); LASSERT(*lsmp != NULL);
OBD_FREE((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo)); kfree((*lsmp)->lsm_oinfo[0]);
OBD_FREE(*lsmp, lsm_size); kfree(*lsmp);
*lsmp = NULL; *lsmp = NULL;
return 0; return 0;
} }
...@@ -700,7 +700,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env, ...@@ -700,7 +700,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
int rc; int rc;
int cleanup = 0; int cleanup = 0;
OBD_ALLOC_PTR(ed); ed = kzalloc(sizeof(*ed), GFP_NOFS);
if (ed == NULL) { if (ed == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
...@@ -798,7 +798,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env, ...@@ -798,7 +798,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
case 2: case 2:
cl_device_fini(&ed->ed_cl); cl_device_fini(&ed->ed_cl);
case 1: case 1:
OBD_FREE_PTR(ed); kfree(ed);
case 0: case 0:
default: default:
break; break;
...@@ -895,7 +895,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env, ...@@ -895,7 +895,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
LASSERT(ed->ed_site == lu2cl_site(d->ld_site)); LASSERT(ed->ed_site == lu2cl_site(d->ld_site));
echo_site_fini(env, ed); echo_site_fini(env, ed);
cl_device_fini(&ed->ed_cl); cl_device_fini(&ed->ed_cl);
OBD_FREE_PTR(ed); kfree(ed);
return NULL; return NULL;
} }
...@@ -1577,13 +1577,13 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa, ...@@ -1577,13 +1577,13 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
if (rw == OBD_BRW_WRITE) if (rw == OBD_BRW_WRITE)
brw_flags = OBD_BRW_ASYNC; brw_flags = OBD_BRW_ASYNC;
OBD_ALLOC(pga, npages * sizeof(*pga)); pga = kcalloc(npages, sizeof(*pga), GFP_NOFS);
if (pga == NULL) if (pga == NULL)
return -ENOMEM; return -ENOMEM;
OBD_ALLOC(pages, npages * sizeof(*pages)); pages = kcalloc(npages, sizeof(*pages), GFP_NOFS);
if (pages == NULL) { if (pages == NULL) {
OBD_FREE(pga, npages * sizeof(*pga)); kfree(pga);
return -ENOMEM; return -ENOMEM;
} }
...@@ -1632,8 +1632,8 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa, ...@@ -1632,8 +1632,8 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
} }
OBD_PAGE_FREE(pgp->pg); OBD_PAGE_FREE(pgp->pg);
} }
OBD_FREE(pga, npages * sizeof(*pga)); kfree(pga);
OBD_FREE(pages, npages * sizeof(*pages)); kfree(pages);
return rc; return rc;
} }
...@@ -1659,8 +1659,8 @@ static int echo_client_prep_commit(const struct lu_env *env, ...@@ -1659,8 +1659,8 @@ static int echo_client_prep_commit(const struct lu_env *env,
npages = batch >> PAGE_CACHE_SHIFT; npages = batch >> PAGE_CACHE_SHIFT;
tot_pages = count >> PAGE_CACHE_SHIFT; tot_pages = count >> PAGE_CACHE_SHIFT;
OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local)); lnb = kcalloc(npages, sizeof(struct niobuf_local), GFP_NOFS);
OBD_ALLOC(rnb, npages * sizeof(struct niobuf_remote)); rnb = kcalloc(npages, sizeof(struct niobuf_remote), GFP_NOFS);
if (lnb == NULL || rnb == NULL) { if (lnb == NULL || rnb == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -1738,9 +1738,9 @@ static int echo_client_prep_commit(const struct lu_env *env, ...@@ -1738,9 +1738,9 @@ static int echo_client_prep_commit(const struct lu_env *env,
out: out:
if (lnb) if (lnb)
OBD_FREE(lnb, npages * sizeof(struct niobuf_local)); kfree(lnb);
if (rnb) if (rnb)
OBD_FREE(rnb, npages * sizeof(struct niobuf_remote)); kfree(rnb);
return ret; return ret;
} }
...@@ -1879,7 +1879,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len, ...@@ -1879,7 +1879,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
if (rc < 0) if (rc < 0)
return rc; return rc;
OBD_ALLOC_PTR(env); env = kzalloc(sizeof(*env), GFP_NOFS);
if (env == NULL) if (env == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -2010,7 +2010,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len, ...@@ -2010,7 +2010,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
out: out:
lu_env_fini(env); lu_env_fini(env);
OBD_FREE_PTR(env); kfree(env);
/* XXX this should be in a helper also called by target_send_reply */ /* XXX this should be in a helper also called by target_send_reply */
for (ack_lock = dummy_oti.oti_ack_locks, i = 0; i < 4; for (ack_lock = dummy_oti.oti_ack_locks, i = 0; i < 4;
...@@ -2050,7 +2050,7 @@ static int echo_client_setup(const struct lu_env *env, ...@@ -2050,7 +2050,7 @@ static int echo_client_setup(const struct lu_env *env,
ec->ec_unique = 0; ec->ec_unique = 0;
ec->ec_nstripes = 0; ec->ec_nstripes = 0;
OBD_ALLOC(ocd, sizeof(*ocd)); ocd = kzalloc(sizeof(*ocd), GFP_NOFS);
if (ocd == NULL) { if (ocd == NULL) {
CERROR("Can't alloc ocd connecting to %s\n", CERROR("Can't alloc ocd connecting to %s\n",
lustre_cfg_string(lcfg, 1)); lustre_cfg_string(lcfg, 1));
...@@ -2074,7 +2074,7 @@ static int echo_client_setup(const struct lu_env *env, ...@@ -2074,7 +2074,7 @@ static int echo_client_setup(const struct lu_env *env,
spin_unlock(&tgt->obd_dev_lock); spin_unlock(&tgt->obd_dev_lock);
} }
OBD_FREE(ocd, sizeof(*ocd)); kfree(ocd);
if (rc != 0) { if (rc != 0) {
CERROR("fail to connect to device %s\n", CERROR("fail to connect to device %s\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment