Skip to content

Commit

Permalink
lightnvm: prevent double free on init error
Browse files Browse the repository at this point in the history
Both the nvm_register and nvm_init does a kfree(dev) on error. Make sure
to only free it once.

Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Matias Bjørling authored and Jens Axboe committed Nov 16, 2015
1 parent edad2e6 commit c1480ad
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions drivers/lightnvm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ int nvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blk)
}
EXPORT_SYMBOL(nvm_erase_blk);

static void nvm_core_free(struct nvm_dev *dev)
{
kfree(dev);
}

static int nvm_core_init(struct nvm_dev *dev)
{
struct nvm_id *id = &dev->identity;
Expand Down Expand Up @@ -223,8 +218,6 @@ static void nvm_free(struct nvm_dev *dev)

if (dev->mt)
dev->mt->unregister_mgr(dev);

nvm_core_free(dev);
}

static int nvm_init(struct nvm_dev *dev)
Expand Down Expand Up @@ -351,11 +344,12 @@ void nvm_unregister(char *disk_name)
return;
}

nvm_exit(dev);

down_write(&nvm_lock);
list_del(&dev->devices);
up_write(&nvm_lock);

nvm_exit(dev);
kfree(dev);
}
EXPORT_SYMBOL(nvm_unregister);

Expand Down

0 comments on commit c1480ad

Please sign in to comment.