All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: akpm@linux-foundation.org, sjenning@redhat.com,
	ddstreet@ieee.org,  vitaly.wool@konsulko.com
Cc: nphamcs@gmail.com, yosryahmed@google.com,
	ndesaulniers@google.com,  trix@redhat.com, linux-mm@kvack.org,
	llvm@lists.linux.dev,  patches@lists.linux.dev,
	kernel test robot <lkp@intel.com>,
	 Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store()
Date: Thu, 01 Jun 2023 11:34:26 -0700	[thread overview]
Message-ID: <20230601-zswap-cgroup-wsometimes-uninitialized-v2-1-84912684ac35@kernel.org> (raw)

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>


             reply	other threads:[~2023-06-01 18:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 18:34 Nathan Chancellor [this message]
2023-06-01 18:35 ` [PATCH v2] zswap: Avoid uninitialized use of ret in zswap_frontswap_store() Yosry Ahmed
2023-06-01 19:21   ` Nhat Pham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230601-zswap-cgroup-wsometimes-uninitialized-v2-1-84912684ac35@kernel.org \
    --to=nathan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ddstreet@ieee.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=ndesaulniers@google.com \
    --cc=nphamcs@gmail.com \
    --cc=patches@lists.linux.dev \
    --cc=sjenning@redhat.com \
    --cc=trix@redhat.com \
    --cc=vitaly.wool@konsulko.com \
    --cc=yosryahmed@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.