Commit a845a3aab8a925f675ca8520435b1218b6198a26

Authored by Beomho Seo
Committed by Jonathan Cameron
1 parent cfcd185e70

iio: magnetometer: ak8975: Use devm_* APIs

This patch use devm_* APIs make driver simpler.

Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

Showing 1 changed file with 14 additions and 44 deletions Side-by-side Diff

drivers/iio/magnetometer/ak8975.c
... ... @@ -165,7 +165,7 @@
165 165 else
166 166 irq = gpio_to_irq(data->eoc_gpio);
167 167  
168   - rc = request_irq(irq, ak8975_irq_handler,
  168 + rc = devm_request_irq(&client->dev, irq, ak8975_irq_handler,
169 169 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
170 170 dev_name(&client->dev), data);
171 171 if (rc < 0) {
172 172  
173 173  
... ... @@ -520,21 +520,21 @@
520 520 /* We may not have a GPIO based IRQ to scan, that is fine, we will
521 521 poll if so */
522 522 if (gpio_is_valid(eoc_gpio)) {
523   - err = gpio_request_one(eoc_gpio, GPIOF_IN, "ak_8975");
  523 + err = devm_gpio_request_one(&client->dev, eoc_gpio,
  524 + GPIOF_IN, "ak_8975");
524 525 if (err < 0) {
525 526 dev_err(&client->dev,
526 527 "failed to request GPIO %d, error %d\n",
527 528 eoc_gpio, err);
528   - goto exit;
  529 + return err;
529 530 }
530 531 }
531 532  
532 533 /* Register with IIO */
533   - indio_dev = iio_device_alloc(sizeof(*data));
534   - if (indio_dev == NULL) {
535   - err = -ENOMEM;
536   - goto exit_gpio;
537   - }
  534 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
  535 + if (indio_dev == NULL)
  536 + return -ENOMEM;
  537 +
538 538 data = iio_priv(indio_dev);
539 539 i2c_set_clientdata(client, indio_dev);
540 540  
541 541  
... ... @@ -549,17 +549,16 @@
549 549 name = (char *) id->name;
550 550 } else if (ACPI_HANDLE(&client->dev))
551 551 name = ak8975_match_acpi_device(&client->dev, &data->chipset);
552   - else {
553   - err = -ENOSYS;
554   - goto exit_free_iio;
555   - }
  552 + else
  553 + return -ENOSYS;
  554 +
556 555 dev_dbg(&client->dev, "Asahi compass chip %s\n", name);
557 556  
558 557 /* Perform some basic start-of-day setup of the device. */
559 558 err = ak8975_setup(client);
560 559 if (err < 0) {
561 560 dev_err(&client->dev, "AK8975 initialization fails\n");
562   - goto exit_free_iio;
  561 + return err;
563 562 }
564 563  
565 564 data->client = client;
566 565  
567 566  
568 567  
... ... @@ -571,41 +570,13 @@
571 570 indio_dev->info = &ak8975_info;
572 571 indio_dev->modes = INDIO_DIRECT_MODE;
573 572 indio_dev->name = name;
574   - err = iio_device_register(indio_dev);
  573 + err = devm_iio_device_register(&client->dev, indio_dev);
575 574 if (err < 0)
576   - goto exit_free_iio;
  575 + return err;
577 576  
578 577 return 0;
579   -
580   -exit_free_iio:
581   - iio_device_free(indio_dev);
582   - if (data->eoc_irq)
583   - free_irq(data->eoc_irq, data);
584   -exit_gpio:
585   - if (gpio_is_valid(eoc_gpio))
586   - gpio_free(eoc_gpio);
587   -exit:
588   - return err;
589 578 }
590 579  
591   -static int ak8975_remove(struct i2c_client *client)
592   -{
593   - struct iio_dev *indio_dev = i2c_get_clientdata(client);
594   - struct ak8975_data *data = iio_priv(indio_dev);
595   -
596   - iio_device_unregister(indio_dev);
597   -
598   - if (data->eoc_irq)
599   - free_irq(data->eoc_irq, data);
600   -
601   - if (gpio_is_valid(data->eoc_gpio))
602   - gpio_free(data->eoc_gpio);
603   -
604   - iio_device_free(indio_dev);
605   -
606   - return 0;
607   -}
608   -
609 580 static const struct i2c_device_id ak8975_id[] = {
610 581 {"ak8975", AK8975},
611 582 {"ak8963", AK8963},
... ... @@ -628,7 +599,6 @@
628 599 .acpi_match_table = ACPI_PTR(ak_acpi_match),
629 600 },
630 601 .probe = ak8975_probe,
631   - .remove = ak8975_remove,
632 602 .id_table = ak8975_id,
633 603 };
634 604 module_i2c_driver(ak8975_driver);