Patchwork [1/1] MTD: Fix wrong check register_blkdev return value

login
register
mail settings
Submitter Frank Li
Date Oct. 26, 2010, 3:02 a.m.
Message ID <1288062139-2192-1-git-send-email-Frank.Li@freescale.com>
Download mbox | patch
Permalink /patch/69158/
State New
Headers show

Comments

Frank Li - Oct. 26, 2010, 3:02 a.m.
register_blkdev return 1..255 when major = 0.

if (ret ) {
	printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n",
		tr->name, tr->major, ret);
	      mutex_unlock(&mtd_table_mutex);
	return ret;
}

Above code will return fail when register_blkdev return allocated major number.

Signed-off-by: Frank Li <Frank.Li@freescale.com>
---
 drivers/mtd/mtd_blkdevs.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Li Frank-B20596 - Oct. 28, 2010, 1:30 a.m.
Why no one review my patch? That's fix a bug when major is zero at mtd
blktrans layer.

> -----Original Message-----
> From: Li Frank-B20596
> Sent: Tuesday, October 26, 2010 11:02 AM
> To: linux-mtd@lists.infradead.org
> Cc: Li Frank-B20596
> Subject: [PATCH 1/1] MTD: Fix wrong check register_blkdev return value
> 
> register_blkdev return 1..255 when major = 0.
> 
> if (ret ) {
> 	printk(KERN_WARNING "Unable to register %s block device on
> major %d: %d\n",
> 		tr->name, tr->major, ret);
> 	      mutex_unlock(&mtd_table_mutex);
> 	return ret;
> }
> 
> Above code will return fail when register_blkdev return allocated
major
> number.
> 
> Signed-off-by: Frank Li <Frank.Li@freescale.com>
> ---
>  drivers/mtd/mtd_blkdevs.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
> index a919587..63790e9 100644
> --- a/drivers/mtd/mtd_blkdevs.c
> +++ b/drivers/mtd/mtd_blkdevs.c
> @@ -502,13 +502,16 @@ int register_mtd_blktrans(struct
mtd_blktrans_ops
> *tr)
>  	mutex_lock(&mtd_table_mutex);
> 
>  	ret = register_blkdev(tr->major, tr->name);
> -	if (ret) {
> +	if (ret < 0) {
>  		printk(KERN_WARNING "Unable to register %s block device
on
> major %d: %d\n",
>  		       tr->name, tr->major, ret);
>  		mutex_unlock(&mtd_table_mutex);
>  		return ret;
>  	}
> 
> +	if (ret)
> +		tr->major = ret;
> +
>  	tr->blkshift = ffs(tr->blksize) - 1;
> 
>  	INIT_LIST_HEAD(&tr->devs);
> --
> 1.7.1

Patch

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index a919587..63790e9 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -502,13 +502,16 @@  int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
 	mutex_lock(&mtd_table_mutex);
 
 	ret = register_blkdev(tr->major, tr->name);
-	if (ret) {
+	if (ret < 0) {
 		printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n",
 		       tr->name, tr->major, ret);
 		mutex_unlock(&mtd_table_mutex);
 		return ret;
 	}
 
+	if (ret)
+		tr->major = ret;
+
 	tr->blkshift = ffs(tr->blksize) - 1;
 
 	INIT_LIST_HEAD(&tr->devs);