svn commit: r321360 - stable/11/sys/kern

Alan Cox alc at FreeBSD.org
Sat Jul 22 05:26:30 UTC 2017


Author: alc
Date: Sat Jul 22 05:26:29 2017
New Revision: 321360
URL: https://svnweb.freebsd.org/changeset/base/321360

Log:
  MFC r315621
    Use IDX_TO_OFF(), not ptoa(), when converting the difference between two
    vm_pindex_t's into a vm_ooffset_t.
  
    The length given to shm_dotruncate() must never be negative.  Assert this.
  
    Tidy up a comment.

Modified:
  stable/11/sys/kern/uipc_shm.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/uipc_shm.c
==============================================================================
--- stable/11/sys/kern/uipc_shm.c	Sat Jul 22 04:57:51 2017	(r321359)
+++ stable/11/sys/kern/uipc_shm.c	Sat Jul 22 05:26:29 2017	(r321360)
@@ -418,6 +418,7 @@ shm_dotruncate(struct shmfd *shmfd, off_t length)
 	vm_ooffset_t delta;
 	int base, rv;
 
+	KASSERT(length >= 0, ("shm_dotruncate: length < 0"));
 	object = shmfd->shm_object;
 	VM_OBJECT_WLOCK(object);
 	if (length == shmfd->shm_size) {
@@ -478,7 +479,7 @@ retry:
 				vm_pager_page_unswapped(m);
 			}
 		}
-		delta = ptoa(object->size - nobjsize);
+		delta = IDX_TO_OFF(object->size - nobjsize);
 
 		/* Toss in memory pages. */
 		if (nobjsize < object->size)
@@ -493,8 +494,8 @@ retry:
 		swap_release_by_cred(delta, object->cred);
 		object->charge -= delta;
 	} else {
-		/* Attempt to reserve the swap */
-		delta = ptoa(nobjsize - object->size);
+		/* Try to reserve additional swap space. */
+		delta = IDX_TO_OFF(nobjsize - object->size);
 		if (!swap_reserve_by_cred(delta, object->cred)) {
 			VM_OBJECT_WUNLOCK(object);
 			return (ENOMEM);


More information about the svn-src-all mailing list