File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ static struct mock_bus_type iommufd_mock_bus_type = {
36
36
},
37
37
};
38
38
39
- static atomic_t mock_dev_num ;
39
+ static DEFINE_IDA ( mock_dev_ida ) ;
40
40
41
41
enum {
42
42
MOCK_DIRTY_TRACK = 1 ,
@@ -123,6 +123,7 @@ enum selftest_obj_type {
123
123
struct mock_dev {
124
124
struct device dev ;
125
125
unsigned long flags ;
126
+ int id ;
126
127
};
127
128
128
129
struct selftest_obj {
@@ -631,7 +632,7 @@ static void mock_dev_release(struct device *dev)
631
632
{
632
633
struct mock_dev * mdev = container_of (dev , struct mock_dev , dev );
633
634
634
- atomic_dec ( & mock_dev_num );
635
+ ida_free ( & mock_dev_ida , mdev -> id );
635
636
kfree (mdev );
636
637
}
637
638
@@ -653,8 +654,12 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags)
653
654
mdev -> dev .release = mock_dev_release ;
654
655
mdev -> dev .bus = & iommufd_mock_bus_type .bus ;
655
656
656
- rc = dev_set_name (& mdev -> dev , "iommufd_mock%u" ,
657
- atomic_inc_return (& mock_dev_num ));
657
+ rc = ida_alloc (& mock_dev_ida , GFP_KERNEL );
658
+ if (rc < 0 )
659
+ goto err_put ;
660
+ mdev -> id = rc ;
661
+
662
+ rc = dev_set_name (& mdev -> dev , "iommufd_mock%u" , mdev -> id );
658
663
if (rc )
659
664
goto err_put ;
660
665
You can’t perform that action at this time.
0 commit comments