Date: Tue, 16 Jan 2018 19:29:32 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328056 - head/sys/fs/ext2fs Message-ID: <201801161929.w0GJTWbN027800@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801161929.w0GJTWbN027800>