2014-01-23 19:51:53

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH 2/4] mtd: block2mtd: Add mutex_destroy

mutex_destroy added on each device in block2mtd_exit and add_device failure

Signed-off-by: Fabian Frederick <[email protected]>
---
drivers/mtd/devices/block2mtd.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 0efee5b..8071596 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -240,14 +240,14 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)

if (IS_ERR(bdev)) {
pr_err("error: cannot open device %s\n", devname);
- goto devinit_err;
+ goto devinit_err1;
}
dev->blkdev = bdev;

if ((MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) ||
(MAJOR(bdev->bd_dev) == MTD_CHAR_MAJOR)) {
pr_err("attempting to use an MTD device as a block device\n");
- goto devinit_err;
+ goto devinit_err1;
}

mutex_init(&dev->write_mutex);
@@ -256,7 +256,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
/* make the name contain the block device in */
name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
if (!name)
- goto devinit_err;
+ goto devinit_err2;

dev->mtd.name = name;

@@ -275,7 +275,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)

if (mtd_device_register(&dev->mtd, NULL, 0)) {
/* Device didn't get added, so free the entry */
- goto devinit_err;
+ goto devinit_err2;
}
list_add(&dev->list, &blkmtd_device_list);
pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
@@ -284,7 +284,9 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
dev->mtd.erasesize >> 10, dev->mtd.erasesize);
return dev;

-devinit_err:
+devinit_err2:
+ mutex_destroy(&dev->write_mutex);
+devinit_err1:
block2mtd_free_device(dev);
return NULL;
}
@@ -449,6 +451,7 @@ static void block2mtd_exit(void)
struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list);
block2mtd_sync(&dev->mtd);
mtd_device_unregister(&dev->mtd);
+ mutex_destroy(&dev->write_mutex);
pr_info("mtd%d: [%s] removed\n",
dev->mtd.index,
dev->mtd.name + strlen("block2mtd: "));
--
1.8.1.4


2014-01-25 05:38:12

by Ezequiel Garcia

[permalink] [raw]
Subject: Re: [PATCH 2/4] mtd: block2mtd: Add mutex_destroy

On Thu, Jan 23, 2014 at 08:51:47PM +0100, Fabian Frederick wrote:
> mutex_destroy added on each device in block2mtd_exit and add_device failure
>
> Signed-off-by: Fabian Frederick <[email protected]>
> ---
> drivers/mtd/devices/block2mtd.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
> index 0efee5b..8071596 100644
> --- a/drivers/mtd/devices/block2mtd.c
> +++ b/drivers/mtd/devices/block2mtd.c
> @@ -240,14 +240,14 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
>
> if (IS_ERR(bdev)) {
> pr_err("error: cannot open device %s\n", devname);
> - goto devinit_err;
> + goto devinit_err1;

Ah, this one commit looks good, but the naming of the labels doesn't.

Instead, you should use a name describing what the error path does,
such as "err_free_block2mtd" and "err_destroy_mutex" or something like that.

We have a language full of words with meaning, so it's shame to use
dumb numbers :-)
--
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com