Message ID | 5652D290.8090705@lightnvm.io (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Jens Axboe |
Headers | show |
This is okay with me. 2015-11-23 16:47 GMT+08:00 Matias Bjørling <mb@lightnvm.io>: > On 11/23/2015 09:29 AM, Wenwei Tao wrote: >> >> free allocated nvm block and gennvm lun structures when >> gennvm register fails, otherwise it will cause memory leak. >> >> Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com> >> --- >> drivers/lightnvm/gennvm.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c >> index ae1fb2b..03fc7a5 100644 >> --- a/drivers/lightnvm/gennvm.c >> +++ b/drivers/lightnvm/gennvm.c >> @@ -211,12 +211,15 @@ static int gennvm_register(struct nvm_dev *dev) >> ret = gennvm_blocks_init(dev, gn); >> if (ret) { >> pr_err("gennvm: could not initialize blocks\n"); >> + gennvm_blocks_free(dev); >> + gennvm_luns_free(dev); >> goto err; >> } >> >> return 1; >> err: >> kfree(gn); >> + dev->mp = NULL; >> return ret; >> } >> >> > Thanks Tao, would it be okay with you if I apply the patch like this: > > diff --git i/drivers/lightnvm/gennvm.c w/drivers/lightnvm/gennvm.c > index e20e74e..3969a98 100644 > --- i/drivers/lightnvm/gennvm.c > +++ w/drivers/lightnvm/gennvm.c > @@ -207,6 +207,14 @@ static int gennvm_blocks_init(struct nvm_dev *dev, > struct gen_nvm *gn) > return 0; > } > > +static void gennvm_free(struct nvm_dev *dev) > +{ > + gennvm_blocks_free(dev); > + gennvm_luns_free(dev); > + kfree(dev->mp); > + dev->mp = NULL; > +} > + > static int gennvm_register(struct nvm_dev *dev) > { > struct gen_nvm *gn; > @@ -234,16 +242,13 @@ static int gennvm_register(struct nvm_dev *dev) > > return 1; > err: > - kfree(gn); > + gennvm_free(dev); > return ret; > } > > static void gennvm_unregister(struct nvm_dev *dev) > { > - gennvm_blocks_free(dev); > - gennvm_luns_free(dev); > - kfree(dev->mp); > - dev->mp = NULL; > + gennvm_free(dev); > } > > -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 11/23/2015 10:00 AM, Wenwei Tao wrote: > This is okay with me. Great, I'll go ahead and apply it. > > 2015-11-23 16:47 GMT+08:00 Matias Bjørling <mb@lightnvm.io>: >> On 11/23/2015 09:29 AM, Wenwei Tao wrote: >>> >>> free allocated nvm block and gennvm lun structures when >>> gennvm register fails, otherwise it will cause memory leak. >>> >>> Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com> >>> --- >>> drivers/lightnvm/gennvm.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c >>> index ae1fb2b..03fc7a5 100644 >>> --- a/drivers/lightnvm/gennvm.c >>> +++ b/drivers/lightnvm/gennvm.c >>> @@ -211,12 +211,15 @@ static int gennvm_register(struct nvm_dev *dev) >>> ret = gennvm_blocks_init(dev, gn); >>> if (ret) { >>> pr_err("gennvm: could not initialize blocks\n"); >>> + gennvm_blocks_free(dev); >>> + gennvm_luns_free(dev); >>> goto err; >>> } >>> >>> return 1; >>> err: >>> kfree(gn); >>> + dev->mp = NULL; >>> return ret; >>> } >>> >>> >> Thanks Tao, would it be okay with you if I apply the patch like this: >> >> diff --git i/drivers/lightnvm/gennvm.c w/drivers/lightnvm/gennvm.c >> index e20e74e..3969a98 100644 >> --- i/drivers/lightnvm/gennvm.c >> +++ w/drivers/lightnvm/gennvm.c >> @@ -207,6 +207,14 @@ static int gennvm_blocks_init(struct nvm_dev *dev, >> struct gen_nvm *gn) >> return 0; >> } >> >> +static void gennvm_free(struct nvm_dev *dev) >> +{ >> + gennvm_blocks_free(dev); >> + gennvm_luns_free(dev); >> + kfree(dev->mp); >> + dev->mp = NULL; >> +} >> + >> static int gennvm_register(struct nvm_dev *dev) >> { >> struct gen_nvm *gn; >> @@ -234,16 +242,13 @@ static int gennvm_register(struct nvm_dev *dev) >> >> return 1; >> err: >> - kfree(gn); >> + gennvm_free(dev); >> return ret; >> } >> >> static void gennvm_unregister(struct nvm_dev *dev) >> { >> - gennvm_blocks_free(dev); >> - gennvm_luns_free(dev); >> - kfree(dev->mp); >> - dev->mp = NULL; >> + gennvm_free(dev); >> } >> >> -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git i/drivers/lightnvm/gennvm.c w/drivers/lightnvm/gennvm.c index e20e74e..3969a98 100644 --- i/drivers/lightnvm/gennvm.c +++ w/drivers/lightnvm/gennvm.c @@ -207,6 +207,14 @@ static int gennvm_blocks_init(struct nvm_dev *dev, struct gen_nvm *gn) return 0; } +static void gennvm_free(struct nvm_dev *dev) +{ + gennvm_blocks_free(dev); + gennvm_luns_free(dev); + kfree(dev->mp); + dev->mp = NULL; +} + static int gennvm_register(struct nvm_dev *dev) {