Skip to contentSkip to conversation

cleanup: Fix sparse complaining about passing iomem ptr to no_free_ptr()

PATCH Superseded Ilpo Järvinen 1 participant 1 message Mar 26, 2024 x86 platform drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ilpo Järvinen

author maintainer
#0 lore raw

PATCH 1/1 cleanup: Fix sparse complaining about passing iomem ptr to no_free_ptr()

Calling no_free_ptr() for an __iomem pointer results in sparse complaining about the types:
sparse: warning: incorrect type in argument 1 (different address spaces)
sparse: expected void const volatile *val
sparse: got void [noderef] __iomem *__val
(The example from drivers/platform/x86/intel/pmc/core_ssram.c:277).

The problem is caused by the signature of __must_check_fn() added in the commit 85be6d842447 ("cleanup: Make no_free_ptr() __must_check") to enforce return value is always used.

Use __force to allow both iomem and non-iomem pointers to be given for no_free_ptr().

---
 include/linux/cleanup.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/cleanup.h +1 -1
index c2d09bc4f976..4f4d709c3967 100644
@@ -73,7 +73,7 @@ const volatile void * __must_check_fn(const volatile void *val)
 { return val; }
 
 #define no_free_ptr(p) \
-	((typeof(p)) __must_check_fn(__get_and_null_ptr(p)))
+	((typeof(p)) __must_check_fn((__force const volatile void *)__get_and_null_ptr(p)))
 
 #define return_ptr(p)	return no_free_ptr(p)
 
Signature · 1 line
2.39.2