From owner-svn-src-all@freebsd.org Mon Jan 15 21:19:23 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9C46BE777CA; Mon, 15 Jan 2018 21:19:23 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 763CE6F019; Mon, 15 Jan 2018 21:19:23 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8EFBF16940; Mon, 15 Jan 2018 21:19:22 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w0FLJMFG066287; Mon, 15 Jan 2018 21:19:22 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0FLJM6Q066284; Mon, 15 Jan 2018 21:19:22 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201801152119.w0FLJM6Q066284@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Mon, 15 Jan 2018 21:19:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328024 - head/sys/netgraph X-SVN-Group: head X-SVN-Commit-Author: pfg X-SVN-Commit-Paths: head/sys/netgraph X-SVN-Commit-Revision: 328024 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jan 2018 21:19:23 -0000 Author: pfg Date: Mon Jan 15 21:19:21 2018 New Revision: 328024 URL: https://svnweb.freebsd.org/changeset/base/328024 Log: 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 Modified: head/sys/netgraph/ng_bridge.c head/sys/netgraph/ng_deflate.c head/sys/netgraph/ng_parse.c Modified: head/sys/netgraph/ng_bridge.c ============================================================================== --- head/sys/netgraph/ng_bridge.c Mon Jan 15 21:18:04 2018 (r328023) +++ head/sys/netgraph/ng_bridge.c Mon Jan 15 21:19:21 2018 (r328024) @@ -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; Modified: head/sys/netgraph/ng_deflate.c ============================================================================== --- head/sys/netgraph/ng_deflate.c Mon Jan 15 21:18:04 2018 (r328023) +++ head/sys/netgraph/ng_deflate.c Mon Jan 15 21:19:21 2018 (r328024) @@ -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 Modified: head/sys/netgraph/ng_parse.c ============================================================================== --- head/sys/netgraph/ng_parse.c Mon Jan 15 21:18:04 2018 (r328023) +++ head/sys/netgraph/ng_parse.c Mon Jan 15 21:19:21 2018 (r328024) @@ -1207,7 +1207,8 @@ ng_parse_composite(const struct ng_parse_type *type, c 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;