All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] xfs: initialize error in xfs_defer_finish_one
@ 2022-08-01 19:03 Sherry Yang
  2022-08-01 20:49 ` Dave Chinner
  0 siblings, 1 reply; 5+ messages in thread
From: Sherry Yang @ 2022-08-01 19:03 UTC (permalink / raw)
  To: djwong, dchinner, allison.henderson, chandanrlinux, bfoster
  Cc: linux-xfs, linux-kernel, sherry.yang

Path through non-void function 'xfs_defer_finish_one' may return error
uninitialized if no iteration of 'list_for_each_safe' occurs. Fix this
by initializing error.

Fixes: bb47d79750f1 ("xfs: refactor xfs_defer_finish_noroll")
Cc: stable@vger.kernel.org
Signed-off-by: Sherry Yang <sherry.yang@oracle.com>
---
 fs/xfs/libxfs/xfs_defer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xfs/libxfs/xfs_defer.c b/fs/xfs/libxfs/xfs_defer.c
index 5a321b783398..3188712ff34e 100644
--- a/fs/xfs/libxfs/xfs_defer.c
+++ b/fs/xfs/libxfs/xfs_defer.c
@@ -468,7 +468,7 @@ xfs_defer_finish_one(
 	const struct xfs_defer_op_type	*ops = defer_op_types[dfp->dfp_type];
 	struct xfs_btree_cur		*state = NULL;
 	struct list_head		*li, *n;
-	int				error;
+	int				error = 0;
 
 	trace_xfs_defer_pending_finish(tp->t_mountp, dfp);
 
-- 
2.31.1


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

* Re: [PATCH v1] xfs: initialize error in xfs_defer_finish_one
  2022-08-01 19:03 [PATCH v1] xfs: initialize error in xfs_defer_finish_one Sherry Yang
@ 2022-08-01 20:49 ` Dave Chinner
  2022-08-03  4:31   ` Darrick J. Wong
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Chinner @ 2022-08-01 20:49 UTC (permalink / raw)
  To: Sherry Yang
  Cc: djwong, dchinner, allison.henderson, chandanrlinux, bfoster,
	linux-xfs, linux-kernel

On Mon, Aug 01, 2022 at 12:03:11PM -0700, Sherry Yang wrote:
> Path through non-void function 'xfs_defer_finish_one' may return error
> uninitialized if no iteration of 'list_for_each_safe' occurs. Fix this
> by initializing error.

I didn't think this situation was possible - how do we get deferred
work queued with no work items on it?

If we can return an uninitialised error from xfs_defer_finish_one()
because of an empty queued work, then something else has gone wrong
earlier in the work deferral process. If this can actually happen,
then we need to fix whatever is creating the empty work rather than
paper over it by initialising the error being returned for empty
works...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH v1] xfs: initialize error in xfs_defer_finish_one
  2022-08-01 20:49 ` Dave Chinner
@ 2022-08-03  4:31   ` Darrick J. Wong
  2022-08-03 23:42     ` Sherry Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2022-08-03  4:31 UTC (permalink / raw)
  To: Dave Chinner
  Cc: Sherry Yang, dchinner, allison.henderson, chandanrlinux, bfoster,
	linux-xfs, linux-kernel

On Tue, Aug 02, 2022 at 06:49:02AM +1000, Dave Chinner wrote:
> On Mon, Aug 01, 2022 at 12:03:11PM -0700, Sherry Yang wrote:
> > Path through non-void function 'xfs_defer_finish_one' may return error
> > uninitialized if no iteration of 'list_for_each_safe' occurs. Fix this
> > by initializing error.
> 
> I didn't think this situation was possible - how do we get deferred
> work queued with no work items on it?
> 
> If we can return an uninitialised error from xfs_defer_finish_one()
> because of an empty queued work, then something else has gone wrong
> earlier in the work deferral process. If this can actually happen,
> then we need to fix whatever is creating the empty work rather than
> paper over it by initialising the error being returned for empty
> works...

/me bets this is a response to a static checker that doesn't know that
list_empty(&dfp->dfp_work) == false in all circumstances.  It's not
possible for tp->t_dfops to contain an xfs_defer_pending with no work
items.

--D

> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com

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

