Commit a95e56e72c196970a8067cd515c658d064813170

Authored by J. Bruce Fields
1 parent 164f98adbb

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: J. Bruce Fields <bfields@citi.umich.edu>

Showing 1 changed file with 16 additions and 16 deletions Side-by-side Diff

... ... @@ -465,7 +465,7 @@
465 465 int create)
466 466 {
467 467 struct nsm_handle *nsm = NULL;
468   - struct list_head *pos;
  468 + struct nsm_handle *pos;
469 469  
470 470 if (!sin)
471 471 return NULL;
472 472  
473 473  
474 474  
... ... @@ -480,16 +480,16 @@
480 480 }
481 481  
482 482 mutex_lock(&nsm_mutex);
483   - list_for_each(pos, &nsm_handles) {
484   - nsm = list_entry(pos, struct nsm_handle, sm_link);
  483 + list_for_each_entry(pos, &nsm_handles, sm_link) {
485 484  
486 485 if (hostname && nsm_use_hostnames) {
487   - if (strlen(nsm->sm_name) != hostname_len
488   - || memcmp(nsm->sm_name, hostname, hostname_len))
  486 + if (strlen(pos->sm_name) != hostname_len
  487 + || memcmp(pos->sm_name, hostname, hostname_len))
489 488 continue;
490   - } else if (!nlm_cmp_addr(&nsm->sm_addr, sin))
  489 + } else if (!nlm_cmp_addr(&pos->sm_addr, sin))
491 490 continue;
492   - atomic_inc(&nsm->sm_count);
  491 + atomic_inc(&pos->sm_count);
  492 + nsm = pos;
493 493 goto out;
494 494 }
495 495  
496 496  
... ... @@ -499,15 +499,15 @@
499 499 }
500 500  
501 501 nsm = kzalloc(sizeof(*nsm) + hostname_len + 1, GFP_KERNEL);
502   - if (nsm != NULL) {
503   - nsm->sm_addr = *sin;
504   - nsm->sm_name = (char *) (nsm + 1);
505   - memcpy(nsm->sm_name, hostname, hostname_len);
506   - nsm->sm_name[hostname_len] = '\0';
507   - atomic_set(&nsm->sm_count, 1);
  502 + if (nsm == NULL)
  503 + goto out;
  504 + nsm->sm_addr = *sin;
  505 + nsm->sm_name = (char *) (nsm + 1);
  506 + memcpy(nsm->sm_name, hostname, hostname_len);
  507 + nsm->sm_name[hostname_len] = '\0';
  508 + atomic_set(&nsm->sm_count, 1);
508 509  
509   - list_add(&nsm->sm_link, &nsm_handles);
510   - }
  510 + list_add(&nsm->sm_link, &nsm_handles);
511 511  
512 512 out:
513 513 mutex_unlock(&nsm_mutex);