Skip to content

Commit 8e6cf5f

Browse files
zhangyi089tytso
authored andcommitted
jbd2: jbd2_journal_init_{dev,inode} return proper error return value
Current jbd2_journal_init_{dev,inode} return NULL if some error happens, make them to pass out proper error return value. [ Fix from Yang Yingliang folded in. ] Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent d9a4549 commit 8e6cf5f

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

fs/ext4/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5815,7 +5815,7 @@ static journal_t *ext4_get_journal(struct super_block *sb,
58155815
return NULL;
58165816

58175817
journal = jbd2_journal_init_inode(journal_inode);
5818-
if (!journal) {
5818+
if (IS_ERR(journal)) {
58195819
ext4_msg(sb, KERN_ERR, "Could not load journal inode");
58205820
iput(journal_inode);
58215821
return NULL;
@@ -5894,7 +5894,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
58945894

58955895
journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
58965896
start, len, blocksize);
5897-
if (!journal) {
5897+
if (IS_ERR(journal)) {
58985898
ext4_msg(sb, KERN_ERR, "failed to create device journal");
58995899
goto out_bdev;
59005900
}

fs/jbd2/journal.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
15311531

15321532
journal = kzalloc(sizeof(*journal), GFP_KERNEL);
15331533
if (!journal)
1534-
return NULL;
1534+
return ERR_PTR(-ENOMEM);
15351535

15361536
journal->j_blocksize = blocksize;
15371537
journal->j_dev = bdev;
@@ -1576,6 +1576,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
15761576
* journal descriptor can store up to n blocks, we need enough
15771577
* buffers to write out full descriptor block.
15781578
*/
1579+
err = -ENOMEM;
15791580
n = journal->j_blocksize / jbd2_min_tag_size();
15801581
journal->j_wbufsize = n;
15811582
journal->j_fc_wbuf = NULL;
@@ -1607,7 +1608,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
16071608
jbd2_journal_destroy_revoke(journal);
16081609
journal_fail_superblock(journal);
16091610
kfree(journal);
1610-
return NULL;
1611+
return ERR_PTR(err);
16111612
}
16121613

16131614
/* jbd2_journal_init_dev and jbd2_journal_init_inode:
@@ -1640,8 +1641,8 @@ journal_t *jbd2_journal_init_dev(struct block_device *bdev,
16401641
journal_t *journal;
16411642

16421643
journal = journal_init_common(bdev, fs_dev, start, len, blocksize);
1643-
if (!journal)
1644-
return NULL;
1644+
if (IS_ERR(journal))
1645+
return ERR_CAST(journal);
16451646

16461647
snprintf(journal->j_devname, sizeof(journal->j_devname),
16471648
"%pg", journal->j_dev);
@@ -1667,11 +1668,9 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
16671668

16681669
blocknr = 0;
16691670
err = bmap(inode, &blocknr);
1670-
16711671
if (err || !blocknr) {
1672-
pr_err("%s: Cannot locate journal superblock\n",
1673-
__func__);
1674-
return NULL;
1672+
pr_err("%s: Cannot locate journal superblock\n", __func__);
1673+
return err ? ERR_PTR(err) : ERR_PTR(-EINVAL);
16751674
}
16761675

16771676
jbd2_debug(1, "JBD2: inode %s/%ld, size %lld, bits %d, blksize %ld\n",
@@ -1681,8 +1680,8 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
16811680
journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev,
16821681
blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
16831682
inode->i_sb->s_blocksize);
1684-
if (!journal)
1685-
return NULL;
1683+
if (IS_ERR(journal))
1684+
return ERR_CAST(journal);
16861685

16871686
journal->j_inode = inode;
16881687
snprintf(journal->j_devname, sizeof(journal->j_devname),

fs/ocfs2/journal.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,9 +911,9 @@ int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty)
911911

912912
/* call the kernels journal init function now */
913913
j_journal = jbd2_journal_init_inode(inode);
914-
if (j_journal == NULL) {
914+
if (IS_ERR(j_journal)) {
915915
mlog(ML_ERROR, "Linux journal layer error\n");
916-
status = -EINVAL;
916+
status = PTR_ERR(j_journal);
917917
goto done;
918918
}
919919

@@ -1687,9 +1687,9 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
16871687
}
16881688

16891689
journal = jbd2_journal_init_inode(inode);
1690-
if (journal == NULL) {
1690+
if (IS_ERR(journal)) {
16911691
mlog(ML_ERROR, "Linux journal layer error\n");
1692-
status = -EIO;
1692+
status = PTR_ERR(journal);
16931693
goto done;
16941694
}
16951695

0 commit comments

Comments
 (0)