[PATCH] media: staging: ipu3: img-mmu: fix sign-to-unsigned conversion

Richard Lyu posted 1 patch 1 month ago
There is a newer version of this series
drivers/staging/media/ipu3/ipu3-mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] media: staging: ipu3: img-mmu: fix sign-to-unsigned conversion
Posted by Richard Lyu 1 month ago
imgu_mmu_unmap() returns size_t (unsigned), representing the number of
bytes successfully unmapped. However, when the alignment check fails,
it currently returns -EINVAL.

On 64-bit systems, this negative error code is implicitly converted
to a very large unsigned value (18446744073709551594), incorrectly
indicating that memory was unmapped and potentially breaking the
caller's logic.

Return 0 when the alignment check fails to correctly indicate that
no bytes were unmapped while resolving the following
-Wsign-conversion warning:

drivers/staging/media/ipu3/ipu3-mmu.c:393:24: warning: unsigned
conversion from 'int' to 'size_t' {aka 'long unsigned int'} changes
value from '-22' to '18446744073709551594' [-Wsign-conversion]
  393 |         return -EINVAL;

Signed-off-by: Richard Lyu <richard.lyu@suse.com>
---
 drivers/staging/media/ipu3/ipu3-mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c
index b196a5815903..fcea125e5935 100644
--- a/drivers/staging/media/ipu3/ipu3-mmu.c
+++ b/drivers/staging/media/ipu3/ipu3-mmu.c
@@ -390,7 +390,7 @@ size_t imgu_mmu_unmap(struct imgu_mmu_info *info, unsigned long iova,
 	if (!IS_ALIGNED(iova | size, IPU3_PAGE_SIZE)) {
 		dev_err(mmu->dev, "unaligned: iova 0x%lx size 0x%zx\n",
 			iova, size);
-		return -EINVAL;
+		return 0;
 	}
 
 	dev_dbg(mmu->dev, "unmap this: iova 0x%lx size 0x%zx\n", iova, size);
-- 
2.51.0
Re: [PATCH] media: staging: ipu3: img-mmu: fix sign-to-unsigned conversion
Posted by Dan Carpenter 1 month ago
On Fri, Mar 06, 2026 at 06:43:59PM +0800, Richard Lyu wrote:
> imgu_mmu_unmap() returns size_t (unsigned), representing the number of
> bytes successfully unmapped. However, when the alignment check fails,
> it currently returns -EINVAL.
> 
> On 64-bit systems, this negative error code is implicitly converted
> to a very large unsigned value (18446744073709551594),

That happens on a 32bit also, although of course, the number would be
smaller.

> incorrectly
> indicating that memory was unmapped and potentially breaking the
> caller's logic.
> 

All the callers ignore the return value so it doesn't actually affect
anything.  The commit message needs to say this.

> Return 0 when the alignment check fails to correctly indicate that
> no bytes were unmapped while resolving the following
> -Wsign-conversion warning:
> 
> drivers/staging/media/ipu3/ipu3-mmu.c:393:24: warning: unsigned
> conversion from 'int' to 'size_t' {aka 'long unsigned int'} changes
> value from '-22' to '18446744073709551594' [-Wsign-conversion]
>   393 |         return -EINVAL;
> 
> Signed-off-by: Richard Lyu <richard.lyu@suse.com>

Please add a Fixes tag.

Otherwise, the fix looks okay to me.

regards,
dan carpenter