Message ID | 20171006130459.29127-2-marek.behun@nic.cz |
---|---|
State | Accepted |
Commit | ecab881c7fcd7484420b6aa15b0f748458640191 |
Delegated to: | Tom Rini |
Headers | show |
Series | [U-Boot,1/4] linux/time.h: Remove dead code | expand |
On Fri, 6 Oct 2017 06:54:34 -0700 "J. William Campbell" <jwilliamcampbell@comcast.net> wrote: > Hi Marek, > If the searched key is not found, isn't it an error to use > the res value AT ALL? Setting it to 0 may cover up the warning, but > the function shouldn't actually use it for anything. If it does, it > is modifying an element that doesn't match the search key. Hi Bill, the res variable is just an indicator if an error occured. In these functions if no key is found, it is not an error (for example if no key is found in btrfs_readdir, it just means the directory is empty, which is not an error). Marek > > Best Regards, > Bill Campbell
On Fri, Oct 06, 2017 at 03:04:57PM +0200, Marek Behún wrote: > The variable res should be initialized to 0 in these functions, > because if the searched key is not found, the variable is used > uninitialized. > > Reported-by: Coverity (CID: 167335) > Reported-by: Coverity (CID: 167336) > Reported-by: Coverity (CID: 167337) > Signed-off-by: Marek Behun <marek.behun@nic.cz> Applied to u-boot/master, thanks!
diff --git a/fs/btrfs/chunk-map.c b/fs/btrfs/chunk-map.c index 48407f3331..ce7330b1b7 100644 --- a/fs/btrfs/chunk-map.c +++ b/fs/btrfs/chunk-map.c @@ -147,7 +147,7 @@ int btrfs_read_chunk_tree(void) struct btrfs_path path; struct btrfs_key key, *found_key; struct btrfs_chunk *chunk; - int res; + int res = 0; key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; key.type = BTRFS_CHUNK_ITEM_KEY; diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index decf86eb53..970563404f 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -93,7 +93,7 @@ int btrfs_readdir(const struct btrfs_root *root, u64 dir, struct btrfs_path path; struct btrfs_key key, *found_key; struct btrfs_dir_item *item; - int res; + int res = 0; key.objectid = dir; key.type = BTRFS_DIR_INDEX_KEY; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0d3da28296..0af04278a3 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -324,7 +324,7 @@ u64 btrfs_file_read(const struct btrfs_root *root, u64 inr, u64 offset, struct btrfs_path path; struct btrfs_key key; struct btrfs_file_extent_item *extent; - int res; + int res = 0; u64 rd, rd_all = -1ULL; key.objectid = inr;
The variable res should be initialized to 0 in these functions, because if the searched key is not found, the variable is used uninitialized. Reported-by: Coverity (CID: 167335) Reported-by: Coverity (CID: 167336) Reported-by: Coverity (CID: 167337) Signed-off-by: Marek Behun <marek.behun@nic.cz> --- fs/btrfs/chunk-map.c | 2 +- fs/btrfs/dir-item.c | 2 +- fs/btrfs/inode.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)