Commit 452204ae531f236696d69966d0ff2f5ca0ef02f7

Authored by Sachin Kamat
Committed by Jonathan Cameron
1 parent 297c8876d9

iio: imu: inv_mpu6050: Use devm_iio_device_alloc

Using devm_iio_device_alloc makes code simpler. While at
it include missing iio.h header file and do some cleanup.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

Showing 1 changed file with 10 additions and 17 deletions Side-by-side Diff

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
... ... @@ -23,6 +23,7 @@
23 23 #include <linux/interrupt.h>
24 24 #include <linux/kfifo.h>
25 25 #include <linux/spinlock.h>
  26 +#include <linux/iio/iio.h>
26 27 #include "inv_mpu_iio.h"
27 28  
28 29 /*
29 30  
... ... @@ -663,16 +664,13 @@
663 664 int result;
664 665  
665 666 if (!i2c_check_functionality(client->adapter,
666   - I2C_FUNC_SMBUS_I2C_BLOCK)) {
  667 + I2C_FUNC_SMBUS_I2C_BLOCK))
  668 + return -ENOSYS;
667 669  
668   - result = -ENOSYS;
669   - goto out_no_free;
670   - }
671   - indio_dev = iio_device_alloc(sizeof(*st));
672   - if (indio_dev == NULL) {
673   - result = -ENOMEM;
674   - goto out_no_free;
675   - }
  670 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
  671 + if (!indio_dev)
  672 + return -ENOMEM;
  673 +
676 674 st = iio_priv(indio_dev);
677 675 st->client = client;
678 676 st->plat_data = *(struct inv_mpu6050_platform_data
679 677  
... ... @@ -680,13 +678,13 @@
680 678 /* power is turned on inside check chip type*/
681 679 result = inv_check_and_setup_chip(st, id);
682 680 if (result)
683   - goto out_free;
  681 + return result;
684 682  
685 683 result = inv_mpu6050_init_config(indio_dev);
686 684 if (result) {
687 685 dev_err(&client->dev,
688 686 "Could not initialize device.\n");
689   - goto out_free;
  687 + return result;
690 688 }
691 689  
692 690 i2c_set_clientdata(client, indio_dev);
... ... @@ -705,7 +703,7 @@
705 703 if (result) {
706 704 dev_err(&st->client->dev, "configure buffer fail %d\n",
707 705 result);
708   - goto out_free;
  706 + return result;
709 707 }
710 708 result = inv_mpu6050_probe_trigger(indio_dev);
711 709 if (result) {
... ... @@ -727,10 +725,6 @@
727 725 inv_mpu6050_remove_trigger(st);
728 726 out_unreg_ring:
729 727 iio_triggered_buffer_cleanup(indio_dev);
730   -out_free:
731   - iio_device_free(indio_dev);
732   -out_no_free:
733   -
734 728 return result;
735 729 }
736 730  
... ... @@ -742,7 +736,6 @@
742 736 iio_device_unregister(indio_dev);
743 737 inv_mpu6050_remove_trigger(st);
744 738 iio_triggered_buffer_cleanup(indio_dev);
745   - iio_device_free(indio_dev);
746 739  
747 740 return 0;
748 741 }