summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/mmc/core/block.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 10c56f0bee34..6450348edd1a 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -2323,9 +2323,7 @@ static int mmc_rpmb_chrdev_open(struct inode *inode, struct file *filp)
get_device(&rpmb->dev);
filp->private_data = rpmb;
- mutex_lock(&open_lock);
- rpmb->md->usage++;
- mutex_unlock(&open_lock);
+ mmc_blk_get(rpmb->md->disk);
return nonseekable_open(inode, filp);
}
@@ -2336,9 +2334,7 @@ static int mmc_rpmb_chrdev_release(struct inode *inode, struct file *filp)
struct mmc_rpmb_data, chrdev);
put_device(&rpmb->dev);
- mutex_lock(&open_lock);
- rpmb->md->usage--;
- mutex_unlock(&open_lock);
+ mmc_blk_put(rpmb->md);
return 0;
}
@@ -2354,6 +2350,13 @@ static const struct file_operations mmc_rpmb_fileops = {
#endif
};
+static void mmc_blk_rpmb_device_release(struct device *dev)
+{
+ struct mmc_rpmb_data *rpmb = dev_get_drvdata(dev);
+
+ ida_simple_remove(&mmc_rpmb_ida, rpmb->id);
+ kfree(rpmb);
+}
static int mmc_blk_alloc_rpmb_part(struct mmc_card *card,
struct mmc_blk_data *md,
@@ -2372,8 +2375,10 @@ static int mmc_blk_alloc_rpmb_part(struct mmc_card *card,
return devidx;
rpmb = kzalloc(sizeof(*rpmb), GFP_KERNEL);
- if (!rpmb)
+ if (!rpmb) {
+ ida_simple_remove(&mmc_rpmb_ida, devidx);
return -ENOMEM;
+ }
snprintf(rpmb_name, sizeof(rpmb_name),
"mmcblk%u%s", card->host->index, subname ? subname : "");
@@ -2384,6 +2389,7 @@ static int mmc_blk_alloc_rpmb_part(struct mmc_card *card,
rpmb->dev.bus = &mmc_rpmb_bus_type;
rpmb->dev.devt = MKDEV(MAJOR(mmc_rpmb_devt), rpmb->id);
rpmb->dev.parent = &card->dev;
+ rpmb->dev.release = mmc_blk_rpmb_device_release;
device_initialize(&rpmb->dev);
dev_set_drvdata(&rpmb->dev, rpmb);
rpmb->md = md;
@@ -2393,7 +2399,7 @@ static int mmc_blk_alloc_rpmb_part(struct mmc_card *card,
ret = cdev_device_add(&rpmb->chrdev, &rpmb->dev);
if (ret) {
pr_err("%s: could not add character device\n", rpmb_name);
- goto out_remove_ida;
+ goto out_put_device;
}
list_add(&rpmb->node, &md->rpmbs);
@@ -2408,18 +2414,16 @@ static int mmc_blk_alloc_rpmb_part(struct mmc_card *card,
return 0;
-out_remove_ida:
- ida_simple_remove(&mmc_rpmb_ida, rpmb->id);
- kfree(rpmb);
+out_put_device:
+ put_device(&rpmb->dev);
return ret;
}
static void mmc_blk_remove_rpmb_part(struct mmc_rpmb_data *rpmb)
+
{
cdev_device_del(&rpmb->chrdev, &rpmb->dev);
- device_del(&rpmb->dev);
- ida_simple_remove(&mmc_rpmb_ida, rpmb->id);
- kfree(rpmb);
+ put_device(&rpmb->dev);
}
/* MMC Physical partitions consist of two boot partitions and