History

hwmon: (gpio-fan) take fan_data->lock in gpio_fan_shutdown()

set_fan_speed() writes the control GPIOs one bit at a time. Every other caller locks around it; gpio_fan_shutdown() doesn't. If it races a locked caller, the GPIO writes can interleave and leave the fan at a speed neither caller asked for.

Cong Nguyen committed 2 months ago

Commit bb2424c1 parent 508baf11 file · +4 −1Browse files

Unified · Split

drivers/hwmon/gpio-fan.c+4−1
@@ -612,8 +612,11 @@ static void gpio_fan_shutdown(struct platform_device *pdev) · 611 unmodified lines
612612 {
613613 struct gpio_fan_data *fan_data = platform_get_drvdata(pdev);
614614
615− if (fan_data->gpios)
615+ if (fan_data->gpios) {
616+ mutex_lock(&fan_data->lock);
616617 set_fan_speed(fan_data, 0);
618+ mutex_unlock(&fan_data->lock);
619+ }
617620 }
618621
619622 static int gpio_fan_runtime_suspend(struct device *dev)