int ade7854_probe(struct iio_dev *indio_dev, struct device *dev) { int ret; struct ade7854_state *st = iio_priv(indio_dev); /* setup the industrialio driver allocated elements */ mutex_init(&st->buf_lock); indio_dev->dev.parent = dev; indio_dev->info = &ade7854_info; indio_dev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(indio_dev); if (ret) goto error_free_dev; /* Get the device into a sane initial state */ ret = ade7854_initial_setup(indio_dev); if (ret) goto error_unreg_dev; return 0; error_unreg_dev: iio_device_unregister(indio_dev); error_free_dev: iio_device_free(indio_dev); return ret; }
int ade7854_probe(struct ade7854_state *st, struct device *dev) { int ret; /* Allocate the comms buffers */ st->rx = kzalloc(sizeof(*st->rx)*ADE7854_MAX_RX, GFP_KERNEL); if (st->rx == NULL) { ret = -ENOMEM; goto error_free_st; } st->tx = kzalloc(sizeof(*st->tx)*ADE7854_MAX_TX, GFP_KERNEL); if (st->tx == NULL) { ret = -ENOMEM; goto error_free_rx; } mutex_init(&st->buf_lock); /* setup the industrialio driver allocated elements */ st->indio_dev = iio_allocate_device(); if (st->indio_dev == NULL) { ret = -ENOMEM; goto error_free_tx; } st->indio_dev->dev.parent = dev; st->indio_dev->attrs = &ade7854_attribute_group; st->indio_dev->dev_data = (void *)(st); st->indio_dev->driver_module = THIS_MODULE; st->indio_dev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(st->indio_dev); if (ret) goto error_free_dev; /* Get the device into a sane initial state */ ret = ade7854_initial_setup(st); if (ret) goto error_unreg_dev; return 0; error_unreg_dev: iio_device_unregister(st->indio_dev); 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); return ret; }