Re: [PATCH 1/2] staging: iio: ad2s1210: Destroy mutex at remove

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 18 May 2019 19:15:57 -0300
Tallys Martins <tallysmartins@xxxxxxxxx> wrote:

> Ensure the mutex will be destroyed on drive removal.
> Also adds mutex comment description.
> 
> Signed-off-by: Tallys Martins <tallysmartins@xxxxxxxxx>
> Signed-off-by: Souza Guilherme <gdsdsilva@xxxxxxxxxxxxxxxx>
> Co-developed-by: Souza Guilherme <gdsdsilva@xxxxxxxxxxxxxxxx>
Hi.

This particular 'issue' is never a simple one.

The destroy_mutex call is intended for lock debugging only,
which is why there is devm_init_mutex or similar to allow for
automatic unwinding. 

It simple cleanup paths like this, it provides very little value
and leads to a more complex unwind.

It is for this reason that the vast majority of drivers simply
don't bother.

Hence, unless there is a good reason I'm missing I won't be
introducing more of them.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/resolver/ad2s1210.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
> index b6be0bc202f5..b91cf57c5e57 100644
> --- a/drivers/staging/iio/resolver/ad2s1210.c
> +++ b/drivers/staging/iio/resolver/ad2s1210.c
> @@ -86,7 +86,7 @@ static const struct ad2s1210_gpio gpios[] = {
>  static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 };
>  
>  struct ad2s1210_state {
> -	struct mutex lock;
> +	struct mutex lock; /* lock to protect the state on r/w operations */
>  	struct spi_device *sdev;
>  	struct gpio_desc *gpios[5];
>  	unsigned int fclkin;
> @@ -689,8 +689,10 @@ static int ad2s1210_probe(struct spi_device *spi)
>  static int ad2s1210_remove(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev = spi_get_drvdata(spi);
> +	struct ad2s1210_state *ad2s1210_ad = iio_priv(indio_dev);
>  
>  	iio_device_unregister(indio_dev);
> +	mutex_destroy(&ad2s1210_ad->lock);
>  
>  	return 0;
>  }

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux