Re: [RFC v2 1/4] cleanup: Fix discarded const warning when defining guards

From: Amir Goldstein
Date: Fri Jan 26 2024 - 09:46:29 EST


On Fri, Jan 26, 2024 at 1:57 AM Vinicius Costa Gomes
<vinicius.gomes@xxxxxxxxx> wrote:
>
> When defining guards for const types the void* return implicitly
> discards the const modifier. Be explicit about it.
>
> Compiler warning (gcc 13.2.1):
>
> ./include/linux/cleanup.h:154:18: warning: return discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
> 154 | { return *_T; }
> | ^~~
> ./include/linux/cred.h:193:1: note: in expansion of macro ‘DEFINE_GUARD’
> 193 | DEFINE_GUARD(cred, const struct cred *, _T = override_creds_light(_T),
> | ^~~~~~~~~~~~
>

I did not look closely, but can't you use DEFINE_LOCK_GUARD_1()?

Thanks,
Amir.