diff mbox

[v2,1/2] mfd: tps65910: Fix crash in i2c_driver .probe

Message ID 1371550481-28126-2-git-send-email-ttynkkynen@nvidia.com
State Not Applicable
Headers show

Commit Message

Tuomas Tynkkynen June 18, 2013, 10:14 a.m. UTC
Commit "i2c: core: make it possible to match a pure device tree driver"
changed semantics of the i2c probing for device tree devices.
Device tree probed devices now get a NULL i2c_device_id pointer.
This caused kernel panics due to NULL dereference.

Moves the of_match_device call from tps65910_parse_dt to .probe to
allow the chip type to be detected from device tree but with the
device parameters coming from platform data.

Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
---
 v2: Don't overwrite platform data from DT 

 drivers/mfd/tps65910.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

Comments

Stephen Warren June 18, 2013, 3:39 p.m. UTC | #1
On 06/18/2013 04:14 AM, Tuomas Tynkkynen wrote:
> Commit "i2c: core: make it possible to match a pure device tree driver"
> changed semantics of the i2c probing for device tree devices.
> Device tree probed devices now get a NULL i2c_device_id pointer.
> This caused kernel panics due to NULL dereference.
> 
> Moves the of_match_device call from tps65910_parse_dt to .probe to
> allow the chip type to be detected from device tree but with the
> device parameters coming from platform data.

Reviewed-by: Stephen Warren <swaren@nvidia.com>

It's a pity that every driver that supports DT is going to need this
boiler-plate though. Perhaps the I2C core can acquire a follow-on patch
that does this for drivers in the future.
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lee Jones June 19, 2013, 8:18 a.m. UTC | #2
On Tue, 18 Jun 2013, Tuomas Tynkkynen wrote:

> Commit "i2c: core: make it possible to match a pure device tree driver"
> changed semantics of the i2c probing for device tree devices.
> Device tree probed devices now get a NULL i2c_device_id pointer.
> This caused kernel panics due to NULL dereference.
> 
> Moves the of_match_device call from tps65910_parse_dt to .probe to
> allow the chip type to be detected from device tree but with the
> device parameters coming from platform data.
> 
> Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>

Applied with Stephen's Reviewed-by, thanks.
Samuel Ortiz June 19, 2013, 8:27 a.m. UTC | #3
Hi Lee,

On Wed, Jun 19, 2013 at 09:18:59AM +0100, Lee Jones wrote:
> On Tue, 18 Jun 2013, Tuomas Tynkkynen wrote:
> 
> > Commit "i2c: core: make it possible to match a pure device tree driver"
> > changed semantics of the i2c probing for device tree devices.
> > Device tree probed devices now get a NULL i2c_device_id pointer.
> > This caused kernel panics due to NULL dereference.
> > 
> > Moves the of_match_device call from tps65910_parse_dt to .probe to
> > allow the chip type to be detected from device tree but with the
> > device parameters coming from platform data.
> > 
> > Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
> 
> Applied with Stephen's Reviewed-by, thanks.
According to Wolfgang, this is not needed as he will revert the i2c
commits that are causing those crashes.
I would not take it for now.

Cheers,
Samuel.
Lee Jones June 19, 2013, 9:48 a.m. UTC | #4
On Wed, 19 Jun 2013, Samuel Ortiz wrote:

> Hi Lee,
> 
> On Wed, Jun 19, 2013 at 09:18:59AM +0100, Lee Jones wrote:
> > On Tue, 18 Jun 2013, Tuomas Tynkkynen wrote:
> > 
> > > Commit "i2c: core: make it possible to match a pure device tree driver"
> > > changed semantics of the i2c probing for device tree devices.
> > > Device tree probed devices now get a NULL i2c_device_id pointer.
> > > This caused kernel panics due to NULL dereference.
> > > 
> > > Moves the of_match_device call from tps65910_parse_dt to .probe to
> > > allow the chip type to be detected from device tree but with the
> > > device parameters coming from platform data.
> > > 
> > > Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
> > 
> > Applied with Stephen's Reviewed-by, thanks.
> According to Wolfgang, this is not needed as he will revert the i2c
> commits that are causing those crashes.
> I would not take it for now.

