Re: [PATCH] mmc: move regulator handling to core

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Walleij
Date: Saturday, August 28, 2010 - 7:48 am

2010/8/27 Chris Ball <cjb@laptop.org>:


Actually just before the summer I submitted something not quite similar:
I moved all regulator handling *out* of the MMC core because I didn't
trust the way reference counting was being handled.

There is something very disturbing about this code from
regulator/core/core.c mmc_regulator_set_ocr():

enabled = regulator_is_enabled(supply);
if (enabled < 0)
	return enabled;

if (...) {
	(...)
	voltage = regulator_get_voltage(supply);
	if (voltage < 0)
		result = voltage;
	else if (voltage < min_uV || voltage > max_uV)
		result = regulator_set_voltage(supply, min_uV, max_uV);
	else
		result = 0;

	if (result == 0 && !enabled)
		result = regulator_enable(supply);
} else if (enabled) {
	result = regulator_disable(supply);
}

I didn't realize until today where the problem is: if you have
two hosts on the same regulator this does not handle
concurrency correctly. There is no lock taken between reading
the enabled status and acting on it later in the code.

So it looks to me like it is possible for one slot to enable the
regulator and race with another slot which disables it at the
same time and end up with the regulator disabled :-(

My solution would still be to move the enable/disable out
of the core, so I need to follow up on that.

This old patch however, goes in the opposite direction,
moving it all into the core. If you do this, please fix the
concurrency issue also...

Yours,
Linus Walleij
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] mmc: move regulator handling to core, Daniel Mack, (Thu Dec 3, 5:46 am)
Re: [PATCH] mmc: move regulator handling to core, Mark Brown, (Thu Dec 3, 6:06 am)
Re: [PATCH] mmc: move regulator handling to core, Daniel Mack, (Thu Dec 3, 6:14 am)
Re: [PATCH] mmc: move regulator handling to core, Mark Brown, (Thu Dec 3, 6:22 am)
Re: [PATCH] mmc: move regulator handling to core, Daniel Mack, (Thu Dec 3, 6:32 am)
Re: [PATCH] mmc: move regulator handling to core, Mark Brown, (Thu Dec 3, 6:40 am)
Re: [PATCH] mmc: move regulator handling to core, Daniel Mack, (Thu Dec 3, 6:43 am)
Re: [PATCH] mmc: move regulator handling to core, Adrian Hunter, (Thu Dec 3, 7:27 am)
Re: [PATCH] mmc: move regulator handling to core, Russell King - ARM Linux, (Thu Dec 3, 7:58 am)
Re: [PATCH] mmc: move regulator handling to core, Mark Brown, (Thu Dec 3, 8:09 am)
Re: [PATCH] mmc: move regulator handling to core, Daniel Mack, (Thu Dec 3, 12:20 pm)
Re: [PATCH] mmc: move regulator handling to core, Adrian Hunter, (Thu Dec 3, 1:12 pm)
Re: [PATCH] mmc: move regulator handling to core, Daniel Mack, (Fri Dec 4, 4:58 am)
Re: [PATCH] mmc: move regulator handling to core, Daniel Mack, (Fri Dec 11, 5:58 pm)
RE: [PATCH] mmc: move regulator handling to core, Madhusudhan, (Mon Dec 14, 10:43 am)
Re: [PATCH] mmc: move regulator handling to core, David Brownell, (Mon Dec 14, 10:44 pm)
Re: [PATCH] mmc: move regulator handling to core, Chris Ball, (Fri Aug 27, 12:03 pm)
Re: [PATCH] mmc: move regulator handling to core, Linus Walleij, (Sat Aug 28, 7:48 am)
Re: [PATCH] mmc: move regulator handling to core, Mark Brown, (Sun Aug 29, 6:27 am)
Re: [PATCH] mmc: move regulator handling to core, Linus Walleij, (Sun Aug 29, 8:30 am)
Re: [PATCH] mmc: move regulator handling to core, Mark Brown, (Tue Aug 31, 4:07 am)
Re: [PATCH] mmc: move regulator handling to core, Linus Walleij, (Tue Aug 31, 5:15 am)