From: Jonathan Cameron <jic23@cam.ac.uk>
To: Jonathan Cameron <jic23@cam.ac.uk>
Cc: greg@kroah.com, linux-iio@vger.kernel.org
Subject: Re: [PATCH 12/54] staging:iio:accel:kxsd9: allocate state with iio_dev and use iio_priv to access.
Date: Mon, 27 Jun 2011 12:19:47 +0100 [thread overview]
Message-ID: <4E086753.9070105@cam.ac.uk> (raw)
In-Reply-To: <1309169104-22139-13-git-send-email-jic23@cam.ac.uk>
And here is the clanger I mentioned. Always a good idea to
actually allocate the storage you are using...
> struct kxsd9_state *st;
> int ret = 0;
>
> - st = kzalloc(sizeof(*st), GFP_KERNEL);
> - if (st == NULL) {
> + indio_dev = iio_allocate_device(0);
GAH. Going to have to check this set more thoroughly.
> + if (indio_dev == NULL) {
> ret = -ENOMEM;
> goto error_ret;
> }
> - spi_set_drvdata(spi, st);
> -
> - st->rx = kmalloc(sizeof(*st->rx)*KXSD9_STATE_RX_SIZE,
> - GFP_KERNEL);
> - if (st->rx == NULL) {
> - ret = -ENOMEM;
> - goto error_free_st;
> - }
> - st->tx = kmalloc(sizeof(*st->tx)*KXSD9_STATE_TX_SIZE,
> - GFP_KERNEL);
> - if (st->tx == NULL) {
> - ret = -ENOMEM;
> - goto error_free_rx;
> - }
> + st = iio_priv(indio_dev);
> + spi_set_drvdata(spi, indio_dev);
>
> st->us = spi;
> mutex_init(&st->buf_lock);
> - st->indio_dev = iio_allocate_device(0);
> - if (st->indio_dev == NULL) {
> - ret = -ENOMEM;
> - goto error_free_tx;
> - }
> - st->indio_dev->dev.parent = &spi->dev;
> - st->indio_dev->info = &kxsd9_info;
> - st->indio_dev->dev_data = (void *)(st);
> - st->indio_dev->modes = INDIO_DIRECT_MODE;
>
> - ret = iio_device_register(st->indio_dev);
> + indio_dev->dev.parent = &spi->dev;
> + indio_dev->info = &kxsd9_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> +
> + ret = iio_device_register(indio_dev);
> if (ret)
> goto error_free_dev;
>
> @@ -355,25 +336,14 @@ static int __devinit kxsd9_probe(struct spi_device *spi)
> return 0;
>
> error_free_dev:
> - iio_free_device(st->indio_dev);
> -error_free_tx:
> - kfree(st->tx);
> -error_free_rx:
> - kfree(st->rx);
> -error_free_st:
> - kfree(st);
> + iio_free_device(indio_dev);
> error_ret:
> return ret;
> }
>
> static int __devexit kxsd9_remove(struct spi_device *spi)
> {
> - struct kxsd9_state *st = spi_get_drvdata(spi);
> -
> - iio_device_unregister(st->indio_dev);
> - kfree(st->tx);
> - kfree(st->rx);
> - kfree(st);
> + iio_device_unregister(spi_get_drvdata(spi));
>
> return 0;
> }
next prev parent reply other threads:[~2011-06-27 11:19 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 [this message]
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 ` [PATCH 21/54] staging:iio:adc:ad7816: " Jonathan Cameron
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=4E086753.9070105@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.