Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Jan 2018 15:55:51 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r328261 - head/sys/dev/drm2
Message-ID:  <201801221555.w0MFtpeU014956@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Mon Jan 22 15:55:51 2018
New Revision: 328261
URL: https://svnweb.freebsd.org/changeset/base/328261

Log:
  drm2: Basic use of mallocarray(9).
  
  These functions deal the same type of overflows we do with mallocarray(9).
  Using our mallocarray will panic, which different from the previous
  behavior (returning NULL), but neither behavior is more correct.
  
  As a sidenote, drm_calloc_large() is not currently used at all.
  
  Reviewed by:	dumbbell
  Differential Revision:	https://reviews.freebsd.org/D13835

Modified:
  head/sys/dev/drm2/drm_mem_util.h

Modified: head/sys/dev/drm2/drm_mem_util.h
==============================================================================
--- head/sys/dev/drm2/drm_mem_util.h	Mon Jan 22 08:33:59 2018	(r328260)
+++ head/sys/dev/drm2/drm_mem_util.h	Mon Jan 22 15:55:51 2018	(r328261)
@@ -36,19 +36,15 @@ __FBSDID("$FreeBSD$");
 
 static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
 {
-	if (size != 0 && nmemb > SIZE_MAX / size)
-		return NULL;
 
-	return malloc(nmemb * size, DRM_MEM_DRIVER, M_NOWAIT | M_ZERO);
+	return mallocarray(nmemb, size, DRM_MEM_DRIVER, M_NOWAIT | M_ZERO);
 }
 
 /* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
 static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
 {
-	if (size != 0 && nmemb > SIZE_MAX / size)
-		return NULL;
 
-	return malloc(nmemb * size, DRM_MEM_DRIVER, M_NOWAIT);
+	return mallocarray(nmemb, size, DRM_MEM_DRIVER, M_NOWAIT);
 }
 
 static __inline void drm_free_large(void *ptr)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801221555.w0MFtpeU014956>