72
72
73
73
/* IDA for CDX controllers registered with the CDX bus */
74
74
static DEFINE_IDA (cdx_controller_ida );
75
+ /* Lock to protect controller ops */
76
+ static DEFINE_MUTEX (cdx_controller_lock );
75
77
76
78
static char * compat_node_name = "xlnx,versal-net-cdx" ;
77
79
@@ -396,6 +398,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
396
398
if (!val )
397
399
return - EINVAL ;
398
400
401
+ mutex_lock (& cdx_controller_lock );
402
+
399
403
/* Unregister all the devices on the bus */
400
404
cdx_unregister_devices (& cdx_bus_type );
401
405
@@ -415,6 +419,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
415
419
put_device (& pd -> dev );
416
420
}
417
421
422
+ mutex_unlock (& cdx_controller_lock );
423
+
418
424
return count ;
419
425
}
420
426
static BUS_ATTR_WO (rescan );
@@ -538,12 +544,14 @@ int cdx_register_controller(struct cdx_controller *cdx)
538
544
return ret ;
539
545
}
540
546
547
+ mutex_lock (& cdx_controller_lock );
541
548
cdx -> id = ret ;
542
549
543
550
/* Scan all the devices */
544
551
if (cdx -> ops -> scan )
545
552
cdx -> ops -> scan (cdx );
546
553
cdx -> controller_registered = true;
554
+ mutex_unlock (& cdx_controller_lock );
547
555
548
556
return 0 ;
549
557
}
@@ -554,9 +562,13 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
554
562
if (cdx -> id >= MAX_CDX_CONTROLLERS )
555
563
return ;
556
564
565
+ mutex_lock (& cdx_controller_lock );
566
+
557
567
cdx -> controller_registered = false;
558
568
device_for_each_child (cdx -> dev , NULL , cdx_unregister_device );
559
569
ida_free (& cdx_controller_ida , cdx -> id );
570
+
571
+ mutex_unlock (& cdx_controller_lock );
560
572
}
561
573
EXPORT_SYMBOL_GPL (cdx_unregister_controller );
562
574
0 commit comments