提交 a95e56e7 编写于 作者: J J. Bruce Fields

lockd: clean up __nsm_find()

Use list_for_each_entry().  Also, in keeping with kernel style, make the
normal case (kzalloc succeeds) unindented and handle the abnormal case
with a goto.
Signed-off-by: NJ. Bruce Fields <bfields@citi.umich.edu>
上级 164f98ad
...@@ -465,7 +465,7 @@ __nsm_find(const struct sockaddr_in *sin, ...@@ -465,7 +465,7 @@ __nsm_find(const struct sockaddr_in *sin,
int create) int create)
{ {
struct nsm_handle *nsm = NULL; struct nsm_handle *nsm = NULL;
struct list_head *pos; struct nsm_handle *pos;
if (!sin) if (!sin)
return NULL; return NULL;
...@@ -480,16 +480,16 @@ __nsm_find(const struct sockaddr_in *sin, ...@@ -480,16 +480,16 @@ __nsm_find(const struct sockaddr_in *sin,
} }
mutex_lock(&nsm_mutex); mutex_lock(&nsm_mutex);
list_for_each(pos, &nsm_handles) { list_for_each_entry(pos, &nsm_handles, sm_link) {
nsm = list_entry(pos, struct nsm_handle, sm_link);
if (hostname && nsm_use_hostnames) { if (hostname && nsm_use_hostnames) {
if (strlen(nsm->sm_name) != hostname_len if (strlen(pos->sm_name) != hostname_len
|| memcmp(nsm->sm_name, hostname, hostname_len)) || memcmp(pos->sm_name, hostname, hostname_len))
continue; continue;
} else if (!nlm_cmp_addr(&nsm->sm_addr, sin)) } else if (!nlm_cmp_addr(&pos->sm_addr, sin))
continue; continue;
atomic_inc(&nsm->sm_count); atomic_inc(&pos->sm_count);
nsm = pos;
goto out; goto out;
} }
...@@ -499,15 +499,15 @@ __nsm_find(const struct sockaddr_in *sin, ...@@ -499,15 +499,15 @@ __nsm_find(const struct sockaddr_in *sin,
} }
nsm = kzalloc(sizeof(*nsm) + hostname_len + 1, GFP_KERNEL); nsm = kzalloc(sizeof(*nsm) + hostname_len + 1, GFP_KERNEL);
if (nsm != NULL) { if (nsm == NULL)
nsm->sm_addr = *sin; goto out;
nsm->sm_name = (char *) (nsm + 1); nsm->sm_addr = *sin;
memcpy(nsm->sm_name, hostname, hostname_len); nsm->sm_name = (char *) (nsm + 1);
nsm->sm_name[hostname_len] = '\0'; memcpy(nsm->sm_name, hostname, hostname_len);
atomic_set(&nsm->sm_count, 1); nsm->sm_name[hostname_len] = '\0';
atomic_set(&nsm->sm_count, 1);
list_add(&nsm->sm_link, &nsm_handles);
} list_add(&nsm->sm_link, &nsm_handles);
out: out:
mutex_unlock(&nsm_mutex); mutex_unlock(&nsm_mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册