* Re: [PATCH v1] xfs: initialize error in xfs_defer_finish_one
  2022-08-03  4:31   ` Darrick J. Wong
@ 2022-08-03 23:42     ` Sherry Yang
  2022-08-04  5:07       ` Darrick J. Wong
  0 siblings, 1 reply; 5+ messages in thread
From: Sherry Yang @ 2022-08-03 23:42 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Dave Chinner, dchinner, Allison Henderson, chandanrlinux,
	bfoster, linux-xfs, linux-kernel


> On Aug 2, 2022, at 9:31 PM, Darrick J. Wong <djwong@kernel.org> wrote:
> 
> On Tue, Aug 02, 2022 at 06:49:02AM +1000, Dave Chinner wrote:
>> On Mon, Aug 01, 2022 at 12:03:11PM -0700, Sherry Yang wrote:
>>> Path through non-void function 'xfs_defer_finish_one' may return error
>>> uninitialized if no iteration of 'list_for_each_safe' occurs. Fix this
>>> by initializing error.
>> 
>> I didn't think this situation was possible - how do we get deferred
>> work queued with no work items on it?
>> 
>> If we can return an uninitialised error from xfs_defer_finish_one()
>> because of an empty queued work, then something else has gone wrong
>> earlier in the work deferral process. If this can actually happen,
>> then we need to fix whatever is creating the empty work rather than
>> paper over it by initialising the error being returned for empty
>> works...
> 
> /me bets this is a response to a static checker that doesn't know that
> list_empty(&dfp->dfp_work) == false in all circumstances.  It's not
> possible for tp->t_dfops to contain an xfs_defer_pending with no work
> items.

Hi Darrick, 

You’re correct. This is a false positive bug detected by our static code 
analysis tool. Sorry for the noise.

Sherry
> 
> --D
> 
>> Cheers,
>> 
>> Dave.
>> -- 
>> Dave Chinner
>> david@fromorbit.com


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

* Re: [PATCH v1] xfs: initialize error in xfs_defer_finish_one
  2022-08-03 23:42     ` Sherry Yang
@ 2022-08-04  5:07       ` Darrick J. Wong
  0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2022-08-04  5:07 UTC (permalink / raw)
  To: Sherry Yang
  Cc: Dave Chinner, dchinner, Allison Henderson, chandanrlinux,
	bfoster, linux-xfs, linux-kernel

On Wed, Aug 03, 2022 at 11:42:21PM +0000, Sherry Yang wrote:
> 
> > On Aug 2, 2022, at 9:31 PM, Darrick J. Wong <djwong@kernel.org> wrote:
> > 
> > On Tue, Aug 02, 2022 at 06:49:02AM +1000, Dave Chinner wrote:
> >> On Mon, Aug 01, 2022 at 12:03:11PM -0700, Sherry Yang wrote:
> >>> Path through non-void function 'xfs_defer_finish_one' may return error
> >>> uninitialized if no iteration of 'list_for_each_safe' occurs. Fix this
> >>> by initializing error.
> >> 
> >> I didn't think this situation was possible - how do we get deferred
> >> work queued with no work items on it?
> >> 
> >> If we can return an uninitialised error from xfs_defer_finish_one()
> >> because of an empty queued work, then something else has gone wrong
> >> earlier in the work deferral process. If this can actually happen,
> >> then we need to fix whatever is creating the empty work rather than
> >> paper over it by initialising the error being returned for empty
> >> works...
> > 
> > /me bets this is a response to a static checker that doesn't know that
> > list_empty(&dfp->dfp_work) == false in all circumstances.  It's not
> > possible for tp->t_dfops to contain an xfs_defer_pending with no work
> > items.
> 
> Hi Darrick, 
> 
> You’re correct. This is a false positive bug detected by our static code 
> analysis tool. Sorry for the noise.

Well, thank /you/ for running smatch/sparse/whatever on the XFS code
base.  Let us know if you find any other oddities, since it does tend to
find things every now and then. :)

--D

> Sherry
> > 
> > --D
> > 
> >> Cheers,
> >> 
> >> Dave.
> >> -- 
> >> Dave Chinner
> >> david@fromorbit.com
> 

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

end of thread, other threads:[~2022-08-04  5:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01 19:03 [PATCH v1] xfs: initialize error in xfs_defer_finish_one Sherry Yang
2022-08-01 20:49 ` Dave Chinner
2022-08-03  4:31   ` Darrick J. Wong
2022-08-03 23:42     ` Sherry Yang
2022-08-04  5:07       ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.