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

staging: lustre: osc: 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 c5b89520
...@@ -204,7 +204,7 @@ static struct lu_device *osc_device_free(const struct lu_env *env, ...@@ -204,7 +204,7 @@ static struct lu_device *osc_device_free(const struct lu_env *env,
struct osc_device *od = lu2osc_dev(d); struct osc_device *od = lu2osc_dev(d);
cl_device_fini(lu2cl_dev(d)); cl_device_fini(lu2cl_dev(d));
OBD_FREE_PTR(od); kfree(od);
return NULL; return NULL;
} }
...@@ -217,7 +217,7 @@ static struct lu_device *osc_device_alloc(const struct lu_env *env, ...@@ -217,7 +217,7 @@ static struct lu_device *osc_device_alloc(const struct lu_env *env,
struct obd_device *obd; struct obd_device *obd;
int rc; int rc;
OBD_ALLOC_PTR(od); od = kzalloc(sizeof(*od), GFP_NOFS);
if (od == NULL) if (od == NULL)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
......
...@@ -110,7 +110,7 @@ static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp, ...@@ -110,7 +110,7 @@ static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
return lmm_size; return lmm_size;
if (*lmmp != NULL && lsm == NULL) { if (*lmmp != NULL && lsm == NULL) {
OBD_FREE(*lmmp, lmm_size); kfree(*lmmp);
*lmmp = NULL; *lmmp = NULL;
return 0; return 0;
} else if (unlikely(lsm != NULL && ostid_id(&lsm->lsm_oi) == 0)) { } else if (unlikely(lsm != NULL && ostid_id(&lsm->lsm_oi) == 0)) {
...@@ -118,7 +118,7 @@ static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp, ...@@ -118,7 +118,7 @@ static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
} }
if (*lmmp == NULL) { if (*lmmp == NULL) {
OBD_ALLOC(*lmmp, lmm_size); *lmmp = kzalloc(lmm_size, GFP_NOFS);
if (*lmmp == NULL) if (*lmmp == NULL)
return -ENOMEM; return -ENOMEM;
} }
...@@ -157,19 +157,20 @@ static int osc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp, ...@@ -157,19 +157,20 @@ static int osc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
return lsm_size; return lsm_size;
if (*lsmp != NULL && lmm == NULL) { if (*lsmp != NULL && lmm == 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;
} }
if (*lsmp == NULL) { if (*lsmp == NULL) {
OBD_ALLOC(*lsmp, lsm_size); *lsmp = kzalloc(lsm_size, GFP_NOFS);
if (unlikely(*lsmp == NULL)) if (unlikely(*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 (unlikely((*lsmp)->lsm_oinfo[0] == NULL)) { if (unlikely((*lsmp)->lsm_oinfo[0] == NULL)) {
OBD_FREE(*lsmp, lsm_size); kfree(*lsmp);
return -ENOMEM; return -ENOMEM;
} }
loi_init((*lsmp)->lsm_oinfo[0]); loi_init((*lsmp)->lsm_oinfo[0]);
...@@ -962,7 +963,7 @@ int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes) ...@@ -962,7 +963,7 @@ int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes)
} }
client_obd_list_unlock(&cli->cl_loi_list_lock); client_obd_list_unlock(&cli->cl_loi_list_lock);
OBD_ALLOC_PTR(body); body = kzalloc(sizeof(*body), GFP_NOFS);
if (!body) if (!body)
return -ENOMEM; return -ENOMEM;
...@@ -984,7 +985,7 @@ int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes) ...@@ -984,7 +985,7 @@ int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes)
sizeof(*body), body, NULL); sizeof(*body), body, NULL);
if (rc != 0) if (rc != 0)
__osc_update_grant(cli, body->oa.o_grant); __osc_update_grant(cli, body->oa.o_grant);
OBD_FREE_PTR(body); kfree(body);
return rc; return rc;
} }
...@@ -1748,7 +1749,7 @@ static void sort_brw_pages(struct brw_page **array, int num) ...@@ -1748,7 +1749,7 @@ static void sort_brw_pages(struct brw_page **array, int num)
static void osc_release_ppga(struct brw_page **ppga, u32 count) static void osc_release_ppga(struct brw_page **ppga, u32 count)
{ {
LASSERT(ppga != NULL); LASSERT(ppga != NULL);
OBD_FREE(ppga, sizeof(*ppga) * count); kfree(ppga);
} }
static int brw_interpret(const struct lu_env *env, static int brw_interpret(const struct lu_env *env,
...@@ -1908,13 +1909,13 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli, ...@@ -1908,13 +1909,13 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
if (mem_tight) if (mem_tight)
mpflag = cfs_memory_pressure_get_and_set(); mpflag = cfs_memory_pressure_get_and_set();
OBD_ALLOC(crattr, sizeof(*crattr)); crattr = kzalloc(sizeof(*crattr), GFP_NOFS);
if (crattr == NULL) { if (crattr == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
OBD_ALLOC(pga, sizeof(*pga) * page_count); pga = kcalloc(page_count, sizeof(*pga), GFP_NOFS);
if (pga == NULL) { if (pga == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
...@@ -2055,7 +2056,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli, ...@@ -2055,7 +2056,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
if (crattr != NULL) { if (crattr != NULL) {
capa_put(crattr->cra_capa); capa_put(crattr->cra_capa);
OBD_FREE(crattr, sizeof(*crattr)); kfree(crattr);
} }
if (rc != 0) { if (rc != 0) {
...@@ -2064,7 +2065,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli, ...@@ -2064,7 +2065,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
if (oa) if (oa)
OBDO_FREE(oa); OBDO_FREE(oa);
if (pga) if (pga)
OBD_FREE(pga, sizeof(*pga) * page_count); kfree(pga);
/* this should happen rarely and is pretty bad, it makes the /* this should happen rarely and is pretty bad, it makes the
* pending list not follow the dirty order */ * pending list not follow the dirty order */
while (!list_empty(ext_list)) { while (!list_empty(ext_list)) {
...@@ -2617,7 +2618,7 @@ static int osc_getstripe(struct lov_stripe_md *lsm, struct lov_user_md *lump) ...@@ -2617,7 +2618,7 @@ static int osc_getstripe(struct lov_stripe_md *lsm, struct lov_user_md *lump)
* because lov_user_md_vX and lov_mds_md_vX have the same size */ * because lov_user_md_vX and lov_mds_md_vX have the same size */
if (lum.lmm_stripe_count > 0) { if (lum.lmm_stripe_count > 0) {
lum_size = lov_mds_md_size(lum.lmm_stripe_count, lum.lmm_magic); lum_size = lov_mds_md_size(lum.lmm_stripe_count, lum.lmm_magic);
OBD_ALLOC(lumk, lum_size); lumk = kzalloc(lum_size, GFP_NOFS);
if (!lumk) if (!lumk)
return -ENOMEM; return -ENOMEM;
...@@ -2639,7 +2640,7 @@ static int osc_getstripe(struct lov_stripe_md *lsm, struct lov_user_md *lump) ...@@ -2639,7 +2640,7 @@ static int osc_getstripe(struct lov_stripe_md *lsm, struct lov_user_md *lump)
rc = -EFAULT; rc = -EFAULT;
if (lumk != &lum) if (lumk != &lum)
OBD_FREE(lumk, lum_size); kfree(lumk);
return rc; return rc;
} }
......
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