All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: greg@kroah.com
Cc: linux-iio@vger.kernel.org, Jonathan Cameron <jic23@cam.ac.uk>
Subject: [PATCH 21/54] staging:iio:adc:ad7816: allocate chip state with iio_dev and use iio_priv to access.
Date: Mon, 27 Jun 2011 11:04:31 +0100	[thread overview]
Message-ID: <1309169104-22139-22-git-send-email-jic23@cam.ac.uk> (raw)
In-Reply-To: <1309169104-22139-1-git-send-email-jic23@cam.ac.uk>

Again, get rid of unwanted iio_dev pointer in state.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
---
 drivers/staging/iio/adc/ad7816.c |   74 +++++++++++++++++---------------------
 1 files changed, 33 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 11379e4..0c84217 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -43,7 +43,6 @@
 
 struct ad7816_chip_info {
 	struct spi_device *spi_dev;
-	struct iio_dev *indio_dev;
 	u16 rdwr_pin;
 	u16 convert_pin;
 	u16 busy_pin;
@@ -113,7 +112,7 @@ static ssize_t ad7816_show_mode(struct device *dev,
 		char *buf)
 {
 	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7816_chip_info *chip = dev_info->dev_data;
+	struct ad7816_chip_info *chip = iio_priv(dev_info);
 
 	if (chip->mode)
 		return sprintf(buf, "power-save\n");
@@ -127,7 +126,7 @@ static ssize_t ad7816_store_mode(struct device *dev,
 		size_t len)
 {
 	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7816_chip_info *chip = dev_info->dev_data;
+	struct ad7816_chip_info *chip = iio_priv(dev_info);
 
 	if (strcmp(buf, "full")) {
 		gpio_set_value(chip->rdwr_pin, 1);
@@ -159,7 +158,7 @@ static ssize_t ad7816_show_channel(struct device *dev,
 		char *buf)
 {
 	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7816_chip_info *chip = dev_info->dev_data;
+	struct ad7816_chip_info *chip = iio_priv(dev_info);
 
 	return sprintf(buf, "%d\n", chip->channel_id);
 }
@@ -170,7 +169,7 @@ static ssize_t ad7816_store_channel(struct device *dev,
 		size_t len)
 {
 	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7816_chip_info *chip = dev_info->dev_data;
+	struct ad7816_chip_info *chip = iio_priv(dev_info);
 	unsigned long data;
 	int ret;
 
@@ -208,7 +207,7 @@ static ssize_t ad7816_show_value(struct device *dev,
 		char *buf)
 {
 	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7816_chip_info *chip = dev_info->dev_data;
+	struct ad7816_chip_info *chip = iio_priv(dev_info);
 	u16 data;
 	s8 value;
 	int ret;
@@ -265,7 +264,7 @@ static ssize_t ad7816_show_oti(struct device *dev,
 		char *buf)
 {
 	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7816_chip_info *chip = dev_info->dev_data;
+	struct ad7816_chip_info *chip = iio_priv(dev_info);
 	int value;
 
 	if (chip->channel_id > AD7816_CS_MAX) {
@@ -286,7 +285,7 @@ static inline ssize_t ad7816_set_oti(struct device *dev,
 		size_t len)
 {
 	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct ad7816_chip_info *chip = dev_info->dev_data;
+	struct ad7816_chip_info *chip = iio_priv(dev_info);
 	long value;
 	u8 data;
 	int ret;
@@ -345,6 +344,7 @@ static const struct iio_info ad7816_info = {
 static int __devinit ad7816_probe(struct spi_device *spi_dev)
 {
 	struct ad7816_chip_info *chip;
+	struct iio_dev *indio_dev;
 	unsigned short *pins = spi_dev->dev.platform_data;
 	int ret = 0;
 	int i;
@@ -354,13 +354,14 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev)
 		return -EINVAL;
 	}
 
-	chip = kzalloc(sizeof(struct ad7816_chip_info), GFP_KERNEL);
-
-	if (chip == NULL)
-		return -ENOMEM;
-
+	indio_dev = iio_allocate_device(sizeof(*chip));
+	if (indio_dev == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+	chip = iio_priv(indio_dev);
 	/* this is only used for device removal purposes */
-	dev_set_drvdata(&spi_dev->dev, chip);
+	dev_set_drvdata(&spi_dev->dev, indio_dev);
 
 	chip->spi_dev = spi_dev;
 	for (i = 0; i <= AD7816_CS_MAX; i++)
@@ -373,7 +374,7 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev)
 	if (ret) {
 		dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
 			chip->rdwr_pin);
-		goto error_free_chip;
+		goto error_free_device;
 	}
 	gpio_direction_input(chip->rdwr_pin);
 	ret = gpio_request(chip->convert_pin, spi_get_device_id(spi_dev)->name);
@@ -391,20 +392,14 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev)
 	}
 	gpio_direction_input(chip->busy_pin);
 
-	chip->indio_dev = iio_allocate_device(0);
-	if (chip->indio_dev == NULL) {
-		ret = -ENOMEM;
-		goto error_free_gpio;
-	}
-	chip->indio_dev->name = spi_get_device_id(spi_dev)->name;
-	chip->indio_dev->dev.parent = &spi_dev->dev;
-	chip->indio_dev->info = &ad7816_info;
-	chip->indio_dev->dev_data = (void *)chip;
-	chip->indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->name = spi_get_device_id(spi_dev)->name;
+	indio_dev->dev.parent = &spi_dev->dev;
+	indio_dev->info = &ad7816_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	ret = iio_device_register(chip->indio_dev);
+	ret = iio_device_register(indio_dev);
 	if (ret)
-		goto error_free_dev;
+		goto error_free_gpio;
 
 	if (spi_dev->irq) {
 		/* Only low trigger is supported in ad7816/7/8 */
@@ -412,47 +407,44 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev)
 					   NULL,
 					   &ad7816_event_handler,
 					   IRQF_TRIGGER_LOW,
-					   chip->indio_dev->name,
-					   chip->indio_dev);
+					   indio_dev->name,
+					   indio_dev);
 		if (ret)
 			goto error_unreg_dev;
 	}
 
 	dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
-			 chip->indio_dev->name);
+			 indio_dev->name);
 
 	return 0;
 
 error_unreg_dev:
-	iio_device_unregister(chip->indio_dev);
-error_free_dev:
-	iio_free_device(chip->indio_dev);
+	iio_device_unregister(indio_dev);
 error_free_gpio:
 	gpio_free(chip->busy_pin);
 error_free_gpio_convert:
 	gpio_free(chip->convert_pin);
 error_free_gpio_rdwr:
 	gpio_free(chip->rdwr_pin);
-error_free_chip:
-	kfree(chip);
-
+error_free_device:
+	iio_free_device(indio_dev);
+error_ret:
 	return ret;
 }
 
 static int __devexit ad7816_remove(struct spi_device *spi_dev)
 {
-	struct ad7816_chip_info *chip = dev_get_drvdata(&spi_dev->dev);
-	struct iio_dev *indio_dev = chip->indio_dev;
+	struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev);
+	struct ad7816_chip_info *chip = iio_priv(indio_dev);
 
 	dev_set_drvdata(&spi_dev->dev, NULL);
 	if (spi_dev->irq)
 		free_irq(spi_dev->irq, indio_dev);
