hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/iio/dummy/iio_simple_dummy.c
....@@ -1,9 +1,6 @@
1
-/**
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/*
23 * 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.
74 *
85 * A reference industrial I/O driver to illustrate the functionality available.
96 *
....@@ -556,7 +553,7 @@
556553
557554 /**
558555 * iio_dummy_probe() - device instance probe
559
- * @index: an id number for this instance.
556
+ * @name: name of this instance.
560557 *
561558 * Arguments are bus type specific.
562559 * I2C: iio_dummy_probe(struct i2c_client *client,
....@@ -569,12 +566,18 @@
569566 struct iio_dev *indio_dev;
570567 struct iio_dummy_state *st;
571568 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
+ */
572576
573577 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
+
578581 /*
579582 * Allocate an IIO device.
580583 *
....@@ -583,21 +586,16 @@
583586 * It also has a region (accessed by iio_priv()
584587 * for chip specific state information.
585588 */
586
- indio_dev = iio_device_alloc(sizeof(*st));
589
+ indio_dev = iio_device_alloc(parent, sizeof(*st));
587590 if (!indio_dev) {
588591 ret = -ENOMEM;
589
- goto error_ret;
592
+ goto error_free_swd;
590593 }
591594
592595 st = iio_priv(indio_dev);
593596 mutex_init(&st->lock);
594597
595598 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
- */
601599
602600 /*
603601 * Make the iio_dev struct available to remove function.
....@@ -617,6 +615,10 @@
617615 * indio_dev->name = spi_get_device_id(spi)->name;
618616 */
619617 indio_dev->name = kstrdup(name, GFP_KERNEL);
618
+ if (!indio_dev->name) {
619
+ ret = -ENOMEM;
620
+ goto error_free_device;
621
+ }
620622
621623 /* Provide description of available channels */
622624 indio_dev->channels = iio_dummy_channels;
....@@ -633,7 +635,7 @@
633635
634636 ret = iio_simple_dummy_events_register(indio_dev);
635637 if (ret < 0)
636
- goto error_free_device;
638
+ goto error_free_name;
637639
638640 ret = iio_simple_dummy_configure_buffer(indio_dev);
639641 if (ret < 0)
....@@ -650,11 +652,12 @@
650652 iio_simple_dummy_unconfigure_buffer(indio_dev);
651653 error_unregister_events:
652654 iio_simple_dummy_events_unregister(indio_dev);
655
+error_free_name:
656
+ kfree(indio_dev->name);
653657 error_free_device:
654658 iio_device_free(indio_dev);
655
-error_ret:
659
+error_free_swd:
656660 kfree(swd);
657
-error_kzalloc:
658661 return ERR_PTR(ret);
659662 }
660663
....@@ -690,15 +693,16 @@
690693
691694 return 0;
692695 }
693
-/**
696
+
697
+/*
694698 * module_iio_sw_device_driver() - device driver registration
695699 *
696700 * Varies depending on bus type of the device. As there is no device
697701 * here, call probe directly. For information on device registration
698702 * i2c:
699
- * Documentation/i2c/writing-clients
703
+ * Documentation/i2c/writing-clients.rst
700704 * spi:
701
- * Documentation/spi/spi-summary
705
+ * Documentation/spi/spi-summary.rst
702706 */
703707 static const struct iio_sw_device_ops iio_dummy_device_ops = {
704708 .probe = iio_dummy_probe,