Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Aug 2010 17:52:33 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r211579 - stable/7/sys/kern
Message-ID:  <201008211752.o7LHqXQ9076757@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Sat Aug 21 17:52:33 2010
New Revision: 211579
URL: http://svn.freebsd.org/changeset/base/211579

Log:
  MFC r210422: cpufreq: allocate long-lived buffer for handling of sysctl
  requests

Modified:
  stable/7/sys/kern/kern_cpu.c
Directory Properties:
  stable/7/sys/   (props changed)
  stable/7/sys/cddl/contrib/opensolaris/   (props changed)
  stable/7/sys/contrib/dev/acpica/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)

Modified: stable/7/sys/kern/kern_cpu.c
==============================================================================
--- stable/7/sys/kern/kern_cpu.c	Sat Aug 21 17:48:29 2010	(r211578)
+++ stable/7/sys/kern/kern_cpu.c	Sat Aug 21 17:52:33 2010	(r211579)
@@ -76,6 +76,7 @@ struct cpufreq_softc {
 	device_t			dev;
 	struct sysctl_ctx_list		sysctl_ctx;
 	struct task			startup_task;
+	struct cf_level			*levels_buf;
 };
 
 struct cf_setting_array {
@@ -176,6 +177,8 @@ cpufreq_attach(device_t dev)
 
 	CF_DEBUG("initializing one-time data for %s\n",
 	    device_get_nameunit(dev));
+	sc->levels_buf = malloc(CF_MAX_LEVELS * sizeof(*sc->levels_buf),
+	    M_DEVBUF, M_WAITOK);
 	SYSCTL_ADD_PROC(&sc->sysctl_ctx,
 	    SYSCTL_CHILDREN(device_get_sysctl_tree(parent)),
 	    OID_AUTO, "freq", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
@@ -223,6 +226,7 @@ cpufreq_detach(device_t dev)
 	numdevs = devclass_get_count(cpufreq_dc);
 	if (numdevs == 1) {
 		CF_DEBUG("final shutdown for %s\n", device_get_nameunit(dev));
+		free(sc->levels_buf, M_DEVBUF);
 	}
 
 	return (0);
@@ -861,9 +865,7 @@ cpufreq_curr_sysctl(SYSCTL_HANDLER_ARGS)
 
 	devs = NULL;
 	sc = oidp->oid_arg1;
-	levels = malloc(CF_MAX_LEVELS * sizeof(*levels), M_TEMP, M_NOWAIT);
-	if (levels == NULL)
-		return (ENOMEM);
+	levels = sc->levels_buf;
 
 	error = CPUFREQ_GET(sc->dev, &levels[0]);
 	if (error)
@@ -906,8 +908,6 @@ cpufreq_curr_sysctl(SYSCTL_HANDLER_ARGS)
 out:
 	if (devs)
 		free(devs, M_TEMP);
-	if (levels)
-		free(levels, M_TEMP);
 	return (error);
 }
 
@@ -925,7 +925,7 @@ cpufreq_levels_sysctl(SYSCTL_HANDLER_ARG
 
 	/* Get settings from the device and generate the output string. */
 	count = CF_MAX_LEVELS;
-	levels = malloc(count * sizeof(*levels), M_TEMP, M_NOWAIT);
+	levels = sc->levels_buf;
 	if (levels == NULL) {
 		sbuf_delete(&sb);
 		return (ENOMEM);
@@ -948,7 +948,6 @@ cpufreq_levels_sysctl(SYSCTL_HANDLER_ARG
 	error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
 
 out:
-	free(levels, M_TEMP);
 	sbuf_delete(&sb);
 	return (error);
 }



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