Fri Sep 20 11:09:43 2019 UTC ()
Fix programming mistake: 'paddrp' is a pointer given as argument, setting
it to NULL in the called function does not set it to NULL in the caller.

Actually, the callers of these functions do not do anything with the
special error handling, so drop the unused checks and the NULL assignments
altogether.

Found by the lgtm bot.


(maxv)
diff -r1.199 -r1.200 src/sys/uvm/uvm_page.c
diff -r1.9 -r1.10 src/sys/uvm/uvm_physseg.c

cvs diff -r1.199 -r1.200 src/sys/uvm/uvm_page.c (expand / switch to unified diff)

--- src/sys/uvm/uvm_page.c 2019/03/14 19:10:04 1.199
+++ src/sys/uvm/uvm_page.c 2019/09/20 11:09:43 1.200
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uvm_page.c,v 1.199 2019/03/14 19:10:04 kre Exp $ */ 1/* $NetBSD: uvm_page.c,v 1.200 2019/09/20 11:09:43 maxv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Charles D. Cranor and Washington University. 4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 * Copyright (c) 1991, 1993, The Regents of the University of California. 5 * Copyright (c) 1991, 1993, The Regents of the University of California.
6 * 6 *
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * This code is derived from software contributed to Berkeley by 9 * This code is derived from software contributed to Berkeley by
10 * The Mach Operating System project at Carnegie-Mellon University. 10 * The Mach Operating System project at Carnegie-Mellon University.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -56,27 +56,27 @@ @@ -56,27 +56,27 @@
56 * School of Computer Science 56 * School of Computer Science
57 * Carnegie Mellon University 57 * Carnegie Mellon University
58 * Pittsburgh PA 15213-3890 58 * Pittsburgh PA 15213-3890
59 * 59 *
60 * any improvements or extensions that they make and grant Carnegie the 60 * any improvements or extensions that they make and grant Carnegie the
61 * rights to redistribute these changes. 61 * rights to redistribute these changes.
62 */ 62 */
63 63
64/* 64/*
65 * uvm_page.c: page ops. 65 * uvm_page.c: page ops.
66 */ 66 */
67 67
68#include <sys/cdefs.h> 68#include <sys/cdefs.h>
69__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.199 2019/03/14 19:10:04 kre Exp $"); 69__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.200 2019/09/20 11:09:43 maxv Exp $");
70 70
71#include "opt_ddb.h" 71#include "opt_ddb.h"
72#include "opt_uvm.h" 72#include "opt_uvm.h"
73#include "opt_uvmhist.h" 73#include "opt_uvmhist.h"
74#include "opt_readahead.h" 74#include "opt_readahead.h"
75 75
76#include <sys/param.h> 76#include <sys/param.h>
77#include <sys/systm.h> 77#include <sys/systm.h>
78#include <sys/sched.h> 78#include <sys/sched.h>
79#include <sys/kernel.h> 79#include <sys/kernel.h>
80#include <sys/vnode.h> 80#include <sys/vnode.h>
81#include <sys/proc.h> 81#include <sys/proc.h>
82#include <sys/atomic.h> 82#include <sys/atomic.h>
@@ -619,45 +619,39 @@ uvm_page_physget_freelist(paddr_t *paddr @@ -619,45 +619,39 @@ uvm_page_physget_freelist(paddr_t *paddr
619 uvm_physseg_t lcv; 619 uvm_physseg_t lcv;
620 620
621 /* pass 1: try allocating from a matching end */ 621 /* pass 1: try allocating from a matching end */
622#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST) 622#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
623 for (lcv = uvm_physseg_get_last(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_prev(lcv)) 623 for (lcv = uvm_physseg_get_last(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_prev(lcv))
624#else 624#else
625 for (lcv = uvm_physseg_get_first(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_next(lcv)) 625 for (lcv = uvm_physseg_get_first(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_next(lcv))
626#endif 626#endif
627 { 627 {
628 if (uvm.page_init_done == true) 628 if (uvm.page_init_done == true)
629 panic("uvm_page_physget: called _after_ bootstrap"); 629 panic("uvm_page_physget: called _after_ bootstrap");
630 630
631 /* Try to match at front or back on unused segment */ 631 /* Try to match at front or back on unused segment */
632 if (uvm_page_physunload(lcv, freelist, paddrp) == false) { 632 if (uvm_page_physunload(lcv, freelist, paddrp))
633 if (paddrp == NULL) /* freelist fail, try next */ 
634 continue; 
635 } else 
636 return true; 633 return true;
637 } 634 }
638 635
639 /* pass2: forget about matching ends, just allocate something */ 636 /* pass2: forget about matching ends, just allocate something */
640#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST) 637#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
641 for (lcv = uvm_physseg_get_last(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_prev(lcv)) 638 for (lcv = uvm_physseg_get_last(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_prev(lcv))
642#else 639#else
643 for (lcv = uvm_physseg_get_first(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_next(lcv)) 640 for (lcv = uvm_physseg_get_first(); uvm_physseg_valid_p(lcv); lcv = uvm_physseg_get_next(lcv))
644#endif 641#endif
645 { 642 {
646 /* Try the front regardless. */ 643 /* Try the front regardless. */
647 if (uvm_page_physunload_force(lcv, freelist, paddrp) == false) { 644 if (uvm_page_physunload_force(lcv, freelist, paddrp))
648 if (paddrp == NULL) /* freelist fail, try next */ 
649 continue; 
650 } else 
651 return true; 645 return true;
652 } 646 }
653 return false; 647 return false;
654} 648}
655 649
656bool 650bool
657uvm_page_physget(paddr_t *paddrp) 651uvm_page_physget(paddr_t *paddrp)
658{ 652{
659 int i; 653 int i;
660 654
661 /* try in the order of freelist preference */ 655 /* try in the order of freelist preference */
662 for (i = 0; i < VM_NFREELIST; i++) 656 for (i = 0; i < VM_NFREELIST; i++)
663 if (uvm_page_physget_freelist(paddrp, i) == true) 657 if (uvm_page_physget_freelist(paddrp, i) == true)

cvs diff -r1.9 -r1.10 src/sys/uvm/uvm_physseg.c (expand / switch to unified diff)

--- src/sys/uvm/uvm_physseg.c 2018/01/21 17:58:43 1.9
+++ src/sys/uvm/uvm_physseg.c 2019/09/20 11:09:43 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uvm_physseg.c,v 1.9 2018/01/21 17:58:43 christos Exp $ */ 1/* $NetBSD: uvm_physseg.c,v 1.10 2019/09/20 11:09:43 maxv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Charles D. Cranor and Washington University. 4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 * Copyright (c) 1991, 1993, The Regents of the University of California. 5 * Copyright (c) 1991, 1993, The Regents of the University of California.
6 * 6 *
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * This code is derived from software contributed to Berkeley by 9 * This code is derived from software contributed to Berkeley by
10 * The Mach Operating System project at Carnegie-Mellon University. 10 * The Mach Operating System project at Carnegie-Mellon University.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -461,27 +461,26 @@ uvm_physseg_get_highest_frame(void) @@ -461,27 +461,26 @@ uvm_physseg_get_highest_frame(void)
461 * caller. 461 * caller.
462 */ 462 */
463bool 463bool
464uvm_page_physunload(uvm_physseg_t upm, int freelist, paddr_t *paddrp) 464uvm_page_physunload(uvm_physseg_t upm, int freelist, paddr_t *paddrp)
465{ 465{
466 struct uvm_physseg *seg; 466 struct uvm_physseg *seg;
467 467
468 if (__predict_true(uvm.page_init_done == true)) 468 if (__predict_true(uvm.page_init_done == true))
469 panic("%s: unload attempted after uvm_page_init()\n", __func__); 469 panic("%s: unload attempted after uvm_page_init()\n", __func__);
470 470
471 seg = HANDLE_TO_PHYSSEG_NODE(upm); 471 seg = HANDLE_TO_PHYSSEG_NODE(upm);
472 472
473 if (seg->free_list != freelist) { 473 if (seg->free_list != freelist) {
474 paddrp = NULL; 
475 return false; 474 return false;
476 } 475 }
477 476
478 /* 477 /*
479 * During cold boot, what we're about to unplug hasn't been 478 * During cold boot, what we're about to unplug hasn't been
480 * put on the uvm freelist, nor has uvmexp.npages been 479 * put on the uvm freelist, nor has uvmexp.npages been
481 * updated. (This happens in uvm_page.c:uvm_page_init()) 480 * updated. (This happens in uvm_page.c:uvm_page_init())
482 * 481 *
483 * For hotplug, we assume here that the pages being unloaded 482 * For hotplug, we assume here that the pages being unloaded
484 * here are completely out of sight of uvm (ie; not on any uvm 483 * here are completely out of sight of uvm (ie; not on any uvm
485 * lists), and that uvmexp.npages has been suitably 484 * lists), and that uvmexp.npages has been suitably
486 * decremented before we're called. 485 * decremented before we're called.
487 * 486 *
@@ -506,27 +505,26 @@ uvm_page_physunload(uvm_physseg_t upm, i @@ -506,27 +505,26 @@ uvm_page_physunload(uvm_physseg_t upm, i
506} 505}
507 506
508bool 507bool
509uvm_page_physunload_force(uvm_physseg_t upm, int freelist, paddr_t *paddrp) 508uvm_page_physunload_force(uvm_physseg_t upm, int freelist, paddr_t *paddrp)
510{ 509{
511 struct uvm_physseg *seg; 510 struct uvm_physseg *seg;
512 511
513 seg = HANDLE_TO_PHYSSEG_NODE(upm); 512 seg = HANDLE_TO_PHYSSEG_NODE(upm);
514 513
515 if (__predict_true(uvm.page_init_done == true)) 514 if (__predict_true(uvm.page_init_done == true))
516 panic("%s: unload attempted after uvm_page_init()\n", __func__); 515 panic("%s: unload attempted after uvm_page_init()\n", __func__);
517 /* any room in this bank? */ 516 /* any room in this bank? */
518 if (seg->avail_start >= seg->avail_end) { 517 if (seg->avail_start >= seg->avail_end) {
519 paddrp = NULL; 
520 return false; /* nope */ 518 return false; /* nope */
521 } 519 }
522 520
523 *paddrp = ctob(seg->avail_start); 521 *paddrp = ctob(seg->avail_start);
524 522
525 /* Always unplug from front */ 523 /* Always unplug from front */
526 return uvm_physseg_unplug(seg->avail_start, 1); 524 return uvm_physseg_unplug(seg->avail_start, 1);
527} 525}
528 526
529 527
530/* 528/*
531 * vm_physseg_find: find vm_physseg structure that belongs to a PA 529 * vm_physseg_find: find vm_physseg structure that belongs to a PA
532 */ 530 */
@@ -652,27 +650,26 @@ uvm_post_preload_check(void) @@ -652,27 +650,26 @@ uvm_post_preload_check(void)
652 * caller. 650 * caller.
653 */ 651 */
654bool 652bool
655uvm_page_physunload(uvm_physseg_t psi, int freelist, paddr_t *paddrp) 653uvm_page_physunload(uvm_physseg_t psi, int freelist, paddr_t *paddrp)
656{ 654{
657 int x; 655 int x;
658 struct uvm_physseg *seg; 656 struct uvm_physseg *seg;
659 657
660 uvm_post_preload_check(); 658 uvm_post_preload_check();
661 659
662 seg = VM_PHYSMEM_PTR(psi); 660 seg = VM_PHYSMEM_PTR(psi);
663 661
664 if (seg->free_list != freelist) { 662 if (seg->free_list != freelist) {
665 paddrp = NULL; 
666 return false; 663 return false;
667 } 664 }
668 665
669 /* try from front */ 666 /* try from front */
670 if (seg->avail_start == seg->start && 667 if (seg->avail_start == seg->start &&
671 seg->avail_start < seg->avail_end) { 668 seg->avail_start < seg->avail_end) {
672 *paddrp = ctob(seg->avail_start); 669 *paddrp = ctob(seg->avail_start);
673 seg->avail_start++; 670 seg->avail_start++;
674 seg->start++; 671 seg->start++;
675 /* nothing left? nuke it */ 672 /* nothing left? nuke it */
676 if (seg->avail_start == seg->end) { 673 if (seg->avail_start == seg->end) {
677 if (vm_nphysmem == 1) 674 if (vm_nphysmem == 1)
678 panic("uvm_page_physget: out of memory!"); 675 panic("uvm_page_physget: out of memory!");
@@ -707,27 +704,26 @@ uvm_page_physunload(uvm_physseg_t psi, i @@ -707,27 +704,26 @@ uvm_page_physunload(uvm_physseg_t psi, i
707 704
708bool 705bool
709uvm_page_physunload_force(uvm_physseg_t psi, int freelist, paddr_t *paddrp) 706uvm_page_physunload_force(uvm_physseg_t psi, int freelist, paddr_t *paddrp)
710{ 707{
711 int x; 708 int x;
712 struct uvm_physseg *seg; 709 struct uvm_physseg *seg;
713 710
714 uvm_post_preload_check(); 711 uvm_post_preload_check();
715 712
716 seg = VM_PHYSMEM_PTR(psi); 713 seg = VM_PHYSMEM_PTR(psi);
717 714
718 /* any room in this bank? */ 715 /* any room in this bank? */
719 if (seg->avail_start >= seg->avail_end) { 716 if (seg->avail_start >= seg->avail_end) {
720 paddrp = NULL; 
721 return false; /* nope */ 717 return false; /* nope */
722 } 718 }
723 719
724 *paddrp = ctob(seg->avail_start); 720 *paddrp = ctob(seg->avail_start);
725 seg->avail_start++; 721 seg->avail_start++;
726 /* truncate! */ 722 /* truncate! */
727 seg->start = seg->avail_start; 723 seg->start = seg->avail_start;
728 724
729 /* nothing left? nuke it */ 725 /* nothing left? nuke it */
730 if (seg->avail_start == seg->end) { 726 if (seg->avail_start == seg->end) {
731 if (vm_nphysmem == 1) 727 if (vm_nphysmem == 1)
732 panic("uvm_page_physget: out of memory!"); 728 panic("uvm_page_physget: out of memory!");
733 vm_nphysmem--; 729 vm_nphysmem--;