Commit 40f32d93 authored by Preetham Chandru's avatar Preetham Chandru Committed by Greg Kroah-Hartman

staging: iio: ak8975: Remove i2c client data corruption

i2c client data set is of type struct indio_dev pointer and hence the
pointer returned from i2c_get_clientdata() should be assigned to
an object of type struct indio_dev and not to an object of type
struct ak8975_data.

Also in ak8975_probe() client data should be set first
before calling ak8975_setup() as it references the client data.
Signed-off-by: default avatarPreetham Chandru R <pchandru@nvidia.com>
CC: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent be0775ac
...@@ -108,7 +108,8 @@ static const int ak8975_index_to_reg[] = { ...@@ -108,7 +108,8 @@ static const int ak8975_index_to_reg[] = {
static int ak8975_write_data(struct i2c_client *client, static int ak8975_write_data(struct i2c_client *client,
u8 reg, u8 val, u8 mask, u8 shift) u8 reg, u8 val, u8 mask, u8 shift)
{ {
struct ak8975_data *data = i2c_get_clientdata(client); struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct ak8975_data *data = iio_priv(indio_dev);
u8 regval; u8 regval;
int ret; int ret;
...@@ -159,7 +160,8 @@ static int ak8975_read_data(struct i2c_client *client, ...@@ -159,7 +160,8 @@ static int ak8975_read_data(struct i2c_client *client,
*/ */
static int ak8975_setup(struct i2c_client *client) static int ak8975_setup(struct i2c_client *client)
{ {
struct ak8975_data *data = i2c_get_clientdata(client); struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct ak8975_data *data = iio_priv(indio_dev);
u8 device_id; u8 device_id;
int ret; int ret;
...@@ -509,6 +511,7 @@ static int ak8975_probe(struct i2c_client *client, ...@@ -509,6 +511,7 @@ static int ak8975_probe(struct i2c_client *client,
goto exit_gpio; goto exit_gpio;
} }
data = iio_priv(indio_dev); data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
/* Perform some basic start-of-day setup of the device. */ /* Perform some basic start-of-day setup of the device. */
err = ak8975_setup(client); err = ak8975_setup(client);
if (err < 0) { if (err < 0) {
...@@ -516,7 +519,6 @@ static int ak8975_probe(struct i2c_client *client, ...@@ -516,7 +519,6 @@ static int ak8975_probe(struct i2c_client *client,
goto exit_free_iio; goto exit_free_iio;
} }
i2c_set_clientdata(client, indio_dev);
data->client = client; data->client = client;
mutex_init(&data->lock); mutex_init(&data->lock);
data->eoc_irq = client->irq; data->eoc_irq = client->irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment