diff options
author | Pedro F. Giffuni <pfg@FreeBSD.org> | 2018-01-15 21:19:21 +0000 |
---|---|---|
committer | Pedro F. Giffuni <pfg@FreeBSD.org> | 2018-01-15 21:19:21 +0000 |
commit | 3b0a4e40a08c8c3d0f6862648b3ac0126d2d15e4 (patch) | |
tree | e2285d9894b38b5d736c6c3fea328583d6966218 | |
parent | a18a2290cd704e9348285c150c9c6e1d9a2493ff (diff) | |
download | src-3b0a4e40a08c8c3d0f6862648b3ac0126d2d15e4.tar.gz src-3b0a4e40a08c8c3d0f6862648b3ac0126d2d15e4.zip |
netgraph: make some use of mallocarray(9).
Focus on code where we are doing multiplications within malloc(9). None of
these ire likely to overflow, however the change is still useful as some
static checkers can benefit from the allocation attributes we use for
mallocarray.
This initial sweep only covers malloc(9) calls with M_NOWAIT. No good
reason but I started doing the changes before r327796 and at that time it
was convenient to make sure the sorrounding code could handle NULL values.
X-Differential revision: https://reviews.freebsd.org/D13837
Notes
Notes:
svn path=/head/; revision=328024
-rw-r--r-- | sys/netgraph/ng_bridge.c | 2 | ||||
-rw-r--r-- | sys/netgraph/ng_deflate.c | 2 | ||||
-rw-r--r-- | sys/netgraph/ng_parse.c | 3 |
3 files changed, 4 insertions, 3 deletions
diff --git a/sys/netgraph/ng_bridge.c b/sys/netgraph/ng_bridge.c index a1e3f2658d38..11462537e43b 100644 --- a/sys/netgraph/ng_bridge.c +++ b/sys/netgraph/ng_bridge.c @@ -907,7 +907,7 @@ ng_bridge_rehash(priv_p priv) newMask = newNumBuckets - 1; /* Allocate and initialize new table */ - newTab = malloc(newNumBuckets * sizeof(*newTab), + newTab = mallocarray(newNumBuckets, sizeof(*newTab), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO); if (newTab == NULL) return; diff --git a/sys/netgraph/ng_deflate.c b/sys/netgraph/ng_deflate.c index 9c0ab7a753e2..bb6a1823b42c 100644 --- a/sys/netgraph/ng_deflate.c +++ b/sys/netgraph/ng_deflate.c @@ -427,7 +427,7 @@ static void * z_alloc(void *notused, u_int items, u_int size) { - return (malloc(items * size, M_NETGRAPH_DEFLATE, M_NOWAIT)); + return (mallocarray(items, size, M_NETGRAPH_DEFLATE, M_NOWAIT)); } static void diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c index b08cecd102e9..466c01398102 100644 --- a/sys/netgraph/ng_parse.c +++ b/sys/netgraph/ng_parse.c @@ -1207,7 +1207,8 @@ ng_parse_composite(const struct ng_parse_type *type, const char *s, int align, len, blen, error = 0; /* Initialize */ - foff = malloc(num * sizeof(*foff), M_NETGRAPH_PARSE, M_NOWAIT | M_ZERO); + foff = mallocarray(num, sizeof(*foff), M_NETGRAPH_PARSE, + M_NOWAIT | M_ZERO); if (foff == NULL) { error = ENOMEM; goto done; |