Skip to content

Commit 7a0a57c

Browse files
committed
firewire: core: use lock in Xarray instead of local R/W semaphore
The data of XArray structure includes spinlock and requires no external lock, while the data is still under the critical section by fw_device_rwsem. This commit deletes the critical section. Link: https://lore.kernel.org/r/20240812014251.165492-3-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent 7e5a772 commit 7a0a57c

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

drivers/firewire/core-device.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ static int shutdown_unit(struct device *device, void *data)
806806

807807
/*
808808
* fw_device_rwsem acts as dual purpose mutex:
809-
* - serializes accesses to fw_device_idr,
810809
* - serializes accesses to fw_device.config_rom/.config_rom_length and
811810
* fw_unit.directory, unless those accesses happen at safe occasions
812811
*/
@@ -819,8 +818,6 @@ struct fw_device *fw_device_get_by_devt(dev_t devt)
819818
{
820819
struct fw_device *device;
821820

822-
guard(rwsem_read)(&fw_device_rwsem);
823-
824821
device = xa_load(&fw_device_xa, MINOR(devt));
825822
if (device)
826823
fw_device_get(device);
@@ -874,8 +871,7 @@ static void fw_device_shutdown(struct work_struct *work)
874871
device_for_each_child(&device->device, NULL, shutdown_unit);
875872
device_unregister(&device->device);
876873

877-
scoped_guard(rwsem_write, &fw_device_rwsem)
878-
xa_erase(&fw_device_xa, MINOR(device->device.devt));
874+
xa_erase(&fw_device_xa, MINOR(device->device.devt));
879875

880876
fw_device_put(device);
881877
}
@@ -1087,12 +1083,10 @@ static void fw_device_init(struct work_struct *work)
10871083

10881084
fw_device_get(device);
10891085

1090-
scoped_guard(rwsem_write, &fw_device_rwsem) {
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)
1094-
goto error;
1095-
}
1086+
// The index of allocated entry is used for minor identifier of device node.
1087+
ret = xa_alloc(&fw_device_xa, &minor, device, XA_LIMIT(0, MINORMASK), GFP_KERNEL);
1088+
if (ret < 0)
1089+
goto error;
10961090

10971091
device->device.bus = &fw_bus_type;
10981092
device->device.type = &fw_device_type;
@@ -1152,8 +1146,7 @@ static void fw_device_init(struct work_struct *work)
11521146
return;
11531147

11541148
error_with_cdev:
1155-
scoped_guard(rwsem_write, &fw_device_rwsem)
1156-
xa_erase(&fw_device_xa, minor);
1149+
xa_erase(&fw_device_xa, minor);
11571150
error:
11581151
fw_device_put(device); // fw_device_xa's reference.
11591152

0 commit comments

Comments
 (0)