From: Jonathan Cameron <jic23@kernel.org>
To: Matt Ranostay <mranostay@gmail.com>,
Daniel Baluta <daniel.baluta@intel.com>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Matt Ranostay <matt.ranostay@intel.com>,
Lucas De Marchi <lucas.demarchi@intel.com>,
cmo@melexis.com,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
ggao@invensense.com, srinivas.pandruvada@linux.intel.com,
adi.reus@gmail.com
Subject: Re: [PATCH 1/3] iio: imu: mpu6050: Fix name/chip_id when using ACPI
Date: Sun, 20 Mar 2016 10:40:52 +0000 [thread overview]
Message-ID: <56EE7E34.8040608@kernel.org> (raw)
In-Reply-To: <CAKzfze-nFeMJhp7oRrKaCuM+CRJpokFevCEdxB1Mu96H+pUT6A@mail.gmail.com>
On 17/03/16 17:21, Matt Ranostay wrote:
> Reviewed-By: Matt Ranostay <matt.ranostay@intel.com>
I'm guessing this may at some point want backporting, but right now it only
applies to my togreg branch (due to prior changes) so that's where I've applied
this. If you want a faster path to mainline, the please send me the backport.
Jonathan
>
> On Thu, Mar 17, 2016 at 9:32 AM, Daniel Baluta <daniel.baluta@intel.com> wrote:
>> 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
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2016-03-20 10:40 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 ` [PATCH 1/3] iio: imu: mpu6050: Fix name/chip_id when using ACPI Daniel Baluta
2016-03-17 17:21 ` Matt Ranostay
2016-03-20 10:40 ` Jonathan Cameron [this message]
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=56EE7E34.8040608@kernel.org \
--to=jic23@kernel.org \
--cc=adi.reus@gmail.com \
--cc=cmo@melexis.com \
--cc=daniel.baluta@intel.com \
--cc=ggao@invensense.com \
--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=mranostay@gmail.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).