Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bnxt_en: fix ternary sign extension bug in bnxt_show_temp()

The problem is that bnxt_show_temp() returns long but "rc" is an int
and "len" is a u32. With ternary operations the type promotion is quite
tricky. The negative "rc" is first promoted to u32 and then to long so
it ends up being a high positive value instead of a a negative as we
intended.

Fix this by removing the ternary.

Fixes: d69753fa1ecb ("bnxt_en: return proper error codes in bnxt_show_temp")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Dan Carpenter and committed by
David S. Miller
27537929 e7679c55

+3 -1
+3 -1
drivers/net/ethernet/broadcom/bnxt/bnxt.c
··· 9736 9736 if (!rc) 9737 9737 len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */ 9738 9738 mutex_unlock(&bp->hwrm_cmd_lock); 9739 - return rc ?: len; 9739 + if (rc) 9740 + return rc; 9741 + return len; 9740 9742 } 9741 9743 static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0); 9742 9744