summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2019-05-08 22:44:32 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2019-05-08 22:44:32 +0000
commit8cb9985dfed2bc225590478d19e767611cd53b48 (patch)
tree9a3477626e65e6429ed275aa0d14dbfb2f9de418 /sys
parentaf9d720cf4f95805fcadf97e7a59124a227d9995 (diff)
Fix overflow tests such that we can allocate arrays with zero items.
Linux allows this sillyness and it is needed to make X work on the integrated graphics on the AMD Ryzen 3 PRO 2200GE APU. ok jsg@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/pci/drm/include/linux/mm.h2
-rw-r--r--sys/dev/pci/drm/include/linux/slab.h4
2 files changed, 3 insertions, 3 deletions
diff --git a/sys/dev/pci/drm/include/linux/mm.h b/sys/dev/pci/drm/include/linux/mm.h
index 2723690beec..da4080289ba 100644
--- a/sys/dev/pci/drm/include/linux/mm.h
+++ b/sys/dev/pci/drm/include/linux/mm.h
@@ -41,7 +41,7 @@ kvmalloc(size_t size, gfp_t flags)
static inline void *
kvmalloc_array(size_t n, size_t size, int flags)
{
- if (n == 0 || SIZE_MAX / n < size)
+ if (n != 0 && SIZE_MAX / n < size)
return NULL;
return malloc(n * size, M_DRM, flags);
}
diff --git a/sys/dev/pci/drm/include/linux/slab.h b/sys/dev/pci/drm/include/linux/slab.h
index b0b65b71a93..0d5463ecc1b 100644
--- a/sys/dev/pci/drm/include/linux/slab.h
+++ b/sys/dev/pci/drm/include/linux/slab.h
@@ -19,7 +19,7 @@ kmalloc(size_t size, int flags)
static inline void *
kmalloc_array(size_t n, size_t size, int flags)
{
- if (n == 0 || SIZE_MAX / n < size)
+ if (n != 0 && SIZE_MAX / n < size)
return NULL;
return malloc(n * size, M_DRM, flags);
}
@@ -27,7 +27,7 @@ kmalloc_array(size_t n, size_t size, int flags)
static inline void *
kcalloc(size_t n, size_t size, int flags)
{
- if (n == 0 || SIZE_MAX / n < size)
+ if (n != 0 && SIZE_MAX / n < size)
return NULL;
return malloc(n * size, M_DRM, flags | M_ZERO);
}