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

staging: lustre: obdclass: obd_config: remove unneeded null test before free

Kfree can cope with a null argument, so drop null tests.

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

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

The first part of the patch introduces new labels to avoid unnecessary
calls to kfree.  In addition, lprof->lp_md is always null in the cleanup
code at the end of the function, so that kfree is just dropped.
Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2522d76a
...@@ -869,7 +869,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc, ...@@ -869,7 +869,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
lprof->lp_profile = kzalloc(proflen, GFP_NOFS); lprof->lp_profile = kzalloc(proflen, GFP_NOFS);
if (lprof->lp_profile == NULL) { if (lprof->lp_profile == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto free_lprof;
} }
memcpy(lprof->lp_profile, prof, proflen); memcpy(lprof->lp_profile, prof, proflen);
...@@ -877,7 +877,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc, ...@@ -877,7 +877,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
lprof->lp_dt = kzalloc(osclen, GFP_NOFS); lprof->lp_dt = kzalloc(osclen, GFP_NOFS);
if (lprof->lp_dt == NULL) { if (lprof->lp_dt == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto free_lp_profile;
} }
memcpy(lprof->lp_dt, osc, osclen); memcpy(lprof->lp_dt, osc, osclen);
...@@ -886,7 +886,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc, ...@@ -886,7 +886,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
lprof->lp_md = kzalloc(mdclen, GFP_NOFS); lprof->lp_md = kzalloc(mdclen, GFP_NOFS);
if (lprof->lp_md == NULL) { if (lprof->lp_md == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto free_lp_dt;
} }
memcpy(lprof->lp_md, mdc, mdclen); memcpy(lprof->lp_md, mdc, mdclen);
} }
...@@ -894,13 +894,11 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc, ...@@ -894,13 +894,11 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
list_add(&lprof->lp_list, &lustre_profile_list); list_add(&lprof->lp_list, &lustre_profile_list);
return err; return err;
out: free_lp_dt:
if (lprof->lp_md)
kfree(lprof->lp_md);
if (lprof->lp_dt)
kfree(lprof->lp_dt); kfree(lprof->lp_dt);
if (lprof->lp_profile) free_lp_profile:
kfree(lprof->lp_profile); kfree(lprof->lp_profile);
free_lprof:
kfree(lprof); kfree(lprof);
return err; return err;
} }
...@@ -916,7 +914,6 @@ void class_del_profile(const char *prof) ...@@ -916,7 +914,6 @@ void class_del_profile(const char *prof)
list_del(&lprof->lp_list); list_del(&lprof->lp_list);
kfree(lprof->lp_profile); kfree(lprof->lp_profile);
kfree(lprof->lp_dt); kfree(lprof->lp_dt);
if (lprof->lp_md)
kfree(lprof->lp_md); kfree(lprof->lp_md);
kfree(lprof); kfree(lprof);
} }
...@@ -932,7 +929,6 @@ void class_del_profiles(void) ...@@ -932,7 +929,6 @@ void class_del_profiles(void)
list_del(&lprof->lp_list); list_del(&lprof->lp_list);
kfree(lprof->lp_profile); kfree(lprof->lp_profile);
kfree(lprof->lp_dt); kfree(lprof->lp_dt);
if (lprof->lp_md)
kfree(lprof->lp_md); kfree(lprof->lp_md);
kfree(lprof); kfree(lprof);
} }
......
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