ext4: simplify some code in read_mmp_block()

My static check complains because we have:

	if (!*bh)
		return -ENOMEM;
	if (*bh) {

The second check is unnecessary.

I've simplified this code by moving the "if (!*bh)" checks around.  Also
Andreas Dilger says we should probably print a warning if sb_getblk()
fails.

[ Restructured the code so that we print a warning message as well if
  the mmp block doesn't check out, and to print the error code to
  disambiguate between the error cases.  - TYT ]

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
Dan Carpenter 2015-08-15 11:30:31 -04:00 committed by Theodore Ts'o
parent c642dc9e1a
commit 9810446836

View file

@ -69,6 +69,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
ext4_fsblk_t mmp_block) ext4_fsblk_t mmp_block)
{ {
struct mmp_struct *mmp; struct mmp_struct *mmp;
int ret;
if (*bh) if (*bh)
clear_buffer_uptodate(*bh); clear_buffer_uptodate(*bh);
@ -76,33 +77,36 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
/* This would be sb_bread(sb, mmp_block), except we need to be sure /* This would be sb_bread(sb, mmp_block), except we need to be sure
* that the MD RAID device cache has been bypassed, and that the read * that the MD RAID device cache has been bypassed, and that the read
* is not blocked in the elevator. */ * is not blocked in the elevator. */
if (!*bh) if (!*bh) {
*bh = sb_getblk(sb, mmp_block); *bh = sb_getblk(sb, mmp_block);
if (!*bh) if (!*bh) {
return -ENOMEM; ret = -ENOMEM;
if (*bh) { goto warn_exit;
get_bh(*bh);
lock_buffer(*bh);
(*bh)->b_end_io = end_buffer_read_sync;
submit_bh(READ_SYNC | REQ_META | REQ_PRIO, *bh);
wait_on_buffer(*bh);
if (!buffer_uptodate(*bh)) {
brelse(*bh);
*bh = NULL;
} }
} }
if (unlikely(!*bh)) {
ext4_warning(sb, "Error while reading MMP block %llu", get_bh(*bh);
mmp_block); lock_buffer(*bh);
return -EIO; (*bh)->b_end_io = end_buffer_read_sync;
submit_bh(READ_SYNC | REQ_META | REQ_PRIO, *bh);
wait_on_buffer(*bh);
if (!buffer_uptodate(*bh)) {
brelse(*bh);
*bh = NULL;
ret = -EIO;
goto warn_exit;
} }
mmp = (struct mmp_struct *)((*bh)->b_data); mmp = (struct mmp_struct *)((*bh)->b_data);
if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC || if (le32_to_cpu(mmp->mmp_magic) == EXT4_MMP_MAGIC &&
!ext4_mmp_csum_verify(sb, mmp)) ext4_mmp_csum_verify(sb, mmp))
return -EINVAL; return 0;
ret = -EINVAL;
return 0; warn_exit:
ext4_warning(sb, "Error %d while reading MMP block %llu",
ret, mmp_block);
return ret;
} }
/* /*