linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Baluta <daniel.baluta@intel.com>
To: jic23@kernel.org
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	daniel.baluta@intel.com, matt.ranostay@intel.com,
	lucas.demarchi@intel.com, cmo@melexis.com,
	linux-iio@vger.kernel.org, ggao@invensense.com,
	srinivas.pandruvada@linux.intel.com, adi.reus@gmail.com
Subject: [PATCH 1/3] iio: imu: mpu6050: Fix name/chip_id when using ACPI
Date: Thu, 17 Mar 2016 18:32:44 +0200	[thread overview]
Message-ID: <1458232366-12773-2-git-send-email-daniel.baluta@intel.com> (raw)
In-Reply-To: <1458232366-12773-1-git-send-email-daniel.baluta@intel.com>

When using ACPI, id is NULL and the current code automatically
defaults name to NULL and chip id to 0. We should instead use
the data provided in the ACPI device table.

Fixes: c816d9e7a57b ("iio: imu: mpu6050: fix possible NULL dereferences")
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index d0c0e20..5ee4e0d 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -104,6 +104,19 @@ static int inv_mpu6050_deselect_bypass(struct i2c_adapter *adap,
 	return 0;
 }
 
+static const char *inv_mpu_match_acpi_device(struct device *dev, int *chip_id)
+{
+	const struct acpi_device_id *id;
+
+	id = acpi_match_device(dev->driver->acpi_match_table, dev);
+	if (!id)
+		return NULL;
+
+	*chip_id = (int)id->driver_data;
+
+	return dev_name(dev);
+}
+
 /**
  *  inv_mpu_probe() - probe function.
  *  @client:          i2c client.
@@ -115,15 +128,25 @@ static int inv_mpu_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
 	struct inv_mpu6050_state *st;
-	int result;
-	const char *name = id ? id->name : NULL;
-	const int chip_type = id ? id->driver_data : 0;
+	int result, chip_type;
 	struct regmap *regmap;
+	const char *name;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_I2C_BLOCK))
 		return -EOPNOTSUPP;
 
+	if (id) {
+		chip_type = (int)id->driver_data;
+		name = id->name;
+	} else if (ACPI_HANDLE(&client->dev)) {
+		name = inv_mpu_match_acpi_device(&client->dev, &chip_type);
+		if (!name)
+			return -ENODEV;
+	} else {
+		return -ENOSYS;
+	}
+
 	regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config);
 	if (IS_ERR(regmap)) {
 		dev_err(&client->dev, "Failed to register i2c regmap %d\n",
-- 
2.5.0


  reply	other threads:[~2016-03-17 16:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-17 16:32 [PATCH 0/3] Introduce support for INV MPU6050 secondary I2C master Daniel Baluta
2016-03-17 16:32 ` Daniel Baluta [this message]
2016-03-17 17:21   ` [PATCH 1/3] iio: imu: mpu6050: Fix name/chip_id when using ACPI Matt Ranostay
2016-03-20 10:40     ` Jonathan Cameron
2016-03-21 10:16       ` Daniel Baluta
2016-03-21 18:58         ` Jonathan Cameron
2016-03-17 16:32 ` [PATCH 2/3] iio: imu: mpu6050: Move request IRQ outside of probe trigger Daniel Baluta
2016-03-17 17:24   ` Matt Ranostay
2016-03-17 16:32 ` [PATCH 3/3] iio: imu: mpu6050: Add support for auxiliary I2C master Daniel Baluta
2016-03-17 17:28   ` Matt Ranostay
2016-03-17 18:11     ` Ge Gao
2016-03-17 18:13       ` Matt Ranostay
2016-03-17 21:15       ` De Marchi, Lucas
2016-03-20 10:54       ` Jonathan Cameron
2016-03-20 10:47   ` Jonathan Cameron
2016-03-23 12:32     ` Daniel Baluta

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=1458232366-12773-2-git-send-email-daniel.baluta@intel.com \
    --to=daniel.baluta@intel.com \
    --cc=adi.reus@gmail.com \
    --cc=cmo@melexis.com \
    --cc=ggao@invensense.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=matt.ranostay@intel.com \
    --cc=pmeerw@pmeerw.net \
    --cc=srinivas.pandruvada@linux.intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).