Commit 7401aafd5019d32a888e5f27332cf580945574bf

Authored by Dave Chinner
Committed by Dave Chinner
1 parent 1bfd8d0419

xfs: xfs_trans_read_buf() should return an error on failure

When inside a transaction and we fail to read a buffer,
xfs_trans_read_buf returns a null buffer pointer and no error.
xfs_do_da_buf() checks the error return, but not the buffer, and as
a result this read failure condition causes a panic when it attempts
to dereference the non-existant buffer.

Make xfs_trans_read_buf() return the same error for this situation
regardless of whether it is in a transaction or not. This means
every caller does not need to check both the error return and the
buffer before proceeding to use the buffer.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Alex Elder <aelder@sgi.com>

Showing 1 changed file with 2 additions and 1 deletions Side-by-side Diff

fs/xfs/xfs_trans_buf.c
... ... @@ -383,7 +383,8 @@
383 383 bp = xfs_buf_read(target, blkno, len, flags | XBF_DONT_BLOCK);
384 384 if (bp == NULL) {
385 385 *bpp = NULL;
386   - return 0;
  386 + return (flags & XBF_TRYLOCK) ?
  387 + 0 : XFS_ERROR(ENOMEM);
387 388 }
388 389 if (XFS_BUF_GETERROR(bp) != 0) {
389 390 XFS_BUF_SUPER_STALE(bp);