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;
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;
}