public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: always init bma in xfs_bmapi_write
@ 2019-03-18 16:44 Darrick J. Wong
  2019-03-19 13:01 ` Brian Foster
  0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2019-03-18 16:44 UTC (permalink / raw)
  To: xfs; +Cc: Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Always init the tp/ip fields of bma in xfs_bmapi_write so that the
bmapi_finish at the bottom never trips over null transaction or inode
pointers.

Coverity-id: 1443964
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_bmap.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 625ddfb9653e..17c7168966c6 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4254,9 +4254,13 @@ xfs_bmapi_write(
 	struct xfs_bmbt_irec	*mval,		/* output: map values */
 	int			*nmap)		/* i/o: mval size/count */
 {
+	struct xfs_bmalloca	bma = {
+		.tp		= tp,
+		.ip		= ip,
+		.total		= total,
+	};
 	struct xfs_mount	*mp = ip->i_mount;
 	struct xfs_ifork	*ifp;
-	struct xfs_bmalloca	bma = { NULL };	/* args for xfs_bmap_alloc */
 	xfs_fileoff_t		end;		/* end of mapped file region */
 	bool			eof = false;	/* after the end of extents */
 	int			error;		/* error return */
@@ -4324,10 +4328,6 @@ xfs_bmapi_write(
 		eof = true;
 	if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
 		bma.prev.br_startoff = NULLFILEOFF;
-	bma.tp = tp;
-	bma.ip = ip;
-	bma.total = total;
-	bma.datatype = 0;
 	bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
 
 	n = 0;

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

* Re: [PATCH] xfs: always init bma in xfs_bmapi_write
  2019-03-18 16:44 [PATCH] xfs: always init bma in xfs_bmapi_write Darrick J. Wong
@ 2019-03-19 13:01 ` Brian Foster
  2019-03-19 15:15   ` Darrick J. Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Foster @ 2019-03-19 13:01 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: xfs, Christoph Hellwig

On Mon, Mar 18, 2019 at 09:44:01AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Always init the tp/ip fields of bma in xfs_bmapi_write so that the
> bmapi_finish at the bottom never trips over null transaction or inode
> pointers.
> 
> Coverity-id: 1443964
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/libxfs/xfs_bmap.c |   10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index 625ddfb9653e..17c7168966c6 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -4254,9 +4254,13 @@ xfs_bmapi_write(
>  	struct xfs_bmbt_irec	*mval,		/* output: map values */
>  	int			*nmap)		/* i/o: mval size/count */
>  {
> +	struct xfs_bmalloca	bma = {
> +		.tp		= tp,
> +		.ip		= ip,
> +		.total		= total,
> +	};

This should continue to zero-init the rest of the structure, right? If
so, looks fine:

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  	struct xfs_mount	*mp = ip->i_mount;
>  	struct xfs_ifork	*ifp;
> -	struct xfs_bmalloca	bma = { NULL };	/* args for xfs_bmap_alloc */
>  	xfs_fileoff_t		end;		/* end of mapped file region */
>  	bool			eof = false;	/* after the end of extents */
>  	int			error;		/* error return */
> @@ -4324,10 +4328,6 @@ xfs_bmapi_write(
>  		eof = true;
>  	if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
>  		bma.prev.br_startoff = NULLFILEOFF;
> -	bma.tp = tp;
> -	bma.ip = ip;
> -	bma.total = total;
> -	bma.datatype = 0;
>  	bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
>  
>  	n = 0;

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

* Re: [PATCH] xfs: always init bma in xfs_bmapi_write
  2019-03-19 13:01 ` Brian Foster
@ 2019-03-19 15:15   ` Darrick J. Wong
  0 siblings, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2019-03-19 15:15 UTC (permalink / raw)
  To: Brian Foster; +Cc: xfs, Christoph Hellwig

On Tue, Mar 19, 2019 at 09:01:13AM -0400, Brian Foster wrote:
> On Mon, Mar 18, 2019 at 09:44:01AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Always init the tp/ip fields of bma in xfs_bmapi_write so that the
> > bmapi_finish at the bottom never trips over null transaction or inode
> > pointers.
> > 
> > Coverity-id: 1443964
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  fs/xfs/libxfs/xfs_bmap.c |   10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> > index 625ddfb9653e..17c7168966c6 100644
> > --- a/fs/xfs/libxfs/xfs_bmap.c
> > +++ b/fs/xfs/libxfs/xfs_bmap.c
> > @@ -4254,9 +4254,13 @@ xfs_bmapi_write(
> >  	struct xfs_bmbt_irec	*mval,		/* output: map values */
> >  	int			*nmap)		/* i/o: mval size/count */
> >  {
> > +	struct xfs_bmalloca	bma = {
> > +		.tp		= tp,
> > +		.ip		= ip,
> > +		.total		= total,
> > +	};
> 
> This should continue to zero-init the rest of the structure, right?

I hope so.  If not, there's going to be a lot of corrupt in-core structs
in the kernel... :)

Thanks for the review, btw.

--D

> If so, looks fine:
> 
> Reviewed-by: Brian Foster <bfoster@redhat.com>
> 
> >  	struct xfs_mount	*mp = ip->i_mount;
> >  	struct xfs_ifork	*ifp;
> > -	struct xfs_bmalloca	bma = { NULL };	/* args for xfs_bmap_alloc */
> >  	xfs_fileoff_t		end;		/* end of mapped file region */
> >  	bool			eof = false;	/* after the end of extents */
> >  	int			error;		/* error return */
> > @@ -4324,10 +4328,6 @@ xfs_bmapi_write(
> >  		eof = true;
> >  	if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
> >  		bma.prev.br_startoff = NULLFILEOFF;
> > -	bma.tp = tp;
> > -	bma.ip = ip;
> > -	bma.total = total;
> > -	bma.datatype = 0;
> >  	bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
> >  
> >  	n = 0;

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

end of thread, other threads:[~2019-03-19 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-18 16:44 [PATCH] xfs: always init bma in xfs_bmapi_write Darrick J. Wong
2019-03-19 13:01 ` Brian Foster
2019-03-19 15:15   ` Darrick J. Wong

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