MTD: Fix wrong check register_blkdev return value
authorFrank Li <Frank.Li@freescale.com>
Tue, 26 Oct 2010 03:02:19 +0000 (11:02 +0800)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 30 Oct 2010 11:30:50 +0000 (12:30 +0100)
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>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtd_blkdevs.c

index a919587ed4811d7a7d1de4cf6034bc5446d68bf4..63790e975d204087feee6675a1deb1c68f3c6b1f 100644 (file)
@@ -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);