Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list

From: Greg KH
Date: Mon Jul 31 2023 - 08:38:07 EST


On Mon, Jul 31, 2023 at 05:38:10PM +0530, Abhijit Gangurde wrote:
> 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@xxxxxxx>
> ---
> drivers/cdx/cdx.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
> index d2cad4c670a0..66797c8fe400 100644
> --- a/drivers/cdx/cdx.c
> +++ b/drivers/cdx/cdx.c
> @@ -72,6 +72,8 @@
>
> /* CDX controllers registered with the CDX bus */
> static DEFINE_XARRAY_ALLOC(cdx_controllers);
> +/* Lock to protect controller ops and controller list */
> +static DEFINE_MUTEX(cdx_controller_lock);

Wait, why do you have a local list and not just rely on the list the
driver core has for you already? Isn't this a duplicate list where you
have objects on two different lists with a lifespan controlled only by
one of them?

thanks,

greg k-h