Skip to content

Commit f0af816

Browse files
abhijitG-xlnxgregkh
authored andcommitted
cdx: Introduce lock to protect controller ops
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration. Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com> Link: https://lore.kernel.org/r/20231017160505.10640-3-abhijit.gangurde@amd.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 54b406e commit f0af816

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/cdx/cdx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
/* IDA for CDX controllers registered with the CDX bus */
7474
static DEFINE_IDA(cdx_controller_ida);
75+
/* Lock to protect controller ops */
76+
static DEFINE_MUTEX(cdx_controller_lock);
7577

7678
static char *compat_node_name = "xlnx,versal-net-cdx";
7779

@@ -396,6 +398,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
396398
if (!val)
397399
return -EINVAL;
398400

401+
mutex_lock(&cdx_controller_lock);
402+
399403
/* Unregister all the devices on the bus */
400404
cdx_unregister_devices(&cdx_bus_type);
401405

@@ -415,6 +419,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
415419
put_device(&pd->dev);
416420
}
417421

422+
mutex_unlock(&cdx_controller_lock);
423+
418424
return count;
419425
}
420426
static BUS_ATTR_WO(rescan);
@@ -538,12 +544,14 @@ int cdx_register_controller(struct cdx_controller *cdx)
538544
return ret;
539545
}
540546

547+
mutex_lock(&cdx_controller_lock);
541548
cdx->id = ret;
542549

543550
/* Scan all the devices */
544551
if (cdx->ops->scan)
545552
cdx->ops->scan(cdx);
546553
cdx->controller_registered = true;
554+
mutex_unlock(&cdx_controller_lock);
547555

548556
return 0;
549557
}
@@ -554,9 +562,13 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
554562
if (cdx->id >= MAX_CDX_CONTROLLERS)
555563
return;
556564

565+
mutex_lock(&cdx_controller_lock);
566+
557567
cdx->controller_registered = false;
558568
device_for_each_child(cdx->dev, NULL, cdx_unregister_device);
559569
ida_free(&cdx_controller_ida, cdx->id);
570+
571+
mutex_unlock(&cdx_controller_lock);
560572
}
561573
EXPORT_SYMBOL_GPL(cdx_unregister_controller);
562574

0 commit comments

Comments
 (0)