public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: replace a wrong memset() with memzero_page()
@ 2022-03-25  9:37 Qu Wenruo
  2022-03-25 10:10 ` Johannes Thumshirn
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Qu Wenruo @ 2022-03-25  9:37 UTC (permalink / raw)
  To: linux-btrfs

The original code is not really setting the memory to 0x00 but 0x01.

To prevent such problem from happening, use memzero_page() instead.

Since we're here, also make @len const since it's just sectorsize.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/inode.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 78a5145353e1..179d479b72e9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3272,7 +3272,7 @@ static int check_data_csum(struct inode *inode, struct btrfs_bio *bbio,
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
 	char *kaddr;
-	u32 len = fs_info->sectorsize;
+	const u32 len = fs_info->sectorsize;
 	const u32 csum_size = fs_info->csum_size;
 	unsigned int offset_sectors;
 	u8 *csum_expected;
@@ -3287,11 +3287,11 @@ static int check_data_csum(struct inode *inode, struct btrfs_bio *bbio,
 	shash->tfm = fs_info->csum_shash;
 
 	crypto_shash_digest(shash, kaddr + pgoff, len, csum);
+	kunmap_atomic(kaddr);
 
 	if (memcmp(csum, csum_expected, csum_size))
 		goto zeroit;
 
-	kunmap_atomic(kaddr);
 	return 0;
 zeroit:
 	btrfs_print_data_csum_error(BTRFS_I(inode), start, csum, csum_expected,
@@ -3299,9 +3299,8 @@ static int check_data_csum(struct inode *inode, struct btrfs_bio *bbio,
 	if (bbio->device)
 		btrfs_dev_stat_inc_and_print(bbio->device,
 					     BTRFS_DEV_STAT_CORRUPTION_ERRS);
-	memset(kaddr + pgoff, 1, len);
+	memzero_page(page, pgoff, len);
 	flush_dcache_page(page);
-	kunmap_atomic(kaddr);
 	return -EIO;
 }
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2022-04-05 21:15 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-25  9:37 [PATCH] btrfs: replace a wrong memset() with memzero_page() Qu Wenruo
2022-03-25 10:10 ` Johannes Thumshirn
2022-03-25 10:49   ` Qu Wenruo
2022-03-25 10:58     ` Johannes Thumshirn
2022-03-25 16:38 ` Christoph Hellwig
2022-03-26  1:15   ` Qu Wenruo
2022-04-05  4:58   ` Christoph Hellwig
2022-04-05  5:08     ` Qu Wenruo
2022-04-05 14:04       ` David Sterba
2022-04-05 13:59     ` David Sterba
2022-03-28 18:51 ` David Sterba
2022-03-28 18:58   ` David Sterba
2022-03-29  9:57   ` Filipe Manana
2022-03-29 10:49     ` Qu Wenruo
2022-03-29 11:39       ` Filipe Manana
2022-03-29 23:52         ` Qu Wenruo
2022-03-30  9:27           ` Filipe Manana
2022-03-30 10:34             ` Filipe Manana
2022-03-30 10:42               ` Qu Wenruo
2022-03-30 11:02                 ` Filipe Manana
2022-03-30 11:03                 ` Graham Cobb
2022-03-30 21:34                   ` Filipe Manana
2022-03-30 22:29                     ` Graham Cobb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox