public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: dennis@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [bug report] btrfs: change set_level() to bound the level passed in
Date: Thu, 7 Feb 2019 16:40:45 +0100	[thread overview]
Message-ID: <20190207154045.GI2900@twin.jikos.cz> (raw)
In-Reply-To: <20190207103647.GA15902@kadam>

On Thu, Feb 07, 2019 at 01:36:47PM +0300, Dan Carpenter wrote:
> Hello Dennis Zhou,
> 
> The patch a67dc67a2cb8: "btrfs: change set_level() to bound the level
> passed in" from Jan 28, 2019, leads to the following static checker
> warning:
> 
> 	fs/btrfs/compression.c:1576 btrfs_compress_str2level()
> 	error: uninitialized symbol 'level'.
> 
> fs/btrfs/compression.c
>     1566 unsigned int btrfs_compress_str2level(unsigned int type, const char *str)
>     1567 {
>     1568 	unsigned int level;
>     1569 	int ret;
>     1570 
>     1571 	if (!type)
>     1572 		return 0;
>     1573 
>     1574 	if (str[0] == ':') {
>     1575 		ret = kstrtouint(str + 1, 10, &level);
> --> 1576 		if (ret)
>     1577 			level = 0;
> 
> I feel like if the user gives bad input then we should just return an
> error code instead of picking a level.

We've debated a bit and a warning with fallback to default is the
preferred option.
> 
>     1578 	}
> 
> level is not initialized if the first character is not ':'.

Right that's a bug, can be fixed by initializing level to 0, the
set_level() implementations will fall back to default then.

Thanks for the report.

> 
>     1579 
>     1580 	level = btrfs_compress_op[type]->set_level(level);
>     1581 
>     1582 	return level;
>     1583 }

  reply	other threads:[~2019-02-07 15:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-07 10:36 [bug report] btrfs: change set_level() to bound the level passed in Dan Carpenter
2019-02-07 15:40 ` David Sterba [this message]
2019-02-07 15:43   ` Dennis Zhou

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=20190207154045.GI2900@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=dan.carpenter@oracle.com \
    --cc=dennis@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox