]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
firmware: arm_scpi: Prevent the ternary sign expansion bug
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 22 Apr 2021 09:02:29 +0000 (12:02 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 18 Jun 2021 13:02:28 +0000 (15:02 +0200)
commit9616880c56832f300208eff149599bf2792d9c93
tree58a7a815cad5b656d8535c14f16d89465ceba04b
parent76b4378094cd830a9d4adb2450c87c92269ad388
firmware: arm_scpi: Prevent the ternary sign expansion bug

BugLink: https://bugs.launchpad.net/bugs/1931159
[ Upstream commit d9cd78edb2e6b7e26747c0ec312be31e7ef196fe ]

How the type promotion works in ternary expressions is a bit tricky.
The problem is that scpi_clk_get_val() returns longs, "ret" is a int
which holds a negative error code, and le32_to_cpu() is an unsigned int.
We want the negative error code to be cast to a negative long.  But
because le32_to_cpu() is an u32 then "ret" is type promoted to u32 and
becomes a high positive and then it is promoted to long and it is still
a high positive value.

Fix this by getting rid of the ternary.

Link: https://lore.kernel.org/r/YIE7pdqV/h10tEAK@mwanda
Fixes: 8cb7cf56c9fe ("firmware: add support for ARM System Control and Power Interface(SCPI) protocol")
Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
[sudeep.holla: changed to return 0 as clock rate on error]
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/firmware/arm_scpi.c