Skip to contentSkip to conversation

xfs: Fix Smatch warning in xfs_attr_node_get

PATCH In review Allison Collins 2 participants 3 messages Jul 29, 2020 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfs: Fix Smatch warning in xfs_attr_node_get

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

---
 fs/xfs/libxfs/xfs_attr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index e5ec9ed..38fe0d3 100644
@@ -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;
 	}
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Allison Collins

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

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

--D

Quoted 20 lines
---
 fs/xfs/libxfs/xfs_attr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index e5ec9ed..38fe0d3 100644
@@ -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;
 	}
Signature · 1 line
2.7.4
#2 lore raw
Quoted 10 lines · Darrick J. Wong
Quoted 5 lines · Allison Collins

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

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

Quoted 24 lines

--D

Quoted 20 lines
---
  fs/xfs/libxfs/xfs_attr.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index e5ec9ed..38fe0d3 100644
@@ -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;
  	}
Signature · 1 line
2.7.4