-	iio_device_unregister(indio_dev);
-	iio_free_device(chip->indio_dev);
 	gpio_free(chip->busy_pin);
 	gpio_free(chip->convert_pin);
 	gpio_free(chip->rdwr_pin);
-	kfree(chip);
+	iio_device_unregister(indio_dev);
+	iio_free_device(indio_dev);
 
 	return 0;
 }
-- 
1.7.3.4

  parent reply	other threads:[~2011-06-27 10:04 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-27 10:04 [PATCH 00/54] staging:iio: driving towards removal of dev_data pointer Jonathan Cameron
2011-06-27 10:04 ` [PATCH 01/54] iio: industrialio-core: introduce IIO_VAL_INT_PLUS_NANO Jonathan Cameron
2011-06-27 10:04 ` [PATCH 02/54] iio: trigger: Move declaration of struct iio_poll_func to avoid warnings Jonathan Cameron
2011-06-27 10:04 ` [PATCH 03/54] iio: trigger: Add filter callback Jonathan Cameron
2011-06-27 10:04 ` [PATCH 04/54] iio: industrialio-core: iio_write_channel_info accept IIO_VAL_INT_PLUS_NANO Jonathan Cameron
2011-06-27 10:04 ` [PATCH 05/54] IIO: ADC: New driver for AD7792/AD7793 3 Channel SPI ADC Jonathan Cameron
2011-06-27 10:04 ` [PATCH 06/54] staging:iio:accel:adis16203 move buffers into state and use iio_priv to avoid allocating state separately Jonathan Cameron
2011-06-27 10:04 ` [PATCH 07/54] staging:iio:accel:adis16204 allocate tx and rx in state plus state via iio_priv Jonathan Cameron
2011-06-27 10:04 ` [PATCH 08/54] staging:iio:accel:adis16209 " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 09/54] staging:iio:accel:adis16240 " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 10/54] staging:iio:accel:adis16220 " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 11/54] staging:iio:accel:sca3000: allocate state in iio_dev and use iio_priv to access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 12/54] staging:iio:accel:kxsd9: allocate state with " Jonathan Cameron
2011-06-27 11:19   ` Jonathan Cameron
2011-06-27 10:04 ` [PATCH 13/54] staging:iio:adc:ad7476 " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 14/54] staging:iio:adc:ad7887 clear out last few uses of iio_dev->dev_data Jonathan Cameron
2011-06-27 10:04 ` [PATCH 15/54] staging:iio:adc:ad799x " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 16/54] staging:iio:adc:ad7150: allocate chip state with iio_dev and use iio_priv to access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 17/54] staging:iio:adc:ad7152: allocate chip state with iio_dev and use iio_priv for access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 18/54] staging:iio:adc:ad7291: " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 19/54] staging:iio:adc:ad7314 allocate chip state with iio_dev and use iio_priv to access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 20/54] staging:iio:adc:ad7745 " Jonathan Cameron
2011-06-27 10:04 ` Jonathan Cameron [this message]
2011-06-27 10:04 ` [PATCH 22/54] staging:iio:adc:adt75: allocate chip state with iio_dev and cleanup some function calls Jonathan Cameron
2011-06-27 10:04 ` [PATCH 23/54] staging:iio:adc:adt7310: allocate chip state with iio_dev and use iio_priv for access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 24/54] staging:iio:addac:adt7316: allocate chip state with iio_dev and use iio_priv to access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 25/54] staging:iio:dac:ad5624r: allocate chip state with iio_dev and use iio_priv for access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 26/54] staging:iio:dac:ad5504: " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 27/54] staging:iio:dac:ad5446: " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 28/54] staging:iio:dac:ad5791: " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 29/54] staging:iio:dac:max517: allocate chip state with iio_dev and use iio_priv to access it Jonathan Cameron
2011-06-27 10:04 ` [PATCH 30/54] staging:iio:dds:ad5930 Fix attr group location + allocate state with iio_dev Jonathan Cameron
2011-06-27 10:04 ` [PATCH 31/54] staging:iio:dds:ad9832: allocate chip state with iio_dev and use iio_priv to access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 32/54] staging:iio:ad9834: " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 33/54] staging:iio:dds:ad9850 allocate chip state with iio_dev + fix name of attr group Jonathan Cameron
2011-06-27 10:04 ` [PATCH 34/54] staging:iio:dds:ad9810: allocate chip state with iio_dev and use iio_priv for access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 35/54] staging:iio:dds:ad9910: allocate chip state with iio_dev Jonathan Cameron
2011-06-27 10:04 ` [PATCH 36/54] staging:iio:dds:ad9951: " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 37/54] staging:iio:gyro:adis16060 " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 38/54] staging:iio:gyro:adis16080: " Jonathan Cameron
2011-06-27 10:04 ` [PATCH 39/54] staging:iio:gyro:adis16130: allocate chip state with iio_dev and use iio_priv to access it Jonathan Cameron
2011-06-27 10:04 ` [PATCH 40/54] staging:iio:gyro:adis16260: allocate chip state with iio_dev and use iio_priv to access Jonathan Cameron
2011-06-27 10:04 ` [PATCH 41/54] staging:iio:gyro:adxrs450: allocate chip state with iio_dev Jonathan Cameron
2011-06-27 10:04 ` [PATCH 42/54] staging:iio:meter:ade7753 allocate chip state with iio_dev; allocate buffers within state Jonathan Cameron
2011-06-27 10:04 ` [PATCH 43/54] staging:iio:meter:ade7754: allocate state with iio_dev and buffers in state Jonathan Cameron
2011-06-27 10:04 ` [PATCH 44/54] staging:iio:meter:ade7854: Allocate buffers in state and state with iio_dev Jonathan Cameron
2011-06-27 10:04 ` [PATCH 45/54] staging:iio:resolver:ad2s1210 general driver cleanup Jonathan Cameron
2011-06-27 10:04 ` [PATCH 46/54] staging:iio:resolver:ad2s120x cleanup Jonathan Cameron
2011-06-27 10:04 ` [PATCH 47/54] staging:iio:resolver:ad2s90 general cleanup Jonathan Cameron
2011-06-27 10:04 ` [PATCH 48/54] staging:iio:magnetometer:ak8975: allocate chip state with iio_dev Jonathan Cameron
2011-06-27 10:04 ` [PATCH 49/54] staging:iio:meter:ade7759: allocate " Jonathan Cameron
2011-06-27 10:05 ` [PATCH 50/54] staging:iio:magnetometer:hmc5843: allocate device " Jonathan Cameron
2011-06-27 10:05 ` [PATCH 51/54] staging:iio:light:isl29018: " Jonathan Cameron
2011-06-27 10:05 ` [PATCH 52/54] staging:iio:accel:adis16201 general cleanup, move to iio_priv and buffers in adis16201_state Jonathan Cameron
2011-06-27 10:05 ` [PATCH 53/54] staging: IIO corrected the spelling in iio-trig-gpio Jonathan Cameron
2011-06-27 10:05 ` [PATCH 54/54] staging:iio:accel:kxsd9 replace kmallocs in power_up with use of already allocated buffer Jonathan Cameron
2011-06-27 11:19 ` [PATCH 00/54] staging:iio: driving towards removal of dev_data pointer Jonathan Cameron
2011-06-27 12:03   ` Jonathan Cameron

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=1309169104-22139-22-git-send-email-jic23@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --cc=greg@kroah.com \
    --cc=linux-iio@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.