dev/bhnd: Make use of mallocarray(9).

This makes a calloc-like definition check for overflows as is common
practice.
This commit is contained in:
Pedro F. Giffuni 2018-01-11 15:44:03 +00:00
parent 454529cd0b
commit 92e1020a52
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327831
3 changed files with 3 additions and 3 deletions

View File

@ -400,7 +400,7 @@ bcma_erom_get_core_table(bhnd_erom_t *erom, struct bhnd_core_info **cores,
}
/* Allocate our output buffer */
buffer = malloc(sizeof(struct bhnd_core_info) * count, M_BHND,
buffer = mallocarray(count, sizeof(struct bhnd_core_info), M_BHND,
M_NOWAIT);
if (buffer == NULL) {
error = ENOMEM;

View File

@ -74,7 +74,7 @@ MALLOC_DECLARE(M_BHND_NVRAM);
#define bhnd_nv_toupper(c) toupper(c)
#define bhnd_nv_malloc(size) malloc((size), M_BHND_NVRAM, M_NOWAIT)
#define bhnd_nv_calloc(n, size) malloc((n) * (size), M_BHND_NVRAM, \
#define bhnd_nv_calloc(n, size) mallocarray((n), (size), M_BHND_NVRAM, \
M_NOWAIT | M_ZERO)
#define bhnd_nv_reallocf(buf, size) reallocf((buf), (size), M_BHND_NVRAM, \
M_NOWAIT)

View File

@ -445,7 +445,7 @@ siba_erom_get_core_table(bhnd_erom_t *erom, struct bhnd_core_info **cores,
sc = (struct siba_erom *)erom;
/* Allocate our core array */
out = malloc(sizeof(*out) * sc->io.ncores, M_BHND, M_NOWAIT);
out = mallocarray(sc->io.ncores, sizeof(*out), M_BHND, M_NOWAIT);
if (out == NULL)
return (ENOMEM);