summaryrefslogtreecommitdiff
path: root/drivers/block
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2022-07-21 16:09:12 +0300
committerJens Axboe <axboe@kernel.dk>2022-07-21 19:52:12 +0300
commitfa362045564ea7641e7d48295b54f4eb4df689ea (patch)
tree02bf9349465e65b2a0d3820770782957155173b6 /drivers/block
parent49d686cceed2e3148ba2bd2dec7e09b86eba0337 (diff)
downloadlinux-fa362045564ea7641e7d48295b54f4eb4df689ea.tar.xz
ublk: simplify ublk_ch_open and ublk_ch_release
fops->open and fops->release are always paired. Use simple atomic bit ops ot indicate if the device is opened instead of a count that can only be 0 and 1 and a useless cmpxchg loop in ublk_ch_release. Also don't bother clearing file->private_data is the file is about to be freed anyway. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20220721130916.1869719-5-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/ublk_drv.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index deabcb23ae2a..1f7bbbc3276a 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -125,7 +125,8 @@ struct ublk_device {
struct cdev cdev;
struct device cdev_dev;
- atomic_t ch_open_cnt;
+#define UB_STATE_OPEN (1 << 0)
+ unsigned long state;
int ub_number;
struct mutex mutex;
@@ -647,21 +648,17 @@ static int ublk_ch_open(struct inode *inode, struct file *filp)
struct ublk_device *ub = container_of(inode->i_cdev,
struct ublk_device, cdev);
- if (atomic_cmpxchg(&ub->ch_open_cnt, 0, 1) == 0) {
- filp->private_data = ub;
- return 0;
- }
- return -EBUSY;
+ if (test_and_set_bit(UB_STATE_OPEN, &ub->state))
+ return -EBUSY;
+ filp->private_data = ub;
+ return 0;
}
static int ublk_ch_release(struct inode *inode, struct file *filp)
{
struct ublk_device *ub = filp->private_data;
- while (atomic_cmpxchg(&ub->ch_open_cnt, 1, 0) != 1)
- cpu_relax();
-
- filp->private_data = NULL;
+ clear_bit(UB_STATE_OPEN, &ub->state);
return 0;
}