Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Mar 2014 10:25:26 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r263080 - in head/sys: dev/cpuctl dev/hwpmc kern
Message-ID:  <201403121025.s2CAPQRl017239@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed Mar 12 10:25:26 2014
New Revision: 263080
URL: http://svnweb.freebsd.org/changeset/base/263080

Log:
  Use correct types for sizeof() in the calculations for the malloc(9) sizes [1].
  While there, remove unneeded checks for failed allocations with M_WAITOK flag.
  
  Submitted by:	Conrad Meyer <cemeyer@uw.edu> [1]
  MFC after:	1 week

Modified:
  head/sys/dev/cpuctl/cpuctl.c
  head/sys/dev/hwpmc/hwpmc_piv.c
  head/sys/kern/kern_linker.c

Modified: head/sys/dev/cpuctl/cpuctl.c
==============================================================================
--- head/sys/dev/cpuctl/cpuctl.c	Wed Mar 12 10:23:51 2014	(r263079)
+++ head/sys/dev/cpuctl/cpuctl.c	Wed Mar 12 10:25:26 2014	(r263080)
@@ -510,13 +510,8 @@ cpuctl_modevent(module_t mod __unused, i
 		}
 		if (bootverbose)
 			printf("cpuctl: access to MSR registers/cpuid info.\n");
-		cpuctl_devs = (struct cdev **)malloc(sizeof(void *) * mp_ncpus,
-		    M_CPUCTL, M_WAITOK | M_ZERO);
-		if (cpuctl_devs == NULL) {
-			DPRINTF("[cpuctl,%d]: cannot allocate memory\n",
-			    __LINE__);
-			return (ENOMEM);
-		}
+		cpuctl_devs = malloc(sizeof(*cpuctl_devs) * mp_ncpus, M_CPUCTL,
+		    M_WAITOK | M_ZERO);
 		for (cpu = 0; cpu < mp_ncpus; cpu++)
 			if (cpu_enabled(cpu))
 				cpuctl_devs[cpu] = make_dev(&cpuctl_cdevsw, cpu,

Modified: head/sys/dev/hwpmc/hwpmc_piv.c
==============================================================================
--- head/sys/dev/hwpmc/hwpmc_piv.c	Wed Mar 12 10:23:51 2014	(r263079)
+++ head/sys/dev/hwpmc/hwpmc_piv.c	Wed Mar 12 10:25:26 2014	(r263080)
@@ -1620,8 +1620,7 @@ pmc_p4_initialize(struct pmc_mdep *md, i
 	PMCDBG(MDP,INI,1, "%s", "p4-initialize");
 
 	/* Allocate space for pointers to per-cpu descriptors. */
-	p4_pcpu = malloc(sizeof(struct p4_cpu **) * ncpus, M_PMC,
-	    M_ZERO|M_WAITOK);
+	p4_pcpu = malloc(sizeof(*p4_pcpu) * ncpus, M_PMC, M_ZERO | M_WAITOK);
 
 	/* Fill in the class dependent descriptor. */
 	pcd = &md->pmd_classdep[PMC_MDEP_CLASS_INDEX_P4];

Modified: head/sys/kern/kern_linker.c
==============================================================================
--- head/sys/kern/kern_linker.c	Wed Mar 12 10:23:51 2014	(r263079)
+++ head/sys/kern/kern_linker.c	Wed Mar 12 10:25:26 2014	(r263080)
@@ -725,14 +725,11 @@ linker_file_add_dependency(linker_file_t
 	linker_file_t *newdeps;
 
 	sx_assert(&kld_sx, SA_XLOCKED);
-	newdeps = malloc((file->ndeps + 1) * sizeof(linker_file_t *),
-	    M_LINKER, M_WAITOK | M_ZERO);
-	if (newdeps == NULL)
-		return (ENOMEM);
+	newdeps = malloc((file->ndeps + 1) * sizeof(*newdeps), M_LINKER,
+	    M_WAITOK | M_ZERO);
 
 	if (file->deps) {
-		bcopy(file->deps, newdeps,
-		    file->ndeps * sizeof(linker_file_t *));
+		bcopy(file->deps, newdeps, file->ndeps * sizeof(*newdeps));
 		free(file->deps, M_LINKER);
 	}
 	file->deps = newdeps;



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