Message ID | 1617881896-3164-3-git-send-email-yangyicong@hisilicon.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Simplify codes with devm_add_action_or_reset | expand |
On Thu, 8 Apr 2021 19:38:11 +0800 Yicong Yang <yangyicong@hisilicon.com> wrote: > Use devm_add_action_or_reset() instead of devres_alloc() and > devres_add(), which works the same. This will simplify the > code. There is no functional changes. > > Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Tiny amount of fuzz, but nothing that mattered. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at. Thanks, Jonathan > --- > drivers/iio/buffer/industrialio-buffer-dmaengine.c | 22 +++++++++------------- > 1 file changed, 9 insertions(+), 13 deletions(-) > > diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c > index b0cb9a3..9ecc03f 100644 > --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c > +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c > @@ -228,9 +228,9 @@ static void iio_dmaengine_buffer_free(struct iio_buffer *buffer) > iio_buffer_put(buffer); > } > > -static void __devm_iio_dmaengine_buffer_free(struct device *dev, void *res) > +static void __devm_iio_dmaengine_buffer_free(void *buffer) > { > - iio_dmaengine_buffer_free(*(struct iio_buffer **)res); > + iio_dmaengine_buffer_free(buffer); > } > > /** > @@ -247,21 +247,17 @@ static void __devm_iio_dmaengine_buffer_free(struct device *dev, void *res) > struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, > const char *channel) > { > - struct iio_buffer **bufferp, *buffer; > - > - bufferp = devres_alloc(__devm_iio_dmaengine_buffer_free, > - sizeof(*bufferp), GFP_KERNEL); > - if (!bufferp) > - return ERR_PTR(-ENOMEM); > + struct iio_buffer *buffer; > + int ret; > > buffer = iio_dmaengine_buffer_alloc(dev, channel); > - if (IS_ERR(buffer)) { > - devres_free(bufferp); > + if (IS_ERR(buffer)) > return buffer; > - } > > - *bufferp = buffer; > - devres_add(dev, bufferp); > + ret = devm_add_action_or_reset(dev, __devm_iio_dmaengine_buffer_free, > + buffer); > + if (ret) > + return ERR_PTR(ret); > > return buffer; > }
diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c index b0cb9a3..9ecc03f 100644 --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c @@ -228,9 +228,9 @@ static void iio_dmaengine_buffer_free(struct iio_buffer *buffer) iio_buffer_put(buffer); } -static void __devm_iio_dmaengine_buffer_free(struct device *dev, void *res) +static void __devm_iio_dmaengine_buffer_free(void *buffer) { - iio_dmaengine_buffer_free(*(struct iio_buffer **)res); + iio_dmaengine_buffer_free(buffer); } /** @@ -247,21 +247,17 @@ static void __devm_iio_dmaengine_buffer_free(struct device *dev, void *res) struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, const char *channel) { - struct iio_buffer **bufferp, *buffer; - - bufferp = devres_alloc(__devm_iio_dmaengine_buffer_free, - sizeof(*bufferp), GFP_KERNEL); - if (!bufferp) - return ERR_PTR(-ENOMEM); + struct iio_buffer *buffer; + int ret; buffer = iio_dmaengine_buffer_alloc(dev, channel); - if (IS_ERR(buffer)) { - devres_free(bufferp); + if (IS_ERR(buffer)) return buffer; - } - *bufferp = buffer; - devres_add(dev, bufferp); + ret = devm_add_action_or_reset(dev, __devm_iio_dmaengine_buffer_free, + buffer); + if (ret) + return ERR_PTR(ret); return buffer; }
Use devm_add_action_or_reset() instead of devres_alloc() and devres_add(), which works the same. This will simplify the code. There is no functional changes. Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> --- drivers/iio/buffer/industrialio-buffer-dmaengine.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)