Re: [PATCH] hwmon: emc2103: use min_t() for explicit type in fan target clamp
From: Guenter Roeck
Date: Mon Jul 06 2026 - 16:40:02 EST
On 7/6/26 12:57, David Laight wrote:
On Mon, 6 Jul 2026 21:55:19 +0530
Animesh Rai <animeshrai853@xxxxxxxxx> wrote:
Using min() with an explicit cast on one operand is fragile. Replace
with min_t(u16, ...) to make the intended comparison type explicit and
avoid implicit type conversion.
min_t() is worse than having a cast on the argument to min().
It just casts both arguments to the specified type.
If you'd tried you's have found you could have just deleted the cast.
But why is new_target u16, it could just be 'unsigned int'.
That saves a load of masking instructions.
Were old_div 9 and new_div 1 the rescale could overflow 16 bits,
overflowing 32 is much less likely.
(The surrounding code may make the overflow impossible...)
If the code even right?
It ignores values 0x1fe0 to 0x1fff (assuming the high bits can't
be set) so they must be 'special' in some way, but doesn't stop the
same 'special' values being generated when rescaled.
No, it isn't, as reported by Sashiko. So the patch does not improve
anything while at the same time ignoring the real problems in the
driver.
Guenter