Re: [PATCH 3/5] hwmon: (gpio-fan) Ensure lock is held during set_fan_speed()

From: Guenter Roeck
Date: Sun Mar 02 2025 - 11:54:36 EST


On Mon, Feb 10, 2025 at 03:59:31PM +0100, Alexander Stein wrote:
> Instead of just documenting by comment, ensure locking per code.
>
> Signed-off-by: Alexander Stein <alexander.stein@xxxxxxxxxxxxxxx>
> ---
> drivers/hwmon/gpio-fan.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
> index b779240328d59..322b161d5ca1f 100644
> --- a/drivers/hwmon/gpio-fan.c
> +++ b/drivers/hwmon/gpio-fan.c
> @@ -124,9 +124,10 @@ static int __get_fan_ctrl(struct gpio_fan_data *fan_data)
> return ctrl_val;
> }
>
> -/* Must be called with fan_data->lock held, except during initialization. */
> static void set_fan_speed(struct gpio_fan_data *fan_data, int speed_index)
> {
> + WARN_ON_ONCE(!mutex_is_locked(&fan_data->lock));
> +

No, this just increases code size for no good reason. The comment is
perfectly fine and sufficient.

Guenter