patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store()
@ 2023-06-01 18:34 Nathan Chancellor
  2023-06-01 18:35 ` Yosry Ahmed
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2023-06-01 18:34 UTC (permalink / raw)
  To: akpm, sjenning, ddstreet, vitaly.wool
  Cc: nphamcs, yosryahmed, ndesaulniers, trix, linux-mm, llvm, patches,
	kernel test robot, Nathan Chancellor

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@intel.com>
Closes: https://lore.kernel.org/202306011435.2BxsHFUE-lkp@intel.com/
Closes: https://lore.kernel.org/202306012152.o4FL7Y6J-lkp@intel.com/
Closes: https://github.com/ClangBuiltLinux/linux/issues/1861
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
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@kernel.org
---
 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@kernel.org>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store()
  2023-06-01 18:34 [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store() Nathan Chancellor
@ 2023-06-01 18:35 ` Yosry Ahmed
  2023-06-01 19:21   ` Nhat Pham
  0 siblings, 1 reply; 3+ messages in thread
From: Yosry Ahmed @ 2023-06-01 18:35 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: akpm, sjenning, ddstreet, vitaly.wool, nphamcs, ndesaulniers,
	trix, linux-mm, llvm, patches, kernel test robot

On Thu, Jun 1, 2023 at 11:34 AM Nathan Chancellor <nathan@kernel.org> 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@intel.com>
> Closes: https://lore.kernel.org/202306011435.2BxsHFUE-lkp@intel.com/
> Closes: https://lore.kernel.org/202306012152.o4FL7Y6J-lkp@intel.com/
> Closes: https://github.com/ClangBuiltLinux/linux/issues/1861
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks!

Reviewed-by: Yosry Ahmed <yosryahmed@google.com>

> ---
> 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@kernel.org
> ---
>  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@kernel.org>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store()
  2023-06-01 18:35 ` Yosry Ahmed
@ 2023-06-01 19:21   ` Nhat Pham
  0 siblings, 0 replies; 3+ messages in thread
From: Nhat Pham @ 2023-06-01 19:21 UTC (permalink / raw)
  To: Yosry Ahmed
  Cc: Nathan Chancellor, akpm, sjenning, ddstreet, vitaly.wool,
	ndesaulniers, trix, linux-mm, llvm, patches, kernel test robot

On Thu, Jun 1, 2023 at 11:36 AM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> On Thu, Jun 1, 2023 at 11:34 AM Nathan Chancellor <nathan@kernel.org> 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@intel.com>
> > Closes: https://lore.kernel.org/202306011435.2BxsHFUE-lkp@intel.com/
> > Closes: https://lore.kernel.org/202306012152.o4FL7Y6J-lkp@intel.com/
> > Closes: https://github.com/ClangBuiltLinux/linux/issues/1861
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
>
> Thanks!
>
> Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
>
> > ---
> > 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@kernel.org
> > ---
> >  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@kernel.org>
> >
Acked-by: Nhat Pham <nphamcs@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-01 19:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 18:34 [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store() Nathan Chancellor
2023-06-01 18:35 ` Yosry Ahmed
2023-06-01 19:21   ` Nhat Pham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).