Fair enough. Unapplied.
Wolfram Sang June 19, 2013, 10 a.m. UTC | #5
On Wed, Jun 19, 2013 at 10:27:40AM +0200, Samuel Ortiz wrote:
> Hi Lee,
> 
> On Wed, Jun 19, 2013 at 09:18:59AM +0100, Lee Jones wrote:
> > On Tue, 18 Jun 2013, Tuomas Tynkkynen wrote:
> > 
> > > Commit "i2c: core: make it possible to match a pure device tree driver"
> > > changed semantics of the i2c probing for device tree devices.
> > > Device tree probed devices now get a NULL i2c_device_id pointer.
> > > This caused kernel panics due to NULL dereference.
> > > 
> > > Moves the of_match_device call from tps65910_parse_dt to .probe to
> > > allow the chip type to be detected from device tree but with the
> > > device parameters coming from platform data.
> > > 
> > > Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
> > 
> > Applied with Stephen's Reviewed-by, thanks.
> According to Wolfgang, this is not needed as he will revert the i2c
> commits that are causing those crashes.
> I would not take it for now.

"Wolfram", please ;) Otherwise correct.

Thanks.
Samuel Ortiz June 19, 2013, 10:06 a.m. UTC | #6
Hi Wolfram,

On Wed, Jun 19, 2013 at 12:00:20PM +0200, Wolfram Sang wrote:
> > > Applied with Stephen's Reviewed-by, thanks.
> > According to Wolfgang, this is not needed as he will revert the i2c
> > commits that are causing those crashes.
> > I would not take it for now.
> 
> "Wolfram", please ;) Otherwise correct.
Apologies, it seems I have issues with first names today...

Cheers,
Samuel.
diff mbox

Patch

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index d792772..61147b4 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -384,22 +384,13 @@  static struct of_device_id tps65910_of_match[] = {
 MODULE_DEVICE_TABLE(of, tps65910_of_match);
 
 static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
-						int *chip_id)
+						int chip_id)
 {
 	struct device_node *np = client->dev.of_node;
 	struct tps65910_board *board_info;
 	unsigned int prop;
-	const struct of_device_id *match;
 	int ret = 0;
 
-	match = of_match_device(tps65910_of_match, &client->dev);
-	if (!match) {
-		dev_err(&client->dev, "Failed to find matching dt id\n");
-		return NULL;
-	}
-
-	*chip_id  = (int)match->data;
-
 	board_info = devm_kzalloc(&client->dev, sizeof(*board_info),
 			GFP_KERNEL);
 	if (!board_info) {
@@ -410,13 +401,13 @@  static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
 	ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop);
 	if (!ret)
 		board_info->vmbch_threshold = prop;
-	else if (*chip_id == TPS65911)
+	else if (chip_id == TPS65911)
 		dev_warn(&client->dev, "VMBCH-Threshold not specified");
 
 	ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop);
 	if (!ret)
 		board_info->vmbch2_threshold = prop;
-	else if (*chip_id == TPS65911)
+	else if (chip_id == TPS65911)
 		dev_warn(&client->dev, "VMBCH2-Threshold not specified");
 
 	prop = of_property_read_bool(np, "ti,en-ck32k-xtal");
@@ -432,7 +423,7 @@  static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
 #else
 static inline
 struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
-					 int *chip_id)
+					 int chip_id)
 {
 	return NULL;
 }
@@ -461,16 +452,28 @@  static int tps65910_i2c_probe(struct i2c_client *i2c,
 	struct tps65910_board *of_pmic_plat_data = NULL;
 	struct tps65910_platform_data *init_data;
 	int ret = 0;
-	int chip_id = id->driver_data;
+	int chip_id = -1;
 
 	pmic_plat_data = dev_get_platdata(&i2c->dev);
 
-	if (!pmic_plat_data && i2c->dev.of_node) {
-		pmic_plat_data = tps65910_parse_dt(i2c, &chip_id);
-		of_pmic_plat_data = pmic_plat_data;
+	if (id) {
+		chip_id = id->driver_data;
+	} else if (i2c->dev.of_node) {
+		const struct of_device_id *match;
+		match = of_match_device(tps65910_of_match, &i2c->dev);
+		if (!match) {
+			dev_err(&i2c->dev, "Failed to find matching dt id\n");
+			return -EINVAL;
+		}
+		chip_id  = (int)match->data;
+
+		if (!pmic_plat_data) {
+			pmic_plat_data = tps65910_parse_dt(i2c, chip_id);
+			of_pmic_plat_data = pmic_plat_data;
+		}
 	}
 
-	if (!pmic_plat_data)
+	if (!pmic_plat_data || chip_id < 0)
 		return -EINVAL;
 
 	init_data = devm_kzalloc(&i2c->dev, sizeof(*init_data), GFP_KERNEL);