diff mbox series

[3/8] btrfs: fix uninit warning from get_inode_gen usage

Message ID aa2e624f5626b37a267ea123baf7db2d76be41ee.1671221596.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Fixup uninitialized warnings and enable extra checks | expand

Commit Message

Josef Bacik Dec. 16, 2022, 8:15 p.m. UTC
Anybody that calls get_inode_gen() can have an uninitialized gen if
there's an error.  This isn't a big deal because all the users just exit
if they get an error, however it makes -Wmaybe-uninitialized complain,
so fix this up to always init the passed in gen, this quiets all of the
uninitialized warnings in send.c.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/send.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Qu Wenruo Dec. 17, 2022, 12:16 a.m. UTC | #1
On 2022/12/17 04:15, Josef Bacik wrote:
> Anybody that calls get_inode_gen() can have an uninitialized gen if
> there's an error.  This isn't a big deal because all the users just exit
> if they get an error, however it makes -Wmaybe-uninitialized complain,
> so fix this up to always init the passed in gen, this quiets all of the
> uninitialized warnings in send.c.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/send.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
> index 67f7c698ade3..25a235179edb 100644
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -955,14 +955,12 @@ static int get_inode_info(struct btrfs_root *root, u64 ino,
>   static int get_inode_gen(struct btrfs_root *root, u64 ino, u64 *gen)
>   {
>   	int ret;
> -	struct btrfs_inode_info info;
> +	struct btrfs_inode_info info = {};
>   
> -	if (!gen)
> -		return -EPERM;
> +	ASSERT(gen);
>   
>   	ret = get_inode_info(root, ino, &info);
> -	if (!ret)
> -		*gen = info.gen;
> +	*gen = info.gen;
>   	return ret;
>   }
>
Johannes Thumshirn Dec. 19, 2022, 7:55 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
David Sterba Dec. 20, 2022, 7:16 p.m. UTC | #3
On Fri, Dec 16, 2022 at 03:15:53PM -0500, Josef Bacik wrote:
> Anybody that calls get_inode_gen() can have an uninitialized gen if
> there's an error.  This isn't a big deal because all the users just exit
> if they get an error, however it makes -Wmaybe-uninitialized complain,
> so fix this up to always init the passed in gen, this quiets all of the
> uninitialized warnings in send.c.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/send.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
> index 67f7c698ade3..25a235179edb 100644
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -955,14 +955,12 @@ static int get_inode_info(struct btrfs_root *root, u64 ino,
>  static int get_inode_gen(struct btrfs_root *root, u64 ino, u64 *gen)
>  {
>  	int ret;
> -	struct btrfs_inode_info info;
> +	struct btrfs_inode_info info = {};

The { 0 } initializer should be used.
diff mbox series

Patch

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 67f7c698ade3..25a235179edb 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -955,14 +955,12 @@  static int get_inode_info(struct btrfs_root *root, u64 ino,
 static int get_inode_gen(struct btrfs_root *root, u64 ino, u64 *gen)
 {
 	int ret;
-	struct btrfs_inode_info info;
+	struct btrfs_inode_info info = {};
 
-	if (!gen)
-		return -EPERM;
+	ASSERT(gen);
 
 	ret = get_inode_info(root, ino, &info);
-	if (!ret)
-		*gen = info.gen;
+	*gen = info.gen;
 	return ret;
 }