From: Bartosz Golaszewski Date: Mon, 24 Aug 2020 17:38:59 +0000 (+0200) Subject: iio: adc: xilinx-xadc: use devm_krealloc() X-Git-Tag: v5.15~2676^2~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=750628c79bb10ada3d404f576d476c3cef2da6fb;p=platform%2Fkernel%2Flinux-starfive.git iio: adc: xilinx-xadc: use devm_krealloc() Use the managed variant of krealloc() and shrink the code a bit. Signed-off-by: Bartosz Golaszewski Acked-by: Jonathan Cameron Link: https://lore.kernel.org/r/20200824173859.4910-4-brgl@bgdev.pl Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index d0b7ef2..f93c34f 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -1092,6 +1092,7 @@ MODULE_DEVICE_TABLE(of, xadc_of_match_table); static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, unsigned int *conf) { + struct device *dev = indio_dev->dev.parent; struct xadc *xadc = iio_priv(indio_dev); struct iio_chan_spec *channels, *chan; struct device_node *chan_node, *child; @@ -1136,7 +1137,8 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, *conf |= XADC_CONF0_MUX | XADC_CONF0_CHAN(ext_mux_chan); } - channels = kmemdup(xadc_channels, sizeof(xadc_channels), GFP_KERNEL); + channels = devm_kmemdup(dev, xadc_channels, + sizeof(xadc_channels), GFP_KERNEL); if (!channels) return -ENOMEM; @@ -1172,8 +1174,9 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, of_node_put(chan_node); indio_dev->num_channels = num_channels; - indio_dev->channels = krealloc(channels, sizeof(*channels) * - num_channels, GFP_KERNEL); + indio_dev->channels = devm_krealloc(dev, channels, + sizeof(*channels) * num_channels, + GFP_KERNEL); /* If we can't resize the channels array, just use the original */ if (!indio_dev->channels) indio_dev->channels = channels; @@ -1225,14 +1228,14 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_parse_dt(indio_dev, pdev->dev.of_node, &conf0); if (ret) - goto err_device_free; + return ret; if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, &xadc_trigger_handler, &xadc_buffer_ops); if (ret) - goto err_device_free; + return ret; xadc->convst_trigger = xadc_alloc_trigger(indio_dev, "convst"); if (IS_ERR(xadc->convst_trigger)) { @@ -1350,8 +1353,6 @@ err_free_convst_trigger: err_triggered_buffer_cleanup: if (xadc->ops->flags & XADC_FLAGS_BUFFERED) iio_triggered_buffer_cleanup(indio_dev); -err_device_free: - kfree(indio_dev->channels); return ret; } @@ -1371,7 +1372,6 @@ static int xadc_remove(struct platform_device *pdev) cancel_delayed_work_sync(&xadc->zynq_unmask_work); clk_disable_unprepare(xadc->clk); kfree(xadc->data); - kfree(indio_dev->channels); return 0; }