| .. | .. |
|---|
| 1 | | -/** |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 2 | +/* |
|---|
| 2 | 3 | * Copyright (c) 2011 Jonathan Cameron |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 5 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 6 | | - * the Free Software Foundation. |
|---|
| 7 | 4 | * |
|---|
| 8 | 5 | * A reference industrial I/O driver to illustrate the functionality available. |
|---|
| 9 | 6 | * |
|---|
| .. | .. |
|---|
| 556 | 553 | |
|---|
| 557 | 554 | /** |
|---|
| 558 | 555 | * iio_dummy_probe() - device instance probe |
|---|
| 559 | | - * @index: an id number for this instance. |
|---|
| 556 | + * @name: name of this instance. |
|---|
| 560 | 557 | * |
|---|
| 561 | 558 | * Arguments are bus type specific. |
|---|
| 562 | 559 | * I2C: iio_dummy_probe(struct i2c_client *client, |
|---|
| .. | .. |
|---|
| 569 | 566 | struct iio_dev *indio_dev; |
|---|
| 570 | 567 | struct iio_dummy_state *st; |
|---|
| 571 | 568 | struct iio_sw_device *swd; |
|---|
| 569 | + struct device *parent = NULL; |
|---|
| 570 | + |
|---|
| 571 | + /* |
|---|
| 572 | + * With hardware: Set the parent device. |
|---|
| 573 | + * parent = &spi->dev; |
|---|
| 574 | + * parent = &client->dev; |
|---|
| 575 | + */ |
|---|
| 572 | 576 | |
|---|
| 573 | 577 | swd = kzalloc(sizeof(*swd), GFP_KERNEL); |
|---|
| 574 | | - if (!swd) { |
|---|
| 575 | | - ret = -ENOMEM; |
|---|
| 576 | | - goto error_kzalloc; |
|---|
| 577 | | - } |
|---|
| 578 | + if (!swd) |
|---|
| 579 | + return ERR_PTR(-ENOMEM); |
|---|
| 580 | + |
|---|
| 578 | 581 | /* |
|---|
| 579 | 582 | * Allocate an IIO device. |
|---|
| 580 | 583 | * |
|---|
| .. | .. |
|---|
| 583 | 586 | * It also has a region (accessed by iio_priv() |
|---|
| 584 | 587 | * for chip specific state information. |
|---|
| 585 | 588 | */ |
|---|
| 586 | | - indio_dev = iio_device_alloc(sizeof(*st)); |
|---|
| 589 | + indio_dev = iio_device_alloc(parent, sizeof(*st)); |
|---|
| 587 | 590 | if (!indio_dev) { |
|---|
| 588 | 591 | ret = -ENOMEM; |
|---|
| 589 | | - goto error_ret; |
|---|
| 592 | + goto error_free_swd; |
|---|
| 590 | 593 | } |
|---|
| 591 | 594 | |
|---|
| 592 | 595 | st = iio_priv(indio_dev); |
|---|
| 593 | 596 | mutex_init(&st->lock); |
|---|
| 594 | 597 | |
|---|
| 595 | 598 | iio_dummy_init_device(indio_dev); |
|---|
| 596 | | - /* |
|---|
| 597 | | - * With hardware: Set the parent device. |
|---|
| 598 | | - * indio_dev->dev.parent = &spi->dev; |
|---|
| 599 | | - * indio_dev->dev.parent = &client->dev; |
|---|
| 600 | | - */ |
|---|
| 601 | 599 | |
|---|
| 602 | 600 | /* |
|---|
| 603 | 601 | * Make the iio_dev struct available to remove function. |
|---|
| .. | .. |
|---|
| 617 | 615 | * indio_dev->name = spi_get_device_id(spi)->name; |
|---|
| 618 | 616 | */ |
|---|
| 619 | 617 | indio_dev->name = kstrdup(name, GFP_KERNEL); |
|---|
| 618 | + if (!indio_dev->name) { |
|---|
| 619 | + ret = -ENOMEM; |
|---|
| 620 | + goto error_free_device; |
|---|
| 621 | + } |
|---|
| 620 | 622 | |
|---|
| 621 | 623 | /* Provide description of available channels */ |
|---|
| 622 | 624 | indio_dev->channels = iio_dummy_channels; |
|---|
| .. | .. |
|---|
| 633 | 635 | |
|---|
| 634 | 636 | ret = iio_simple_dummy_events_register(indio_dev); |
|---|
| 635 | 637 | if (ret < 0) |
|---|
| 636 | | - goto error_free_device; |
|---|
| 638 | + goto error_free_name; |
|---|
| 637 | 639 | |
|---|
| 638 | 640 | ret = iio_simple_dummy_configure_buffer(indio_dev); |
|---|
| 639 | 641 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 650 | 652 | iio_simple_dummy_unconfigure_buffer(indio_dev); |
|---|
| 651 | 653 | error_unregister_events: |
|---|
| 652 | 654 | iio_simple_dummy_events_unregister(indio_dev); |
|---|
| 655 | +error_free_name: |
|---|
| 656 | + kfree(indio_dev->name); |
|---|
| 653 | 657 | error_free_device: |
|---|
| 654 | 658 | iio_device_free(indio_dev); |
|---|
| 655 | | -error_ret: |
|---|
| 659 | +error_free_swd: |
|---|
| 656 | 660 | kfree(swd); |
|---|
| 657 | | -error_kzalloc: |
|---|
| 658 | 661 | return ERR_PTR(ret); |
|---|
| 659 | 662 | } |
|---|
| 660 | 663 | |
|---|
| .. | .. |
|---|
| 690 | 693 | |
|---|
| 691 | 694 | return 0; |
|---|
| 692 | 695 | } |
|---|
| 693 | | -/** |
|---|
| 696 | + |
|---|
| 697 | +/* |
|---|
| 694 | 698 | * module_iio_sw_device_driver() - device driver registration |
|---|
| 695 | 699 | * |
|---|
| 696 | 700 | * Varies depending on bus type of the device. As there is no device |
|---|
| 697 | 701 | * here, call probe directly. For information on device registration |
|---|
| 698 | 702 | * i2c: |
|---|
| 699 | | - * Documentation/i2c/writing-clients |
|---|
| 703 | + * Documentation/i2c/writing-clients.rst |
|---|
| 700 | 704 | * spi: |
|---|
| 701 | | - * Documentation/spi/spi-summary |
|---|
| 705 | + * Documentation/spi/spi-summary.rst |
|---|
| 702 | 706 | */ |
|---|
| 703 | 707 | static const struct iio_sw_device_ops iio_dummy_device_ops = { |
|---|
| 704 | 708 | .probe = iio_dummy_probe, |
|---|