Re: [PATCH] iio: light: vcnl4000: Fix WARN_ON on uninitialized lock

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

 



On Mon, Jan 30, 2023 at 10:37:42AM +0100, Mårten Lindahl wrote:
> There are different init functions for the sensors in this driver in
> which only one initialize the generic vcnl4000_lock. With commit
> e21b5b1f2 ("iio: light: vcnl4000: Preserve conf bits when toggle power")
> the vcnl4040 sensor started to depend on the lock, but it was missed to
> initialize it in vcnl4040's init function. This has not been visible
> until we run lockdep on it:

>   DEBUG_LOCKS_WARN_ON(lock->magic != lock)
>   WARNING: CPU: 1 PID: 8800 at kernel/locking/mutex.c:575 __mutex_lock+0x4f8/0x890
>   ...
>   Call trace:
>    __mutex_lock
>    mutex_lock_nested
>    vcnl4200_set_power_state
>    vcnl4200_init
>    vcnl4000_probe
>    i2c_device_probe
>    really_probe
>    __driver_probe_device
>    driver_probe_device
>    __driver_attach
>    bus_for_each_dev
>    driver_attach
>    bus_add_driver
>    driver_register
>    i2c_register_driver
>    vcnl4000_driver_init
>    do_one_initcall
>    do_init_module
>    load_module
>    __do_sys_finit_module
>    ...

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages

Otherwise looks good to me,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

> Fix this by adding mutex_init on the lock in the init function used for
> vcnl4040.
> 
> Fixes: e21b5b1f2 ("iio: light: vcnl4000: Preserve conf bits when toggle power")
> Signed-off-by: Mårten Lindahl <marten.lindahl@xxxxxxxx>
> ---
>  drivers/iio/light/vcnl4000.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index cc1a2062e76d..a8a9fc3b1a02 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -316,6 +316,7 @@ static int vcnl4200_init(struct vcnl4000_data *data)
>  	}
>  	mutex_init(&data->vcnl4200_al.lock);
>  	mutex_init(&data->vcnl4200_ps.lock);
> +	mutex_init(&data->vcnl4000_lock);
>  
>  	ret = data->chip_spec->set_power_state(data, true);
>  	if (ret < 0)
> -- 
> 2.30.2
> 

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux