2017-11-18 14:50:16

by Gustavo A. R. Silva

[permalink] [raw]
Subject: 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:

diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index 1858c91..a69a11f 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -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






From 1586076955004605591@xxx Wed Dec 06 22:54:15 +0000 2017
X-GM-THRID: 1585946427959255769
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread