]> www.infradead.org Git - users/jedix/linux-maple.git/commit
devres: Correclty strip percpu address space of devm_free_percpu() argument
authorUros Bizjak <ubizjak@gmail.com>
Fri, 30 Aug 2024 08:33:52 +0000 (10:33 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Sep 2024 11:15:21 +0000 (13:15 +0200)
commitfea64fa04c31426eae512751e0c5342345c5741c
treed359168770732edf1081bd821d3ba8eef85c402e
parent903c44939abc02e2f3d6f2ad65fa090f7e5df5b6
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 <ubizjak@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/20240830083406.9695-1-ubizjak@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/devres.c