[Nouveau] drm/nouveau: fan:

Colin King (gmail) colin.i.king at gmail.com
Fri Jul 28 08:09:37 UTC 2023


Hi,

static analysis with cppcheck has detected an issue in function 
nvkm_fan_update() in drivers/gpu/drm/nouveau/nvkm/subdev/therm/fan.c as 
follows:

         /* schedule next fan update, if not at target speed already */
         if (target != duty) {
                 u16 bump_period = fan->bios.bump_period;
                 u16 slow_down_period = fan->bios.slow_down_period;
                 u64 delay;

                 if (duty > target)
                         delay = slow_down_period;
                 else if (duty == target)
                         delay = min(bump_period, slow_down_period) ;
                 else
                         delay = bump_period;

                 nvkm_timer_alarm(tmr, delay * 1000 * 1000, &fan->alarm);
         }

Checking drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c ...
drivers/gpu/drm/nouveau/nvkm/subdev/therm/fan.c:93:17: warning: Opposite 
inner 'if' condition leads to a dead code block. [oppositeInnerCondition]
   else if (duty == target)
                 ^

The first if statement checks if target != duty, however inside the code 
block there is a check if duty == target which can never be true. Either 
the logic is wrong, or the duty == target can be safely removed.

Colin


More information about the Nouveau mailing list