Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Mar 2016 01:14:32 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r297129 - stable/10/cddl/contrib/opensolaris/lib/libdtrace/common
Message-ID:  <201603210114.u2L1EWvc053990@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Mon Mar 21 01:14:32 2016
New Revision: 297129
URL: https://svnweb.freebsd.org/changeset/base/297129

Log:
  MFC r296816:
  
  libdtrace: use calloc(3) instead of malloc(3) when it makes sense.
  
  calloc(3) is faster and occasionally safer than malloc(3) + bzero(3).
  
  In one case, pointed out by Mark[1], this also cleans up a calculation.
  
  Reviewed by:	markj [1]

Modified:
  stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
  stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c
  stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
==============================================================================
--- stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c	Mon Mar 21 00:59:30 2016	(r297128)
+++ stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c	Mon Mar 21 01:14:32 2016	(r297129)
@@ -24,6 +24,7 @@
  */
 /*
  * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
+ * Copyright (c) 2016, Pedro Giffuni.  All rights reserved.
  */
 
 #include <sys/types.h>
@@ -704,22 +705,20 @@ dt_module_load_proc(dtrace_hdl_t *dtp, d
 		return (dt_set_errno(dtp, EDT_CANTLOAD));
 	}
 
-	dmp->dm_libctfp = malloc(sizeof (ctf_file_t *) * arg.dpa_count);
+	dmp->dm_libctfp = calloc(arg.dpa_count, sizeof (ctf_file_t *));
 	if (dmp->dm_libctfp == NULL) {
 		dt_proc_unlock(dtp, p);
 		dt_proc_release(dtp, p);
 		return (dt_set_errno(dtp, EDT_NOMEM));
 	}
-	bzero(dmp->dm_libctfp, sizeof (ctf_file_t *) * arg.dpa_count);
 
-	dmp->dm_libctfn = malloc(sizeof (char *) * arg.dpa_count);
+	dmp->dm_libctfn = calloc(arg.dpa_count, sizeof (char *));
 	if (dmp->dm_libctfn == NULL) {
 		free(dmp->dm_libctfp);
 		dt_proc_unlock(dtp, p);
 		dt_proc_release(dtp, p);
 		return (dt_set_errno(dtp, EDT_NOMEM));
 	}
-	bzero(dmp->dm_libctfn, sizeof (char *) * arg.dpa_count);
 
 	dmp->dm_nctflibs = arg.dpa_count;
 
@@ -800,17 +799,14 @@ dt_module_load(dtrace_hdl_t *dtp, dt_mod
 	dmp->dm_nsymbuckets = _dtrace_strbuckets;
 	dmp->dm_symfree = 1;		/* first free element is index 1 */
 
-	dmp->dm_symbuckets = malloc(sizeof (uint_t) * dmp->dm_nsymbuckets);
-	dmp->dm_symchains = malloc(sizeof (dt_sym_t) * dmp->dm_nsymelems + 1);
+	dmp->dm_symbuckets = calloc(dmp->dm_nsymbuckets, sizeof (uint_t));
+	dmp->dm_symchains = calloc(dmp->dm_nsymelems + 1, sizeof (dt_sym_t));
 
 	if (dmp->dm_symbuckets == NULL || dmp->dm_symchains == NULL) {
 		dt_module_unload(dtp, dmp);
 		return (dt_set_errno(dtp, EDT_NOMEM));
 	}
 
-	bzero(dmp->dm_symbuckets, sizeof (uint_t) * dmp->dm_nsymbuckets);
-	bzero(dmp->dm_symchains, sizeof (dt_sym_t) * dmp->dm_nsymelems + 1);
-
 	/*
 	 * Iterate over the symbol table data buffer and insert each symbol
 	 * name into the name hash if the name and type are valid.  Then

Modified: stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c
==============================================================================
--- stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c	Mon Mar 21 00:59:30 2016	(r297128)
+++ stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c	Mon Mar 21 01:14:32 2016	(r297129)
@@ -27,6 +27,7 @@
 
 /*
  * Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2016 Pedro Giffuni.  All rights reserved.
  */
 
 #include <sys/types.h>
@@ -47,15 +48,15 @@ dt_regset_create(ulong_t nregs)
 	if (drp == NULL)
 		return (NULL);
 
-	drp->dr_bitmap = malloc(sizeof (ulong_t) * n);
-	drp->dr_size = nregs;
+	drp->dr_bitmap = calloc(n, sizeof (ulong_t));
 
 	if (drp->dr_bitmap == NULL) {
 		dt_regset_destroy(drp);
 		return (NULL);
 	}
 
-	bzero(drp->dr_bitmap, sizeof (ulong_t) * n);
+	drp->dr_size = nregs;
+
 	return (drp);
 }
 

Modified: stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c
==============================================================================
--- stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c	Mon Mar 21 00:59:30 2016	(r297128)
+++ stable/10/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c	Mon Mar 21 01:14:32 2016	(r297129)
@@ -24,6 +24,10 @@
  * Use is subject to license terms.
  */
 
+/*
+ * Portions Copyright 2016 Pedro Giffuni.  All rights reserved.
+ */
+ 
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
 
 #include <sys/types.h>
@@ -70,12 +74,11 @@ dt_strtab_create(size_t bufsz)
 		return (NULL);
 
 	bzero(sp, sizeof (dt_strtab_t));
-	sp->str_hash = malloc(nbuckets * sizeof (dt_strhash_t *));
+	sp->str_hash = calloc(nbuckets, sizeof (dt_strhash_t *));
 
 	if (sp->str_hash == NULL)
 		goto err;
 
-	bzero(sp->str_hash, nbuckets * sizeof (dt_strhash_t *));
 	sp->str_hashsz = nbuckets;
 	sp->str_bufs = NULL;
 	sp->str_ptr = NULL;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603210114.u2L1EWvc053990>