[PATCH v1 2/3] affs: check sb_getblk failure in getzeroblk/getemptyblk

From: Xixin Liu

Date: Tue Jul 14 2026 - 05:39:06 EST


affs_getzeroblk() and affs_getemptyblk() pass sb_getblk() to
lock_buffer()/wait_on_buffer() without a NULL check, so allocation
failure crashes in the helpers before callers can handle it.

Return NULL when sb_getblk() fails.

Signed-off-by: Xixin Liu <liuxixin@xxxxxxxxxx>
---
fs/affs/affs.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/affs/affs.h b/fs/affs/affs.h
index 44a3f69d275f..651d61b3213a 100644
--- a/fs/affs/affs.h
+++ b/fs/affs/affs.h
@@ -250,6 +250,8 @@ affs_getzeroblk(struct super_block *sb, int block)
pr_debug("%s: %d\n", __func__, block);
if (affs_validblock(sb, block)) {
bh = sb_getblk(sb, block);
+ if (!bh)
+ return NULL;
lock_buffer(bh);
memset(bh->b_data, 0 , sb->s_blocksize);
set_buffer_uptodate(bh);
@@ -265,6 +267,8 @@ affs_getemptyblk(struct super_block *sb, int block)
pr_debug("%s: %d\n", __func__, block);
if (affs_validblock(sb, block)) {
bh = sb_getblk(sb, block);
+ if (!bh)
+ return NULL;
wait_on_buffer(bh);
set_buffer_uptodate(bh);
return bh;
--
2.43.0