Linux NILFS development
 help / color / mirror / Atom feed
* [PATCH] nilfs2: fix dereferencing freed memory
@ 2023-08-18  9:20 Ferry Meng
  2023-08-18 15:45 ` Ryusuke Konishi
  0 siblings, 1 reply; 2+ messages in thread
From: Ferry Meng @ 2023-08-18  9:20 UTC (permalink / raw)
  To: Ryusuke Konishi, linux-nilfs-u79uwXL29TY76Z2rM5mHXA; +Cc: LKML, Ferry Meng

Fix smatch warning:

fs/nilfs2/gcinode.c:103 nilfs_gccache_submit_read_data() error:
dereferencing freed memory 'bh'

Signed-off-by: Ferry Meng <mengferry-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>

diff --git a/fs/nilfs2/gcinode.c b/fs/nilfs2/gcinode.c
index 48fe71d309cb..6319e825f317 100644
--- a/fs/nilfs2/gcinode.c
+++ b/fs/nilfs2/gcinode.c
@@ -73,10 +73,8 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
 		struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
 
 		err = nilfs_dat_translate(nilfs->ns_dat, vbn, &pbn);
-		if (unlikely(err)) { /* -EIO, -ENOMEM, -ENOENT */
-			brelse(bh);
+		if (unlikely(err)) /* -EIO, -ENOMEM, -ENOENT */
 			goto failed;
-		}
 	}
 
 	lock_buffer(bh);
@@ -102,6 +100,8 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
  failed:
 	unlock_page(bh->b_page);
 	put_page(bh->b_page);
+	if (err)
+		brelse(bh);
 	return err;
 }
 
-- 
2.19.1.6.gb485710b


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

end of thread, other threads:[~2023-08-18 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-18  9:20 [PATCH] nilfs2: fix dereferencing freed memory Ferry Meng
2023-08-18 15:45 ` Ryusuke Konishi

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