From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1ED0168 for ; Sat, 4 Dec 2021 22:03:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED114C341C6; Sat, 4 Dec 2021 22:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638655434; bh=KKkQKz7YaSOijVhEN1jjAuBeRAr88jX6ff5BW+zjNw8=; h=From:To:Cc:Subject:Date:From; b=ZA2VYsetzp1OCF0rdJHZ0dFEHyDo+sfyFEvJRm7rJE/gRTLicu3g9tV0E+AcV6px5 FCw35TLq/hOKTTrL4WC9/ZMJDT6WIzPS/TRLdZ/xNYfB8v1pKmmVXr5eotBBAjpF+z VrjV3eSK+DCYFCgkOoj1lMOJ1zTMqj3eZYbXbnLVT3TPwfBpK7tZVVTRaqjFWtvcgJ peWBtkUv628feX1BqTW7dlkba6hNlhnqgkgGhEA88FcvI/UY1+O2EZyPQxBR9+jF4h MtdkcoJFZk97e+TLRJupWZwaIM5WeeS3daRpzeWW4lY/aiQQOHJHtukRZxZ9G+Ezym 4kZpypqOQb6BQ== From: Arnd Bergmann To: David Howells Cc: Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Jeff Layton , linux-cachefs@redhat.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] cachefiles: fix __cachefiles_prepare_write() error handling Date: Sat, 4 Dec 2021 23:03:16 +0100 Message-Id: <20211204220350.633811-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Arnd Bergmann clang points out that __cachefiles_prepare_write() returns an uninitialized error code in one of the code paths: fs/cachefiles/io.c:489:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] if (pos == 0) ^~~~~~~~ fs/cachefiles/io.c:492:6: note: uninitialized use occurs here if (ret < 0) { ^~~ fs/cachefiles/io.c:489:2: note: remove the 'if' if its condition is always true if (pos == 0) ^~~~~~~~~~~~~ fs/cachefiles/io.c:440:9: note: initialize the variable 'ret' to silence this warning int ret; ^ Rework to return zero for success here and skip the rest of the function. Fixes: 0443b01eccbb ("cachefiles: Implement the I/O routines") Signed-off-by: Arnd Bergmann --- fs/cachefiles/io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c index 74ef4d1fc562..0fab313a604d 100644 --- a/fs/cachefiles/io.c +++ b/fs/cachefiles/io.c @@ -486,9 +486,11 @@ static int __cachefiles_prepare_write(struct netfs_cache_resources *cres, /* Partially allocated, but insufficient space: cull. */ fscache_count_no_write_space(); pos = cachefiles_inject_remove_error(); - if (pos == 0) - ret = vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - *_start, *_len); + if (pos != 0) + return 0; + + ret = vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + *_start, *_len); if (ret < 0) { trace_cachefiles_io_error(object, file_inode(file), ret, cachefiles_trace_fallocate_error); -- 2.29.2