Skip to content

Commit fea64fa

Browse files
ubizjakgregkh
authored andcommitted
devres: Correclty strip percpu address space of devm_free_percpu() argument
devm_free_percpu() calls devres_release() with a pointer in percpu address space. devres_release() expects pointers in the generic address space, so address space needs to be stripped from the argument. When strict percpu address space checks are enabled, then the current direct cast from the percpu address space to the generic address space fails the compilation on x86_64 with: devres.c:1234:32: error: cast to generic address space pointer from disjoint ‘__seg_gs’ address space pointer Add intermediate casts to unsigned long to remove address space of the pointer before casting it to the generic AS, as advised in [1] and [2]. Side note: sparse still requires __force, although the documentation [2] allows casts to unsigned long without __force attribute. Found by GCC's named address space checks. There were no changes in the resulting object file. [1] https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html#x86-Named-Address-Spaces [2] https://sparse.docs.kernel.org/en/latest/annotations.html#address-space-name Signed-off-by: Uros Bizjak <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 903c449 commit fea64fa

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/base/devres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,6 @@ void devm_free_percpu(struct device *dev, void __percpu *pdata)
12311231
* devm_free_pages() does.
12321232
*/
12331233
WARN_ON(devres_release(dev, devm_percpu_release, devm_percpu_match,
1234-
(__force void *)pdata));
1234+
(void *)(__force unsigned long)pdata));
12351235
}
12361236
EXPORT_SYMBOL_GPL(devm_free_percpu);

0 commit comments

Comments
 (0)