All of lore.kernel.org
 help / color / mirror / Atom feed
From: boris.brezillon@free-electrons.com (Boris BREZILLON)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 4/7] regulator: axp20x: reset probe data before each probe
Date: Wed, 18 Jun 2014 09:11:59 +0200	[thread overview]
Message-ID: <53A13BBF.7090202@free-electrons.com> (raw)
In-Reply-To: <20140617204449.GD19730@lukather>


On 17/06/2014 22:44, Maxime Ripard wrote:
> On Tue, Jun 17, 2014 at 09:38:40AM +0200, Boris BREZILLON wrote:
>> The init_data and of_node fields of the axp2xx_matches tables are filled
>> at each device probe by the axp20x_regulator_parse_dt function (which then
>> calls the of_regulator_match function).
>> This means we can probe a new device and consider data initialized during
>> the probe of another device as valid.
>>
>> Reset init_data and of_node field to NULL before each probe in order to
>> avoid this kind of issue.
>>
>> Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
>> ---
>>  drivers/regulator/axp20x-regulator.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
>> index 7a30f49..d42bf6d 100644
>> --- a/drivers/regulator/axp20x-regulator.c
>> +++ b/drivers/regulator/axp20x-regulator.c
>> @@ -324,6 +324,15 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
>>  		nregulators = AXP20X_REG_ID_MAX;
>>  	}
>>  
>> +	/*
>> +	 * Reset matches table (this table might have been modified by a
>> +	 * previous AXP2xx device probe).
>> +	 */
>> +	for (i = 0; i < nmatches; i++) {
>> +		matches[i].init_data = NULL;
>> +		matches[i].of_node = NULL;
>> +	}
>> +
> That looks rather hackish, especially since we've never been in such a
> case yet, since we have a single PMIC in our system.

Even if something is unlikely to happen, it doesn't mean it's impossible.
I'm pretty sure there are (or will be) some systems containing several
identical PMICs in the wild, and fixing this possible bug now prevents
us (or other developers) from having a big headache debugging this in
the future.

BTW, what is hackish in this code ?

>
> Can't you just use memzero here?

We can't just memset the whole matches table to zero, because some
fields (name and driver_data) are statically assigned.

>
> Maxime
>

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

WARNING: multiple messages have this Message-ID (diff)
From: Boris BREZILLON <boris.brezillon@free-electrons.com>
To: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Carlo Caione <carlo@caione.org>,
	Shuge <shuge@allwinnertech.com>,
	kevin@allwinnertech.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org, dev@linux-sunxi.org
Subject: Re: [PATCH v4 4/7] regulator: axp20x: reset probe data before each probe
Date: Wed, 18 Jun 2014 09:11:59 +0200	[thread overview]
Message-ID: <53A13BBF.7090202@free-electrons.com> (raw)
In-Reply-To: <20140617204449.GD19730@lukather>


On 17/06/2014 22:44, Maxime Ripard wrote:
> On Tue, Jun 17, 2014 at 09:38:40AM +0200, Boris BREZILLON wrote:
>> The init_data and of_node fields of the axp2xx_matches tables are filled
>> at each device probe by the axp20x_regulator_parse_dt function (which then
>> calls the of_regulator_match function).
>> This means we can probe a new device and consider data initialized during
>> the probe of another device as valid.
>>
>> Reset init_data and of_node field to NULL before each probe in order to
>> avoid this kind of issue.
>>
>> Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
>> ---
>>  drivers/regulator/axp20x-regulator.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
>> index 7a30f49..d42bf6d 100644
>> --- a/drivers/regulator/axp20x-regulator.c
>> +++ b/drivers/regulator/axp20x-regulator.c
>> @@ -324,6 +324,15 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
>>  		nregulators = AXP20X_REG_ID_MAX;
>>  	}
>>  
>> +	/*
>> +	 * Reset matches table (this table might have been modified by a
>> +	 * previous AXP2xx device probe).
>> +	 */
>> +	for (i = 0; i < nmatches; i++) {
>> +		matches[i].init_data = NULL;
>> +		matches[i].of_node = NULL;
>> +	}
>> +
> That looks rather hackish, especially since we've never been in such a
> case yet, since we have a single PMIC in our system.

Even if something is unlikely to happen, it doesn't mean it's impossible.
I'm pretty sure there are (or will be) some systems containing several
identical PMICs in the wild, and fixing this possible bug now prevents
us (or other developers) from having a big headache debugging this in
the future.

BTW, what is hackish in this code ?

>
> Can't you just use memzero here?

We can't just memset the whole matches table to zero, because some
fields (name and driver_data) are statically assigned.

>
> Maxime
>

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


  reply	other threads:[~2014-06-18  7:11 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-17  7:38 [PATCH v4 0/7] mfd: axp20x: add AXP221 PMIC support Boris BREZILLON
2014-06-17  7:38 ` Boris BREZILLON
2014-06-17  7:38 ` Boris BREZILLON
2014-06-17  7:38 ` [PATCH v4 1/7] " Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-18  8:36   ` Lee Jones
2014-06-18  8:36     ` Lee Jones
2014-06-18  8:36     ` Lee Jones
2014-06-18  8:46     ` Boris BREZILLON
2014-06-18  8:46       ` Boris BREZILLON
2014-06-18  8:46       ` Boris BREZILLON
2014-06-18  9:28       ` Lee Jones
2014-06-18  9:28         ` Lee Jones
2014-06-18  9:28         ` Lee Jones
2014-06-17  7:38 ` [PATCH v4 2/7] regulator: axp20x: prepare support for multiple AXP chip families Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38 ` [PATCH v4 3/7] regulator: axp20x: add support for AXP221 regulators Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38 ` [PATCH v4 4/7] regulator: axp20x: reset probe data before each probe Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17 20:44   ` Maxime Ripard
2014-06-17 20:44     ` Maxime Ripard
2014-06-17 20:44     ` Maxime Ripard
2014-06-18  7:11     ` Boris BREZILLON [this message]
2014-06-18  7:11       ` Boris BREZILLON
2014-06-18  8:32       ` [linux-sunxi] " Hans de Goede
2014-06-18  8:32         ` Hans de Goede
2014-06-18  8:32         ` Hans de Goede
2014-06-18 12:44       ` Maxime Ripard
2014-06-18 12:44         ` Maxime Ripard
2014-06-18 12:44         ` Maxime Ripard
2014-06-17  7:38 ` [PATCH v4 5/7] regulator: add support for regulator set registration Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38 ` [PATCH v4 6/7] regulator: axp20x: make use of devm_regulator_set_register Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON
2014-06-17 20:46   ` Maxime Ripard
2014-06-17 20:46     ` Maxime Ripard
2014-06-17 20:46     ` Maxime Ripard
2014-06-18  7:12     ` Boris BREZILLON
2014-06-18  7:12       ` Boris BREZILLON
2014-06-17  7:38 ` [PATCH v4 7/7] mfd: AXP20x: add "x-powers, axp221" compatible string to DT bindings doc Boris BREZILLON
2014-06-17  7:38   ` [PATCH v4 7/7] mfd: AXP20x: add "x-powers,axp221" " Boris BREZILLON
2014-06-17  7:38   ` Boris BREZILLON

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53A13BBF.7090202@free-electrons.com \
    --to=boris.brezillon@free-electrons.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.