diff mbox series

iomap: iomap_bmap should check iomap_apply return value

Message ID 20191107025927.GA6219@magnolia (mailing list archive)
State New, archived
Headers show
Series iomap: iomap_bmap should check iomap_apply return value | expand

Commit Message

Darrick J. Wong Nov. 7, 2019, 2:59 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Check the return value of iomap_apply and return 0 (i.e. error) if it
didn't succeed.

Coverity-id: 1437065
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/iomap/fiemap.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig Nov. 7, 2019, 8:30 a.m. UTC | #1
On Wed, Nov 06, 2019 at 06:59:27PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Check the return value of iomap_apply and return 0 (i.e. error) if it
> didn't succeed.

And how could we set the bno value if we didn't succeed?
Darrick J. Wong Nov. 7, 2019, 3:36 p.m. UTC | #2
On Thu, Nov 07, 2019 at 09:30:50AM +0100, Christoph Hellwig wrote:
> On Wed, Nov 06, 2019 at 06:59:27PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Check the return value of iomap_apply and return 0 (i.e. error) if it
> > didn't succeed.
> 
> And how could we set the bno value if we didn't succeed?

The iomap_bmap caller supplies an ->iomap_end that returns an error.

Granted there's only one caller and it doesn't, so we could dump this
patch and just tell Coverity to shut up, but it's odd that this is the
one place where we ignore the return value.

OTOH it's bmap which has been broken for ages; the more insane behavior
seen in the wild, the better to scare away users. :P

--D
Christoph Hellwig Nov. 8, 2019, 5:51 a.m. UTC | #3
On Thu, Nov 07, 2019 at 07:36:17AM -0800, Darrick J. Wong wrote:
> On Thu, Nov 07, 2019 at 09:30:50AM +0100, Christoph Hellwig wrote:
> > On Wed, Nov 06, 2019 at 06:59:27PM -0800, Darrick J. Wong wrote:
> > > From: Darrick J. Wong <darrick.wong@oracle.com>
> > > 
> > > Check the return value of iomap_apply and return 0 (i.e. error) if it
> > > didn't succeed.
> > 
> > And how could we set the bno value if we didn't succeed?
> 
> The iomap_bmap caller supplies an ->iomap_end that returns an error.
> 
> Granted there's only one caller and it doesn't, so we could dump this
> patch and just tell Coverity to shut up, but it's odd that this is the
> one place where we ignore the return value.
> 
> OTOH it's bmap which has been broken for ages; the more insane behavior
> seen in the wild, the better to scare away users. :P

Oh well.  I guess the patch is fine, it just isn't really needed as-is.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Darrick J. Wong Nov. 8, 2019, 4:11 p.m. UTC | #4
On Fri, Nov 08, 2019 at 06:51:51AM +0100, Christoph Hellwig wrote:
> On Thu, Nov 07, 2019 at 07:36:17AM -0800, Darrick J. Wong wrote:
> > On Thu, Nov 07, 2019 at 09:30:50AM +0100, Christoph Hellwig wrote:
> > > On Wed, Nov 06, 2019 at 06:59:27PM -0800, Darrick J. Wong wrote:
> > > > From: Darrick J. Wong <darrick.wong@oracle.com>
> > > > 
> > > > Check the return value of iomap_apply and return 0 (i.e. error) if it
> > > > didn't succeed.
> > > 
> > > And how could we set the bno value if we didn't succeed?
> > 
> > The iomap_bmap caller supplies an ->iomap_end that returns an error.
> > 
> > Granted there's only one caller and it doesn't, so we could dump this
> > patch and just tell Coverity to shut up, but it's odd that this is the
> > one place where we ignore the return value.
> > 
> > OTOH it's bmap which has been broken for ages; the more insane behavior
> > seen in the wild, the better to scare away users. :P
> 
> Oh well.  I guess the patch is fine, it just isn't really needed as-is.

Thanks for the review. :)

--D

> Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/fs/iomap/fiemap.c b/fs/iomap/fiemap.c
index 690ef2d7c6c8..bccf305ea9ce 100644
--- a/fs/iomap/fiemap.c
+++ b/fs/iomap/fiemap.c
@@ -133,12 +133,16 @@  iomap_bmap(struct address_space *mapping, sector_t bno,
 	struct inode *inode = mapping->host;
 	loff_t pos = bno << inode->i_blkbits;
 	unsigned blocksize = i_blocksize(inode);
+	int ret;
 
 	if (filemap_write_and_wait(mapping))
 		return 0;
 
 	bno = 0;
-	iomap_apply(inode, pos, blocksize, 0, ops, &bno, iomap_bmap_actor);
+	ret = iomap_apply(inode, pos, blocksize, 0, ops, &bno,
+			  iomap_bmap_actor);
+	if (ret)
+		return 0;
 	return bno;
 }
 EXPORT_SYMBOL_GPL(iomap_bmap);