[PATCH 6/6] afs: shorten the afs_cells_lock range

Yuanhan Liu yliu.null at gmail.com
Fri Jun 22 12:09:06 EDT 2012


afs_cells_lock is a lock used to just protect the afs_cells list. Thus
we should lock/unlock between the operation on that list.

Signed-off-by: Yuanhan Liu <yliu.null at gmail.com>
---
 fs/afs/cell.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index e23a9c7..eeff5ab 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -273,21 +273,21 @@ struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz,
 	_enter("\"%*.*s\",", namesz, namesz, name ?: "");
 
 	down_read(&afs_cells_sem);
-	read_lock(&afs_cells_lock);
 
 	if (name) {
 		/* if the cell was named, look for it in the cell record list */
+		read_lock(&afs_cells_lock);
 		list_for_each_entry(cell, &afs_cells, link) {
 			if (strncmp(cell->name, name, namesz) == 0) {
 				afs_get_cell(cell);
+				read_unlock(&afs_cells_lock);
 				goto found;
 			}
 		}
+		read_unlock(&afs_cells_lock);
 		cell = ERR_PTR(-ENOENT);
 		if (dns_cell)
 			goto create_cell;
-	found:
-		;
 	} else {
 		cell = afs_cell_root;
 		if (!cell) {
@@ -304,13 +304,12 @@ struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz,
 
 	}
 
-	read_unlock(&afs_cells_lock);
+found:
 	up_read(&afs_cells_sem);
 	_leave(" = %p", cell);
 	return cell;
 
 create_cell:
-	read_unlock(&afs_cells_lock);
 	up_read(&afs_cells_sem);
 
 	cell = afs_cell_create(name, namesz, NULL, true);
-- 
1.7.4.4




More information about the linux-afs mailing list