All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v3] f2fs: compress: support chksum
Date: Mon, 7 Dec 2020 12:37:03 -0800	[thread overview]
Message-ID: <X86Sb2pvD53MzO5+@gmail.com> (raw)
In-Reply-To: <20201126103209.67985-1-yuchao0@huawei.com>

On Thu, Nov 26, 2020 at 06:32:09PM +0800, Chao Yu wrote:
> +	if (!ret && fi->i_compress_flag & 1 << COMPRESS_CHKSUM) {

This really could use some parentheses.  People shouldn't have to look up a
C operator precedence table to understand the code.

> +		u32 provided = le32_to_cpu(dic->cbuf->chksum);
> +		u32 calculated = f2fs_crc32(sbi, dic->cbuf->cdata, dic->clen);
> +
> +		if (provided != calculated) {
> +			if (!is_inode_flag_set(dic->inode, FI_COMPRESS_CORRUPT)) {
> +				set_inode_flag(dic->inode, FI_COMPRESS_CORRUPT);
> +				printk_ratelimited(
> +					"%sF2FS-fs (%s): checksum invalid, nid = %lu, %x vs %x",
> +					KERN_INFO, sbi->sb->s_id, dic->inode->i_ino,
> +					provided, calculated);
> +			}
> +			set_sbi_flag(sbi, SBI_NEED_FSCK);
> +			WARN_ON_ONCE(1);

WARN, WARN_ON_ONCE, BUG, BUG_ON, etc. are only for kernel bugs, not for invalid
inputs from disk or userspace.

There is already a log message printed just above, so it seems this WARN_ON_ONCE
should just be removed.

- Eric


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v3] f2fs: compress: support chksum
Date: Mon, 7 Dec 2020 12:37:03 -0800	[thread overview]
Message-ID: <X86Sb2pvD53MzO5+@gmail.com> (raw)
In-Reply-To: <20201126103209.67985-1-yuchao0@huawei.com>

On Thu, Nov 26, 2020 at 06:32:09PM +0800, Chao Yu wrote:
> +	if (!ret && fi->i_compress_flag & 1 << COMPRESS_CHKSUM) {

This really could use some parentheses.  People shouldn't have to look up a
C operator precedence table to understand the code.

> +		u32 provided = le32_to_cpu(dic->cbuf->chksum);
> +		u32 calculated = f2fs_crc32(sbi, dic->cbuf->cdata, dic->clen);
> +
> +		if (provided != calculated) {
> +			if (!is_inode_flag_set(dic->inode, FI_COMPRESS_CORRUPT)) {
> +				set_inode_flag(dic->inode, FI_COMPRESS_CORRUPT);
> +				printk_ratelimited(
> +					"%sF2FS-fs (%s): checksum invalid, nid = %lu, %x vs %x",
> +					KERN_INFO, sbi->sb->s_id, dic->inode->i_ino,
> +					provided, calculated);
> +			}
> +			set_sbi_flag(sbi, SBI_NEED_FSCK);
> +			WARN_ON_ONCE(1);

WARN, WARN_ON_ONCE, BUG, BUG_ON, etc. are only for kernel bugs, not for invalid
inputs from disk or userspace.

There is already a log message printed just above, so it seems this WARN_ON_ONCE
should just be removed.

- Eric

  reply	other threads:[~2020-12-07 20:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 10:32 [f2fs-dev] [PATCH v3] f2fs: compress: support chksum Chao Yu
2020-11-26 10:32 ` Chao Yu
2020-12-07 20:37 ` Eric Biggers [this message]
2020-12-07 20:37   ` [f2fs-dev] " Eric Biggers
2020-12-07 21:53   ` Joe Perches
2020-12-07 21:53     ` Joe Perches
2020-12-08  1:18   ` Chao Yu
2020-12-08  1:18     ` Chao Yu
2020-12-08  1:26     ` Jaegeuk Kim
2020-12-08  1:26       ` Jaegeuk Kim
2020-12-08  1:31       ` Chao Yu
2020-12-08  1:31         ` Chao Yu

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=X86Sb2pvD53MzO5+@gmail.com \
    --to=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.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.