Re: [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 1, 2023 at 11:34 AM Nathan Chancellor <nathan@xxxxxxxxxx> wrote:
>
> Clang warns:
>
>   mm/zswap.c:1183:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>    1183 |         if (objcg && !obj_cgroup_may_zswap(objcg))
>         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   mm/zswap.c:1327:9: note: uninitialized use occurs here
>    1327 |         return ret;
>         |                ^~~
>   mm/zswap.c:1183:2: note: remove the 'if' if its condition is always false
>    1183 |         if (objcg && !obj_cgroup_may_zswap(objcg))
>         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    1184 |                 goto reject;
>         | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   mm/zswap.c:1158:9: note: initialize the variable 'ret' to silence this warning
>    1158 |         int ret;
>         |                ^
>         |                 = 0
>   1 error generated.
>
> This condition used to return -ENOMEM by going to the shrink label, so
> set ret to -ENOMEM in the if block explicitly to avoid using it
> uninitialized.
>
> Fixes: 6804144bf1cf ("zswap: do not shrink if cgroup may not zswap")
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Closes: https://lore.kernel.org/202306011435.2BxsHFUE-lkp@xxxxxxxxx/
> Closes: https://lore.kernel.org/202306012152.o4FL7Y6J-lkp@xxxxxxxxx/
> Closes: https://github.com/ClangBuiltLinux/linux/issues/1861
> Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>

Thanks!

Reviewed-by: Yosry Ahmed <yosryahmed@xxxxxxxxxx>

> ---
> Changes in v2:
> - Change ret to -ENOMEM to match this condition's previous return value
>   (Yosry)
> - Link to v1: https://lore.kernel.org/r/20230601-zswap-cgroup-wsometimes-uninitialized-v1-1-35debdd19293@xxxxxxxxxx
> ---
>  mm/zswap.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index cff93643a6ab..30092d9a3b23 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -1180,8 +1180,10 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
>          * local cgroup limits.
>          */
>         objcg = get_obj_cgroup_from_page(page);
> -       if (objcg && !obj_cgroup_may_zswap(objcg))
> +       if (objcg && !obj_cgroup_may_zswap(objcg)) {
> +               ret = -ENOMEM;
>                 goto reject;
> +       }
>
>         /* reclaim space if needed */
>         if (zswap_is_full()) {
>
> ---
> base-commit: b2424568bd9b947b2698b693ff24fec63bb4b36a
> change-id: 20230601-zswap-cgroup-wsometimes-uninitialized-b549ff4247ed
>
> Best regards,
> --
> Nathan Chancellor <nathan@xxxxxxxxxx>
>





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux