Skip to content

Commit 7e5a772

Browse files
committed
firewire: core: replace IDR with XArray to maintain fw_device
In core function, the instances of fw_device corresponding to firewire device node in system are maintained by IDR. As of kernel v6.0, IDR has been superseded by XArray and deprecated. This commit replaces the usage of IDR with XArray to maintain the device instances. The instance of XArray is allocated statically, and initialized with XA_FLAGS_ALLOC so that the index of allocated entry starts with zero and available as the minor identifier of device node. Link: https://lore.kernel.org/r/20240812014251.165492-2-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent ebb9d3c commit 7e5a772

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

drivers/firewire/core-device.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/errno.h>
1313
#include <linux/firewire.h>
1414
#include <linux/firewire-constants.h>
15-
#include <linux/idr.h>
1615
#include <linux/jiffies.h>
1716
#include <linux/kobject.h>
1817
#include <linux/list.h>
@@ -813,7 +812,7 @@ static int shutdown_unit(struct device *device, void *data)
813812
*/
814813
DECLARE_RWSEM(fw_device_rwsem);
815814

816-
DEFINE_IDR(fw_device_idr);
815+
DEFINE_XARRAY_ALLOC(fw_device_xa);
817816
int fw_cdev_major;
818817

819818
struct fw_device *fw_device_get_by_devt(dev_t devt)
@@ -822,7 +821,7 @@ struct fw_device *fw_device_get_by_devt(dev_t devt)
822821

823822
guard(rwsem_read)(&fw_device_rwsem);
824823

825-
device = idr_find(&fw_device_idr, MINOR(devt));
824+
device = xa_load(&fw_device_xa, MINOR(devt));
826825
if (device)
827826
fw_device_get(device);
828827

@@ -858,7 +857,6 @@ static void fw_device_shutdown(struct work_struct *work)
858857
{
859858
struct fw_device *device =
860859
container_of(work, struct fw_device, work.work);
861-
int minor = MINOR(device->device.devt);
862860

863861
if (time_before64(get_jiffies_64(),
864862
device->card->reset_jiffies + SHUTDOWN_DELAY)
@@ -877,7 +875,7 @@ static void fw_device_shutdown(struct work_struct *work)
877875
device_unregister(&device->device);
878876

879877
scoped_guard(rwsem_write, &fw_device_rwsem)
880-
idr_remove(&fw_device_idr, minor);
878+
xa_erase(&fw_device_xa, MINOR(device->device.devt));
881879

882880
fw_device_put(device);
883881
}
@@ -1049,7 +1047,8 @@ static void fw_device_init(struct work_struct *work)
10491047
container_of(work, struct fw_device, work.work);
10501048
struct fw_card *card = device->card;
10511049
struct device *revived_dev;
1052-
int minor, ret;
1050+
u32 minor;
1051+
int ret;
10531052

10541053
/*
10551054
* All failure paths here set node->data to NULL, so that we
@@ -1087,9 +1086,11 @@ static void fw_device_init(struct work_struct *work)
10871086
device_initialize(&device->device);
10881087

10891088
fw_device_get(device);
1089+
10901090
scoped_guard(rwsem_write, &fw_device_rwsem) {
1091-
minor = idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS, GFP_KERNEL);
1092-
if (minor < 0)
1091+
// The index of allocated entry is used for minor identifier of device node.
1092+
ret = xa_alloc(&fw_device_xa, &minor, device, XA_LIMIT(0, MINORMASK), GFP_KERNEL);
1093+
if (ret < 0)
10931094
goto error;
10941095
}
10951096

@@ -1152,9 +1153,9 @@ static void fw_device_init(struct work_struct *work)
11521153

11531154
error_with_cdev:
11541155
scoped_guard(rwsem_write, &fw_device_rwsem)
1155-
idr_remove(&fw_device_idr, minor);
1156+
xa_erase(&fw_device_xa, minor);
11561157
error:
1157-
fw_device_put(device); /* fw_device_idr's reference */
1158+
fw_device_put(device); // fw_device_xa's reference.
11581159

11591160
put_device(&device->device); /* our reference */
11601161
}

drivers/firewire/core-transaction.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/firewire-constants.h>
1414
#include <linux/fs.h>
1515
#include <linux/init.h>
16-
#include <linux/idr.h>
1716
#include <linux/jiffies.h>
1817
#include <linux/kernel.h>
1918
#include <linux/list.h>
@@ -1359,7 +1358,7 @@ static void __exit fw_core_cleanup(void)
13591358
unregister_chrdev(fw_cdev_major, "firewire");
13601359
bus_unregister(&fw_bus_type);
13611360
destroy_workqueue(fw_workqueue);
1362-
idr_destroy(&fw_device_idr);
1361+
xa_destroy(&fw_device_xa);
13631362
}
13641363

13651364
module_init(fw_core_init);

drivers/firewire/core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/fs.h>
99
#include <linux/list.h>
1010
#include <linux/idr.h>
11+
#include <linux/xarray.h>
1112
#include <linux/mm_types.h>
1213
#include <linux/rwsem.h>
1314
#include <linux/slab.h>
@@ -133,7 +134,7 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p);
133134
/* -device */
134135

135136
extern struct rw_semaphore fw_device_rwsem;
136-
extern struct idr fw_device_idr;
137+
extern struct xarray fw_device_xa;
137138
extern int fw_cdev_major;
138139

139140
static inline struct fw_device *fw_device_get(struct fw_device *device)

0 commit comments

Comments
 (0)