Logically dead code at fs/afs/cell.c:206
Hi David,
Today Coverity reported a "Logically dead code" issue at fs/afs/cell.c:206:
if (!excl) {
rcu_read_lock();
cell = afs_lookup_cell_rcu(net, name, namesz);
rcu_read_unlock();
if (!IS_ERR(cell)) {
if (excl) {
afs_put_cell(net, cell);
return ERR_PTR(-EEXIST);
}
goto wait_for_cell;
}
}The problem is that when this code block is executed, the code block starting at line 211 makes no sense, as _excl_ can never be true.
I was wondering if the original intention was to null check _cell_ instead of checking _excl_. So I took a look into function afs_lookup_cell_rcu to see if _cell_ can be returned as a null pointer and at the same time the if condition at line 210 be true, but I couldn't see how that could be possible. It seems to me that when _ret_ is equal to zero, _cell_ cannot be null in afs_lookup_cell_rcu. But is case I'm wrong here and _cell_ could be null at line 210, then I think line 211 should be changed as follows:
fs/afs/cell.c +1 -1
@@ -208,7 +208,7 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net, cell =afs_lookup_cell_rcu (net, name, namesz);rcu_read_unlock ();if (!IS_ERR (cell)) { -if (excl) { +if (cell) {afs_put_cell (net, cell);return ERR_PTR (-EEXIST ); }
But I'm suspicious about it.
What do you think?
Thanks
--
Gustavo A. R. Silva
David Howells
maintainerQuoted 15 lines · Gustavo A. R. Silva
Today Coverity reported a "Logically dead code" issue at
fs/afs/cell.c:206:if (!excl) { rcu_read_lock(); cell = afs_lookup_cell_rcu(net, name, namesz); rcu_read_unlock(); if (!IS_ERR(cell)) { if (excl) { afs_put_cell(net, cell); return ERR_PTR(-EEXIST); } goto wait_for_cell; } }
Quoted 2 lines
The problem is that when this code block is executed, the code block starting at line 211 makes no sense, as _excl_ can never be true.
Good catch. The interior "if (excl) { ... }" statement and body needs removing entirely. Originally the outer "if (!excl)" wrapping it wasn't there.
David
Quoting David Howells <[email protected]>:
Quoted 17 lines
Quoted 15 lines · Gustavo A. R. Silva
Today Coverity reported a "Logically dead code" issue at
fs/afs/cell.c:206:if (!excl) { rcu_read_lock(); cell = afs_lookup_cell_rcu(net, name, namesz); rcu_read_unlock(); if (!IS_ERR(cell)) { if (excl) { afs_put_cell(net, cell); return ERR_PTR(-EEXIST); } goto wait_for_cell; } }
Quoted 7 lines
Quoted 2 lines
The problem is that when this code block is executed, the code block starting at line 211 makes no sense, as _excl_ can never be true.
Good catch. The interior "if (excl) { ... }" statement and body needs removing entirely. Originally the outer "if (!excl)" wrapping it wasn't there.
I'll send a patch to remove that code.
Thanks for clarifying.
--
Gustavo A. R. Silva