diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c index 700f96c70273..33919e87e7ce 100644 --- a/drivers/staging/iio/magnetometer/ak8975.c +++ b/drivers/staging/iio/magnetometer/ak8975.c @@ -89,7 +89,6 @@ */ struct ak8975_data { struct i2c_client *client; - struct iio_dev *indio_dev; struct attribute_group attrs; struct mutex lock; u8 asa[3]; @@ -221,7 +220,7 @@ static ssize_t show_mode(struct device *dev, struct device_attribute *devattr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ak8975_data *data = indio_dev->dev_data; + struct ak8975_data *data = iio_priv(indio_dev); return sprintf(buf, "%lu\n", data->mode); } @@ -234,7 +233,7 @@ static ssize_t store_mode(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ak8975_data *data = indio_dev->dev_data; + struct ak8975_data *data = iio_priv(indio_dev); struct i2c_client *client = data->client; unsigned long oval; int ret; @@ -310,7 +309,7 @@ static ssize_t show_scale(struct device *dev, struct device_attribute *devattr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ak8975_data *data = indio_dev->dev_data; + struct ak8975_data *data = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(devattr); return sprintf(buf, "%ld\n", data->raw_to_gauss[this_attr->address]); @@ -376,7 +375,7 @@ static ssize_t show_raw(struct device *dev, struct device_attribute *devattr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ak8975_data *data = indio_dev->dev_data; + struct ak8975_data *data = iio_priv(indio_dev); struct i2c_client *client = data->client; struct iio_dev_attr *this_attr = to_iio_dev_attr(devattr); u16 meas_reg; @@ -483,46 +482,41 @@ static int ak8975_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ak8975_data *data; + struct iio_dev *indio_dev; + int eoc_gpio; int err; - /* Allocate our device context. */ - data = kzalloc(sizeof(struct ak8975_data), GFP_KERNEL); - if (!data) { - dev_err(&client->dev, "Memory allocation fails\n"); - err = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->client = client; - - mutex_init(&data->lock); - /* Grab and set up the supplied GPIO. */ - data->eoc_irq = client->irq; - data->eoc_gpio = irq_to_gpio(client->irq); + eoc_gpio = irq_to_gpio(client->irq); /* We may not have a GPIO based IRQ to scan, that is fine, we will poll if so */ - if (data->eoc_gpio > 0) { - err = gpio_request(data->eoc_gpio, "ak_8975"); + if (eoc_gpio > 0) { + err = gpio_request(eoc_gpio, "ak_8975"); if (err < 0) { dev_err(&client->dev, "failed to request GPIO %d, error %d\n", - data->eoc_gpio, err); - goto exit_free; + eoc_gpio, err); + goto exit; } - err = gpio_direction_input(data->eoc_gpio); + err = gpio_direction_input(eoc_gpio); if (err < 0) { dev_err(&client->dev, "Failed to configure input direction for GPIO %d, error %d\n", - data->eoc_gpio, err); + eoc_gpio, err); goto exit_gpio; } } else - data->eoc_gpio = 0; /* No GPIO available */ + eoc_gpio = 0; /* No GPIO available */ + /* Register with IIO */ + indio_dev = iio_allocate_device(sizeof(*data)); + if (indio_dev == NULL) { + err = -ENOMEM; + goto exit_gpio; + } + data = iio_priv(indio_dev); /* Perform some basic start-of-day setup of the device. */ err = ak8975_setup(client); if (err < 0) { @@ -530,46 +524,41 @@ static int ak8975_probe(struct i2c_client *client, goto exit_gpio; } - /* Register with IIO */ - data->indio_dev = iio_allocate_device(0); - if (data->indio_dev == NULL) { - err = -ENOMEM; - goto exit_gpio; - } + i2c_set_clientdata(client, indio_dev); + data->client = client; + mutex_init(&data->lock); + data->eoc_irq = client->irq; + data->eoc_gpio = eoc_gpio; + indio_dev->dev.parent = &client->dev; + indio_dev->info = &ak8975_info; + indio_dev->modes = INDIO_DIRECT_MODE; - data->indio_dev->dev.parent = &client->dev; - data->indio_dev->info = &ak8975_info; - data->indio_dev->dev_data = (void *)(data); - data->indio_dev->modes = INDIO_DIRECT_MODE; - - err = iio_device_register(data->indio_dev); + err = iio_device_register(indio_dev); if (err < 0) goto exit_free_iio; return 0; exit_free_iio: - iio_free_device(data->indio_dev); + iio_free_device(indio_dev); exit_gpio: - if (data->eoc_gpio) - gpio_free(data->eoc_gpio); -exit_free: - kfree(data); + if (eoc_gpio) + gpio_free(eoc_gpio); exit: return err; } static int ak8975_remove(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); + int eoc_gpio = data->eoc_gpio; - iio_device_unregister(data->indio_dev); - iio_free_device(data->indio_dev); + iio_device_unregister(indio_dev); + iio_free_device(indio_dev); - if (data->eoc_gpio) - gpio_free(data->eoc_gpio); - - kfree(data); + if (eoc_gpio) + gpio_free(eoc_gpio); return 0; }