Skip to contentSkip to conversation

xfs: xfs_dabuf_map should return ENOMEM when map allocation fails

PATCH In review Darrick J. Wong 3 participants 3 messages Mar 15, 2020 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: xfs_dabuf_map should return ENOMEM when map allocation fails

From: Darrick J. Wong <[email protected]>

If the xfs_buf_map array allocation in xfs_dabuf_map fails for whatever reason, we bail out with error code zero. This will confuse callers, so make sure that we return ENOMEM. Allocation failure should never happen with the small size of the array, but code defensively anyway.

Fixes 45feef8f50b94d ("xfs: refactor xfs_dabuf_map")
---
 fs/xfs/libxfs/xfs_da_btree.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_da_btree.c +3 -1
index a7880c6285db..897749c41f36 100644
@@ -2521,8 +2521,10 @@ xfs_dabuf_map(
 	 */
 	if (nirecs > 1) {
 		map = kmem_zalloc(nirecs * sizeof(struct xfs_buf_map), KM_NOFS);
-		if (!map)
+		if (!map) {
+			error = -ENOMEM;
 			goto out_free_irecs;
+		}
 		*mapp = map;
 	}
 
Reviewed-by on v1 1/1
#1 lore raw

I've verified the commit "45feef8f50b94d56d6a433ad5baf5cdf58e3db98", which was adds goto statement and it make sense to set error to -ENOMEM when kmem_zalloc() fails.

Quoted 10 lines · Darrick J. Wong

From: Darrick J. Wong<[email protected]>

If the xfs_buf_map array allocation in xfs_dabuf_map fails for whatever reason, we bail out with error code zero. This will confuse callers, so make sure that we return ENOMEM. Allocation failure should never happen with the small size of the array, but code defensively anyway.

Fixes 45feef8f50b94d ("xfs: refactor xfs_dabuf_map")

---

Reviewed-by on v1 1/1
#2 lore raw
In reply to Darrick J. Wong
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

If the xfs_buf_map array allocation in xfs_dabuf_map fails for whatever reason, we bail out with error code zero. This will confuse callers, so make sure that we return ENOMEM. Allocation failure should never happen with the small size of the array, but code defensively anyway.

Fixes 45feef8f50b94d ("xfs: refactor xfs_dabuf_map")

Looks good,