hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/iio/adc/xilinx-xadc-core.c
....@@ -1,10 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Xilinx XADC driver
34 *
45 * Copyright 2013-2014 Analog Devices Inc.
5
- * Author: Lars-Peter Clauen <lars@metafoo.de>
6
- *
7
- * Licensed under the GPL-2.
6
+ * Author: Lars-Peter Clausen <lars@metafoo.de>
87 *
98 * Documentation for the parts can be found at:
109 * - XADC hardmacro: Xilinx UG480
....@@ -664,7 +663,7 @@
664663 mutex_lock(&xadc->mutex);
665664
666665 if (state) {
667
- /* Only one of the two triggers can be active at the a time. */
666
+ /* Only one of the two triggers can be active at a time. */
668667 if (xadc->trigger != NULL) {
669668 ret = -EBUSY;
670669 goto err_out;
....@@ -840,8 +839,6 @@
840839
841840 static const struct iio_buffer_setup_ops xadc_buffer_ops = {
842841 .preenable = &xadc_preenable,
843
- .postenable = &iio_triggered_buffer_postenable,
844
- .predisable = &iio_triggered_buffer_predisable,
845842 .postdisable = &xadc_postdisable,
846843 };
847844
....@@ -1095,6 +1092,7 @@
10951092 static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np,
10961093 unsigned int *conf)
10971094 {
1095
+ struct device *dev = indio_dev->dev.parent;
10981096 struct xadc *xadc = iio_priv(indio_dev);
10991097 struct iio_chan_spec *channels, *chan;
11001098 struct device_node *chan_node, *child;
....@@ -1139,7 +1137,8 @@
11391137 *conf |= XADC_CONF0_MUX | XADC_CONF0_CHAN(ext_mux_chan);
11401138 }
11411139
1142
- channels = kmemdup(xadc_channels, sizeof(xadc_channels), GFP_KERNEL);
1140
+ channels = devm_kmemdup(dev, xadc_channels,
1141
+ sizeof(xadc_channels), GFP_KERNEL);
11431142 if (!channels)
11441143 return -ENOMEM;
11451144
....@@ -1175,8 +1174,9 @@
11751174 of_node_put(chan_node);
11761175
11771176 indio_dev->num_channels = num_channels;
1178
- indio_dev->channels = krealloc(channels, sizeof(*channels) *
1179
- num_channels, GFP_KERNEL);
1177
+ indio_dev->channels = devm_krealloc(dev, channels,
1178
+ sizeof(*channels) * num_channels,
1179
+ GFP_KERNEL);
11801180 /* If we can't resize the channels array, just use the original */
11811181 if (!indio_dev->channels)
11821182 indio_dev->channels = channels;
....@@ -1189,7 +1189,6 @@
11891189 const struct of_device_id *id;
11901190 struct iio_dev *indio_dev;
11911191 unsigned int bipolar_mask;
1192
- struct resource *mem;
11931192 unsigned int conf0;
11941193 struct xadc *xadc;
11951194 int ret;
....@@ -1219,27 +1218,24 @@
12191218 spin_lock_init(&xadc->lock);
12201219 INIT_DELAYED_WORK(&xadc->zynq_unmask_work, xadc_zynq_unmask_worker);
12211220
1222
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1223
- xadc->base = devm_ioremap_resource(&pdev->dev, mem);
1221
+ xadc->base = devm_platform_ioremap_resource(pdev, 0);
12241222 if (IS_ERR(xadc->base))
12251223 return PTR_ERR(xadc->base);
12261224
1227
- indio_dev->dev.parent = &pdev->dev;
1228
- indio_dev->dev.of_node = pdev->dev.of_node;
12291225 indio_dev->name = "xadc";
12301226 indio_dev->modes = INDIO_DIRECT_MODE;
12311227 indio_dev->info = &xadc_info;
12321228
12331229 ret = xadc_parse_dt(indio_dev, pdev->dev.of_node, &conf0);
12341230 if (ret)
1235
- goto err_device_free;
1231
+ return ret;
12361232
12371233 if (xadc->ops->flags & XADC_FLAGS_BUFFERED) {
12381234 ret = iio_triggered_buffer_setup(indio_dev,
12391235 &iio_pollfunc_store_time, &xadc_trigger_handler,
12401236 &xadc_buffer_ops);
12411237 if (ret)
1242
- goto err_device_free;
1238
+ return ret;
12431239
12441240 xadc->convst_trigger = xadc_alloc_trigger(indio_dev, "convst");
12451241 if (IS_ERR(xadc->convst_trigger)) {
....@@ -1326,8 +1322,10 @@
13261322 xadc->threshold[i] = 0xffff;
13271323 else
13281324 xadc->threshold[i] = 0;
1329
- xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i),
1325
+ ret = xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i),
13301326 xadc->threshold[i]);
1327
+ if (ret)
1328
+ goto err_free_irq;
13311329 }
13321330
13331331 /* Go to non-buffered mode */
....@@ -1355,8 +1353,6 @@
13551353 err_triggered_buffer_cleanup:
13561354 if (xadc->ops->flags & XADC_FLAGS_BUFFERED)
13571355 iio_triggered_buffer_cleanup(indio_dev);
1358
-err_device_free:
1359
- kfree(indio_dev->channels);
13601356
13611357 return ret;
13621358 }
....@@ -1376,7 +1372,6 @@
13761372 cancel_delayed_work_sync(&xadc->zynq_unmask_work);
13771373 clk_disable_unprepare(xadc->clk);
13781374 kfree(xadc->data);
1379
- kfree(indio_dev->channels);
13801375
13811376 return 0;
13821377 }