Implement the array_size() function in the LinuxKPI. This function
basically multiplies its two arguments and returns SIZE_MAX if the result overflows the size_t type. Else the product of the two arguments is returned. Bump the FreeBSD_version to mitigate issues with existing implementation of array_size() in drm-devel-kmod. Discussed with: manu@ MFC after: 1 week Sponsored by: Mellanox Technologies
This commit is contained in:
parent
6ddc843832
commit
d2890eeea1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363077
@ -31,6 +31,9 @@
|
|||||||
#ifndef __LINUX_OVERFLOW_H__
|
#ifndef __LINUX_OVERFLOW_H__
|
||||||
#define __LINUX_OVERFLOW_H__
|
#define __LINUX_OVERFLOW_H__
|
||||||
|
|
||||||
|
#include <sys/stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#ifndef __has_builtin
|
#ifndef __has_builtin
|
||||||
#define __has_builtin(x) 0
|
#define __has_builtin(x) 0
|
||||||
#endif
|
#endif
|
||||||
@ -45,6 +48,16 @@
|
|||||||
#if __has_builtin(__builtin_mul_overflow)
|
#if __has_builtin(__builtin_mul_overflow)
|
||||||
#define check_mul_overflow(a, b, c) \
|
#define check_mul_overflow(a, b, c) \
|
||||||
__builtin_mul_overflow(a, b, c)
|
__builtin_mul_overflow(a, b, c)
|
||||||
|
|
||||||
|
static inline size_t
|
||||||
|
array_size(size_t x, size_t y)
|
||||||
|
{
|
||||||
|
size_t retval;
|
||||||
|
|
||||||
|
if (__builtin_mul_overflow(x, y, &retval))
|
||||||
|
retval = SIZE_MAX;
|
||||||
|
return (retval);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#error "Compiler does not support __builtin_mul_overflow"
|
#error "Compiler does not support __builtin_mul_overflow"
|
||||||
#endif
|
#endif
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
* in the range 5 to 9.
|
* in the range 5 to 9.
|
||||||
*/
|
*/
|
||||||
#undef __FreeBSD_version
|
#undef __FreeBSD_version
|
||||||
#define __FreeBSD_version 1300100 /* Master, propagated to newvers */
|
#define __FreeBSD_version 1300101 /* Master, propagated to newvers */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
|
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
|
||||||
|
Loading…
Reference in New Issue
Block a user