From owner-svn-src-all@freebsd.org Tue Jan 16 19:29:33 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 AFE02EB3557; Tue, 16 Jan 2018 19:29:33 +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 8C86168E56; Tue, 16 Jan 2018 19:29:33 +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 E65FF24B2B; Tue, 16 Jan 2018 19:29:32 +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 w0GJTWHW027802; Tue, 16 Jan 2018 19:29:32 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0GJTWbN027800; Tue, 16 Jan 2018 19:29:32 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201801161929.w0GJTWbN027800@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Tue, 16 Jan 2018 19:29:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328056 - head/sys/fs/ext2fs X-SVN-Group: head X-SVN-Commit-Author: pfg X-SVN-Commit-Paths: head/sys/fs/ext2fs X-SVN-Commit-Revision: 328056 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: Tue, 16 Jan 2018 19:29:33 -0000 Author: pfg Date: Tue Jan 16 19:29:32 2018 New Revision: 328056 URL: https://svnweb.freebsd.org/changeset/base/328056 Log: ext2fs: use mallocarray(9). Focus on code where we are doing multiplications within malloc(9). These are not likely to overflow, however the change is still useful as some static checkers can benefit from the allocation attributes we use for mallocarray. Modified: head/sys/fs/ext2fs/ext2_lookup.c head/sys/fs/ext2fs/ext2_vfsops.c Modified: head/sys/fs/ext2fs/ext2_lookup.c ============================================================================== --- head/sys/fs/ext2fs/ext2_lookup.c Tue Jan 16 18:36:25 2018 (r328055) +++ head/sys/fs/ext2fs/ext2_lookup.c Tue Jan 16 19:29:32 2018 (r328056) @@ -145,9 +145,9 @@ ext2_readdir(struct vop_readdir_args *ap) off_t offset, startoffset; size_t readcnt, skipcnt; ssize_t startresid; - int ncookies; int DIRBLKSIZ = VTOI(ap->a_vp)->i_e2fs->e2fs_bsize; int error; + u_int ncookies; if (uio->uio_offset < 0) return (EINVAL); @@ -160,7 +160,8 @@ ext2_readdir(struct vop_readdir_args *ap) ncookies = ip->i_size - uio->uio_offset; ncookies = ncookies / (offsetof(struct ext2fs_direct_2, e2d_namlen) + 4) + 1; - cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK); + cookies = mallocarray(ncookies, sizeof(*cookies), M_TEMP, + M_WAITOK); *ap->a_ncookies = ncookies; *ap->a_cookies = cookies; } else { Modified: head/sys/fs/ext2fs/ext2_vfsops.c ============================================================================== --- head/sys/fs/ext2fs/ext2_vfsops.c Tue Jan 16 18:36:25 2018 (r328055) +++ head/sys/fs/ext2fs/ext2_vfsops.c Tue Jan 16 19:29:32 2018 (r328056) @@ -400,9 +400,9 @@ compute_sb_data(struct vnode *devvp, struct ext2fs *es fs->e2fs_bsize / sizeof(struct ext2_gd)); } fs->e2fs_gdbcount = howmany(fs->e2fs_gcount, e2fs_descpb); - fs->e2fs_gd = malloc(e2fs_gdbcount_alloc * fs->e2fs_bsize, + fs->e2fs_gd = mallocarray(e2fs_gdbcount_alloc, fs->e2fs_bsize, M_EXT2MNT, M_WAITOK | M_ZERO); - fs->e2fs_contigdirs = malloc(fs->e2fs_gcount * + fs->e2fs_contigdirs = mallocarray(fs->e2fs_gcount, sizeof(*fs->e2fs_contigdirs), M_EXT2MNT, M_WAITOK | M_ZERO); /* @@ -683,7 +683,8 @@ ext2_mountfs(struct vnode *devvp, struct mount *mp) for (i = 0; i < ump->um_e2fs->e2fs_gcount; i++, sump++) { *lp++ = ump->um_e2fs->e2fs_contigsumsize; sump->cs_init = 0; - sump->cs_sum = malloc((ump->um_e2fs->e2fs_contigsumsize + 1) * + sump->cs_sum = mallocarray( + ump->um_e2fs->e2fs_contigsumsize + 1, sizeof(int32_t), M_EXT2MNT, M_WAITOK | M_ZERO); } }