From 67ff14c5d0b13db11844f4932e656df1ec078545 Mon Sep 17 00:00:00 2001 From: Sudeep Holla Date: Fri, 21 Feb 2025 09:56:31 +0000 Subject: [PATCH] UPSTREAM: firmware: arm_ffa: Explicitly cast return value from FFA_VERSION before comparison The return value ver.a0 is unsigned long type and FFA_RET_NOT_SUPPORTED is a negative value. Since the return value from the firmware can be just 32-bit even on 64-bit systems as FFA specification mentions it as int32 error code in w0 register, explicitly casting to s32 ensures correct sign interpretation when comparing against a signed error code FFA_RET_NOT_SUPPORTED. Without casting, comparison between unsigned long and a negative constant could lead to unintended results due to type promotions. Fixes: 3bbfe9871005 ("firmware: arm_ffa: Add initial Arm FFA driver support") Reported-by: Andrei Homescu Message-Id: <20250221095633.506678-1-sudeep.holla@arm.com> Change-Id: I383762ec971bce54f3d8aef564ebfca3b3ab2a0e Signed-off-by: Sudeep Holla (cherry picked from commit cecf6a504137aa238d768ae440a1f6488cb2f436) Signed-off-by: Andrei Homescu Bug: 435501117 --- drivers/firmware/arm_ffa/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 846c4948fcfd..da2703c04474 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -121,7 +121,7 @@ static int ffa_version_check(u32 *version) .a0 = FFA_VERSION, .a1 = FFA_DRIVER_VERSION, }, &ver); - if (ver.a0 == FFA_RET_NOT_SUPPORTED) { + if ((s32)ver.a0 == FFA_RET_NOT_SUPPORTED) { pr_info("FFA_VERSION returned not supported\n"); return -EOPNOTSUPP; }