diff mbox series

[v2,1/1] xfs: Fix Smatch warning in xfs_attr_node_get

Message ID 20200729043747.11164-1-allison.henderson@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/1] xfs: Fix Smatch warning in xfs_attr_node_get | expand

Commit Message

Allison Henderson July 29, 2020, 4:37 a.m. UTC
Fix warning: variable dereferenced before check 'state' in
xfs_attr_node_get.  If xfs_attr_node_hasname fails, it may return a null
state.  If state is null, do not release paths or derefrence state

Signed-off-by: Allison Collins <allison.henderson@oracle.com>
---
 fs/xfs/libxfs/xfs_attr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Darrick J. Wong July 29, 2020, 7:59 p.m. UTC | #1
On Tue, Jul 28, 2020 at 09:37:47PM -0700, Allison Collins wrote:
> Fix warning: variable dereferenced before check 'state' in
> xfs_attr_node_get.  If xfs_attr_node_hasname fails, it may return a null
> state.  If state is null, do not release paths or derefrence state
> 
> Signed-off-by: Allison Collins <allison.henderson@oracle.com>

Looks ok, though I folded all these into the for-next rebase (and then
forgot to push send on this...)

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/xfs/libxfs/xfs_attr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
> index e5ec9ed..38fe0d3 100644
> --- a/fs/xfs/libxfs/xfs_attr.c
> +++ b/fs/xfs/libxfs/xfs_attr.c
> @@ -1422,7 +1422,7 @@ xfs_attr_node_get(
>  	 * If not in a transaction, we have to release all the buffers.
>  	 */
>  out_release:
> -	for (i = 0; i < state->path.active; i++) {
> +	for (i = 0; i < state && state->path.active; i++) {
>  		xfs_trans_brelse(args->trans, state->path.blk[i].bp);
>  		state->path.blk[i].bp = NULL;
>  	}
> -- 
> 2.7.4
>
Allison Henderson July 29, 2020, 8:02 p.m. UTC | #2
On 7/29/20 12:59 PM, Darrick J. Wong wrote:
> On Tue, Jul 28, 2020 at 09:37:47PM -0700, Allison Collins wrote:
>> Fix warning: variable dereferenced before check 'state' in
>> xfs_attr_node_get.  If xfs_attr_node_hasname fails, it may return a null
>> state.  If state is null, do not release paths or derefrence state
>>
>> Signed-off-by: Allison Collins <allison.henderson@oracle.com>
> 
> Looks ok, though I folded all these into the for-next rebase (and then
> forgot to push send on this...)
> 
No worries, thank you!
Allison

> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> --D
> 
>> ---
>>   fs/xfs/libxfs/xfs_attr.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
>> index e5ec9ed..38fe0d3 100644
>> --- a/fs/xfs/libxfs/xfs_attr.c
>> +++ b/fs/xfs/libxfs/xfs_attr.c
>> @@ -1422,7 +1422,7 @@ xfs_attr_node_get(
>>   	 * If not in a transaction, we have to release all the buffers.
>>   	 */
>>   out_release:
>> -	for (i = 0; i < state->path.active; i++) {
>> +	for (i = 0; i < state && state->path.active; i++) {
>>   		xfs_trans_brelse(args->trans, state->path.blk[i].bp);
>>   		state->path.blk[i].bp = NULL;
>>   	}
>> -- 
>> 2.7.4
>>
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
index e5ec9ed..38fe0d3 100644
--- a/fs/xfs/libxfs/xfs_attr.c
+++ b/fs/xfs/libxfs/xfs_attr.c
@@ -1422,7 +1422,7 @@  xfs_attr_node_get(
 	 * If not in a transaction, we have to release all the buffers.
 	 */
 out_release:
-	for (i = 0; i < state->path.active; i++) {
+	for (i = 0; i < state && state->path.active; i++) {
 		xfs_trans_brelse(args->trans, state->path.blk[i].bp);
 		state->path.blk[i].bp = NULL;
 	}