From owner-svn-src-head@freebsd.org Mon Jan 15 21:08:23 2018 Return-Path: Delivered-To: svn-src-head@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 969E3E76C86; Mon, 15 Jan 2018 21:08: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 725AC6DE9D; Mon, 15 Jan 2018 21:08: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 B9D0016789; Mon, 15 Jan 2018 21:08: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 w0FL8MCF061124; Mon, 15 Jan 2018 21:08:22 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0FL8M8m061120; Mon, 15 Jan 2018 21:08:22 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201801152108.w0FL8M8m061120@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:08:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328016 - in head/sys: amd64/amd64 i386/i386 x86/cpufreq X-SVN-Group: head X-SVN-Commit-Author: pfg X-SVN-Commit-Paths: in head/sys: amd64/amd64 i386/i386 x86/cpufreq X-SVN-Commit-Revision: 328016 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jan 2018 21:08:23 -0000 Author: pfg Date: Mon Jan 15 21:08:22 2018 New Revision: 328016 URL: https://svnweb.freebsd.org/changeset/base/328016 Log: x86: 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/amd64/amd64/bpf_jit_machdep.c head/sys/i386/i386/bpf_jit_machdep.c head/sys/i386/i386/k6_mem.c head/sys/x86/cpufreq/est.c Modified: head/sys/amd64/amd64/bpf_jit_machdep.c ============================================================================== --- head/sys/amd64/amd64/bpf_jit_machdep.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/amd64/amd64/bpf_jit_machdep.c Mon Jan 15 21:08:22 2018 (r328016) @@ -186,7 +186,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, siz /* Allocate the reference table for the jumps. */ if (fjmp) { #ifdef _KERNEL - stream.refs = malloc((nins + 1) * sizeof(u_int), M_BPFJIT, + stream.refs = mallocarray(nins + 1, sizeof(u_int), M_BPFJIT, M_NOWAIT | M_ZERO); #else stream.refs = calloc(nins + 1, sizeof(u_int)); Modified: head/sys/i386/i386/bpf_jit_machdep.c ============================================================================== --- head/sys/i386/i386/bpf_jit_machdep.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/i386/i386/bpf_jit_machdep.c Mon Jan 15 21:08:22 2018 (r328016) @@ -185,7 +185,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, siz /* Allocate the reference table for the jumps. */ if (fjmp) { #ifdef _KERNEL - stream.refs = malloc((nins + 1) * sizeof(u_int), M_BPFJIT, + stream.refs = mallocarray(nins + 1, sizeof(u_int), M_BPFJIT, M_NOWAIT | M_ZERO); #else stream.refs = calloc(nins + 1, sizeof(u_int)); Modified: head/sys/i386/i386/k6_mem.c ============================================================================== --- head/sys/i386/i386/k6_mem.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/i386/i386/k6_mem.c Mon Jan 15 21:08:22 2018 (r328016) @@ -107,7 +107,7 @@ k6_mrinit(struct mem_range_softc *sc) sc->mr_cap = 0; sc->mr_ndesc = 2; /* XXX (BFF) For now, we only have one msr for this */ - sc->mr_desc = malloc(sc->mr_ndesc * sizeof(struct mem_range_desc), + sc->mr_desc = mallocarray(sc->mr_ndesc, sizeof(struct mem_range_desc), M_MEMDESC, M_NOWAIT | M_ZERO); if (sc->mr_desc == NULL) panic("k6_mrinit: malloc returns NULL"); Modified: head/sys/x86/cpufreq/est.c ============================================================================== --- head/sys/x86/cpufreq/est.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/x86/cpufreq/est.c Mon Jan 15 21:08:22 2018 (r328016) @@ -1119,7 +1119,7 @@ est_acpi_info(device_t dev, freq_info **freqs) goto out; /* Parse settings into our local table format. */ - table = malloc((count + 1) * sizeof(freq_info), M_DEVBUF, M_NOWAIT); + table = mallocarray(count + 1, sizeof(freq_info), M_DEVBUF, M_NOWAIT); if (table == NULL) { error = ENOMEM; goto out;