public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: clear state each invocation of of_regulator_match
@ 2013-01-29 19:01 Stephen Warren
  2013-01-30  2:13 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Warren @ 2013-01-29 19:01 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Axel Lin, Graeme Gregory, Laxman Dewangan, AnilKumar Ch,
	linux-kernel

From: Stephen Warren <swarren@nvidia.com>

of_regulator_match() saves some dynamcially allocated state into the
match table that's passed to it. By implementation and not contract, for
each match table entry, if non-NULL state is already present,
of_regulator_match() will not overwrite it. of_regulator_match() is
typically called each time a regulator is probe()d. This means it is
called with the same match table over and over again if a regulator
triggers deferred probe. This results in stale, kfree()d data being left
in the match table from probe to probe, which causes a variety of crashes
or use of invalid data.

Explicitly free all output state from of_regulator_match() before
generating new results in order to avoid this.

Cc: stable@vger.kernel.org
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/regulator/of_regulator.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 6f68491..66ca769 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -120,6 +120,12 @@ int of_regulator_match(struct device *dev, struct device_node *node,
 	if (!dev || !node)
 		return -EINVAL;
 
+	for (i = 0; i < num_matches; i++) {
+		struct of_regulator_match *match = &matches[i];
+		match->init_data = NULL;
+		match->of_node = NULL;
+	}
+
 	for_each_child_of_node(node, child) {
 		name = of_get_property(child,
 					"regulator-compatible", NULL);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] regulator: clear state each invocation of of_regulator_match
  2013-01-29 19:01 [PATCH] regulator: clear state each invocation of of_regulator_match Stephen Warren
@ 2013-01-30  2:13 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2013-01-30  2:13 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Liam Girdwood, Axel Lin, Graeme Gregory, Laxman Dewangan,
	AnilKumar Ch, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 418 bytes --]

On Tue, Jan 29, 2013 at 12:01:13PM -0700, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
> 
> of_regulator_match() saves some dynamcially allocated state into the
> match table that's passed to it. By implementation and not contract, for
> each match table entry, if non-NULL state is already present,
> of_regulator_match() will not overwrite it. of_regulator_match() is

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-30  2:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-29 19:01 [PATCH] regulator: clear state each invocation of of_regulator_match Stephen Warren
2013-01-30  2:13 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox