Author: kib
Date: Mon Dec 10 05:14:04 2012
New Revision: 244076
URL: http://svnweb.freebsd.org/changeset/base/244076

Log:
  Do not ignore zero address, possibly returned by the vm_map_find()
  call.  The function indicates a failure by the TRUE return value.  To
  be extra safe, assert that the return value from the following
  vm_map_insert() indicates success.
  
  Fix style issues in the nearby lines, reformulate the comment.
  
  Reviewed by:  alc (previous version)
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week

Modified:
  head/sys/kern/vfs_bio.c

Modified: head/sys/kern/vfs_bio.c
==============================================================================
--- head/sys/kern/vfs_bio.c     Mon Dec 10 03:11:19 2012        (r244075)
+++ head/sys/kern/vfs_bio.c     Mon Dec 10 05:14:04 2012        (r244076)
@@ -2107,15 +2107,16 @@ restart:
 
                if (maxsize != bp->b_kvasize) {
                        vm_offset_t addr = 0;
+                       int rv;
 
                        bfreekva(bp);
 
                        vm_map_lock(buffer_map);
                        if (vm_map_findspace(buffer_map,
-                               vm_map_min(buffer_map), maxsize, &addr)) {
+                           vm_map_min(buffer_map), maxsize, &addr)) {
                                /*
-                                * Uh oh.  Buffer map is to fragmented.  We
-                                * must defragment the map.
+                                * Buffer map is too fragmented.
+                                * We must defragment the map.
                                 */
                                atomic_add_int(&bufdefragcnt, 1);
                                vm_map_unlock(buffer_map);
@@ -2124,22 +2125,21 @@ restart:
                                brelse(bp);
                                goto restart;
                        }
-                       if (addr) {
-                               vm_map_insert(buffer_map, NULL, 0,
-                                       addr, addr + maxsize,
-                                       VM_PROT_ALL, VM_PROT_ALL, MAP_NOFAULT);
-
-                               bp->b_kvabase = (caddr_t) addr;
-                               bp->b_kvasize = maxsize;
-                               atomic_add_long(&bufspace, bp->b_kvasize);
-                               atomic_add_int(&bufreusecnt, 1);
-                       }
+                       rv = vm_map_insert(buffer_map, NULL, 0, addr,
+                           addr + maxsize, VM_PROT_ALL, VM_PROT_ALL,
+                           MAP_NOFAULT);
+                       KASSERT(rv == KERN_SUCCESS,
+                           ("vm_map_insert(buffer_map) rv %d", rv));
                        vm_map_unlock(buffer_map);
+                       bp->b_kvabase = (caddr_t)addr;
+                       bp->b_kvasize = maxsize;
+                       atomic_add_long(&bufspace, bp->b_kvasize);
+                       atomic_add_int(&bufreusecnt, 1);
                }
                bp->b_saveaddr = bp->b_kvabase;
                bp->b_data = bp->b_saveaddr;
        }
-       return(bp);
+       return (bp);
 }
 
 /*
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to