mmc: card: Avoid null pointer dereference
authorPhilippe De Swert <philippedeswert@gmail.com>
Wed, 11 Apr 2012 20:31:45 +0000 (23:31 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 7 Jun 2015 23:12:03 +0000 (02:12 +0300)
After the null check on md the code jumped to cmd_done, which then
will dereference md in mmc_blk_put. This patch avoids the possible
null pointer dereference in that case.

Signed-off-by: Philippe De Swert <philippedeswert@gmail.com>
Reviewed-by: Namjae Jeon <linkinjeon@gmail.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
drivers/mmc/card/block.c

index c6b3bf9..71db040 100644 (file)
@@ -319,7 +319,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
        md = mmc_blk_get(bdev->bd_disk);
        if (!md) {
                err = -EINVAL;
        md = mmc_blk_get(bdev->bd_disk);
        if (!md) {
                err = -EINVAL;
-               goto cmd_done;
+               goto cmd_err;
        }
 
        card = md->queue.card;
        }
 
        card = md->queue.card;
@@ -418,6 +418,7 @@ cmd_rel_host:
 
 cmd_done:
        mmc_blk_put(md);
 
 cmd_done:
        mmc_blk_put(md);
+cmd_err:
        kfree(idata->buf);
        kfree(idata);
        return err;
        kfree(idata->buf);
        kfree(idata);
        return err;