drop ensure-entering-into-panic-after-recording-an-error-in-superblock
[ext4-patch-queue.git] / simplify-some-code-in-read-mmp_block
blobe510e891640ec3cfdcb7deae63cc329e01cb2611
1 ext4: simplify some code in read_mmp_block()
3 From: Dan Carpenter <dan.carpenter@oracle.com>
5 My static check complains because we have:
7         if (!*bh)
8                 return -ENOMEM;
9         if (*bh) {
11 The second check is unnecessary.
13 I've simplified this code by moving the "if (!*bh)" checks around.  Also
14 Andreas Dilger says we should probably print a warning if sb_getblk()
15 fails.
17 [ Restructured the code so that we print a warning message as well if
18   the mmp block doesn't check out, and to print the error code to
19   disambiguate between the error cases.  - TYT ]
21 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
22 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
23 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
24 ---
25  fs/ext4/mmp.c | 46 +++++++++++++++++++++++++---------------------
26  1 file changed, 25 insertions(+), 21 deletions(-)
28 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
29 index 8313ca3..048c52a 100644
30 --- a/fs/ext4/mmp.c
31 +++ b/fs/ext4/mmp.c
32 @@ -69,6 +69,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
33                           ext4_fsblk_t mmp_block)
34  {
35         struct mmp_struct *mmp;
36 +       int ret;
38         if (*bh)
39                 clear_buffer_uptodate(*bh);
40 @@ -76,33 +77,36 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
41         /* This would be sb_bread(sb, mmp_block), except we need to be sure
42          * that the MD RAID device cache has been bypassed, and that the read
43          * is not blocked in the elevator. */
44 -       if (!*bh)
45 +       if (!*bh) {
46                 *bh = sb_getblk(sb, mmp_block);
47 -       if (!*bh)
48 -               return -ENOMEM;
49 -       if (*bh) {
50 -               get_bh(*bh);
51 -               lock_buffer(*bh);
52 -               (*bh)->b_end_io = end_buffer_read_sync;
53 -               submit_bh(READ_SYNC | REQ_META | REQ_PRIO, *bh);
54 -               wait_on_buffer(*bh);
55 -               if (!buffer_uptodate(*bh)) {
56 -                       brelse(*bh);
57 -                       *bh = NULL;
58 +               if (!*bh) {
59 +                       ret = -ENOMEM;
60 +                       goto warn_exit;
61                 }
62         }
63 -       if (unlikely(!*bh)) {
64 -               ext4_warning(sb, "Error while reading MMP block %llu",
65 -                            mmp_block);
66 -               return -EIO;
68 +       get_bh(*bh);
69 +       lock_buffer(*bh);
70 +       (*bh)->b_end_io = end_buffer_read_sync;
71 +       submit_bh(READ_SYNC | REQ_META | REQ_PRIO, *bh);
72 +       wait_on_buffer(*bh);
73 +       if (!buffer_uptodate(*bh)) {
74 +               brelse(*bh);
75 +               *bh = NULL;
76 +               ret = -EIO;
77 +               goto warn_exit;
78         }
80         mmp = (struct mmp_struct *)((*bh)->b_data);
81 -       if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC ||
82 -           !ext4_mmp_csum_verify(sb, mmp))
83 -               return -EINVAL;
85 -       return 0;
86 +       if (le32_to_cpu(mmp->mmp_magic) == EXT4_MMP_MAGIC &&
87 +           ext4_mmp_csum_verify(sb, mmp))
88 +               return 0;
89 +       ret = -EINVAL;
91 +warn_exit:
92 +       ext4_warning(sb, "Error %d while reading MMP block %llu",
93 +                    ret, mmp_block);
94 +       return ret;
95  }
97  /*