Message ID | 1617881896-3164-5-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:13 +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> > --- > drivers/iio/buffer/industrialio-triggered-buffer.c | 19 +++++-------------- > 1 file changed, 5 insertions(+), 14 deletions(-) > > diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c > index 92b8aea..63b4722 100644 > --- a/drivers/iio/buffer/industrialio-triggered-buffer.c > +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c > @@ -92,9 +92,9 @@ void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev) > } > EXPORT_SYMBOL(iio_triggered_buffer_cleanup); > > -static void devm_iio_triggered_buffer_clean(struct device *dev, void *res) > +static void devm_iio_triggered_buffer_clean(void *indio_dev) > { > - iio_triggered_buffer_cleanup(*(struct iio_dev **)res); > + iio_triggered_buffer_cleanup(indio_dev); > } > > int devm_iio_triggered_buffer_setup_ext(struct device *dev, > @@ -104,24 +104,15 @@ int devm_iio_triggered_buffer_setup_ext(struct device *dev, > const struct iio_buffer_setup_ops *ops, > const struct attribute **buffer_attrs) > { > - struct iio_dev **ptr; > int ret; > > - ptr = devres_alloc(devm_iio_triggered_buffer_clean, sizeof(*ptr), > - GFP_KERNEL); > - if (!ptr) > - return -ENOMEM; > - > - *ptr = indio_dev; > - > ret = iio_triggered_buffer_setup_ext(indio_dev, h, thread, ops, > buffer_attrs); > if (!ret) > - devres_add(dev, ptr); > - else > - devres_free(ptr); > + return ret; This looks inverted from what it should be. if (ret) return ret; return devm_add_action_or_reset()... > > - return ret; > + return devm_add_action_or_reset(dev, devm_iio_triggered_buffer_clean, > + indio_dev); > } > EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup_ext); >
On 2021/4/11 22:16, Jonathan Cameron wrote: > On Thu, 8 Apr 2021 19:38:13 +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> >> --- >> drivers/iio/buffer/industrialio-triggered-buffer.c | 19 +++++-------------- >> 1 file changed, 5 insertions(+), 14 deletions(-) >> >> diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c >> index 92b8aea..63b4722 100644 >> --- a/drivers/iio/buffer/industrialio-triggered-buffer.c >> +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c >> @@ -92,9 +92,9 @@ void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev) >> } >> EXPORT_SYMBOL(iio_triggered_buffer_cleanup); >> >> -static void devm_iio_triggered_buffer_clean(struct device *dev, void *res) >> +static void devm_iio_triggered_buffer_clean(void *indio_dev) >> { >> - iio_triggered_buffer_cleanup(*(struct iio_dev **)res); >> + iio_triggered_buffer_cleanup(indio_dev); >> } >> >> int devm_iio_triggered_buffer_setup_ext(struct device *dev, >> @@ -104,24 +104,15 @@ int devm_iio_triggered_buffer_setup_ext(struct device *dev, >> const struct iio_buffer_setup_ops *ops, >> const struct attribute **buffer_attrs) >> { >> - struct iio_dev **ptr; >> int ret; >> >> - ptr = devres_alloc(devm_iio_triggered_buffer_clean, sizeof(*ptr), >> - GFP_KERNEL); >> - if (!ptr) >> - return -ENOMEM; >> - >> - *ptr = indio_dev; >> - >> ret = iio_triggered_buffer_setup_ext(indio_dev, h, thread, ops, >> buffer_attrs); >> if (!ret) >> - devres_add(dev, ptr); >> - else >> - devres_free(ptr); >> + return ret; > > This looks inverted from what it should be. > > if (ret) > return ret; > > return devm_add_action_or_reset()... > yes. it does. will fix. thanks >> >> - return ret; >> + return devm_add_action_or_reset(dev, devm_iio_triggered_buffer_clean, >> + indio_dev); >> } >> EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup_ext); >> > > > . >
On Mon, 12 Apr 2021 17:05:15 +0800 Yicong Yang <yangyicong@hisilicon.com> wrote: > On 2021/4/11 22:16, Jonathan Cameron wrote: > > On Thu, 8 Apr 2021 19:38:13 +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> > >> --- > >> drivers/iio/buffer/industrialio-triggered-buffer.c | 19 +++++-------------- > >> 1 file changed, 5 insertions(+), 14 deletions(-) > >> > >> diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c > >> index 92b8aea..63b4722 100644 > >> --- a/drivers/iio/buffer/industrialio-triggered-buffer.c > >> +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c > >> @@ -92,9 +92,9 @@ void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev) > >> } > >> EXPORT_SYMBOL(iio_triggered_buffer_cleanup); > >> > >> -static void devm_iio_triggered_buffer_clean(struct device *dev, void *res) > >> +static void devm_iio_triggered_buffer_clean(void *indio_dev) > >> { > >> - iio_triggered_buffer_cleanup(*(struct iio_dev **)res); > >> + iio_triggered_buffer_cleanup(indio_dev); > >> } > >> > >> int devm_iio_triggered_buffer_setup_ext(struct device *dev, > >> @@ -104,24 +104,15 @@ int devm_iio_triggered_buffer_setup_ext(struct device *dev, > >> const struct iio_buffer_setup_ops *ops, > >> const struct attribute **buffer_attrs) > >> { > >> - struct iio_dev **ptr; > >> int ret; > >> > >> - ptr = devres_alloc(devm_iio_triggered_buffer_clean, sizeof(*ptr), > >> - GFP_KERNEL); > >> - if (!ptr) > >> - return -ENOMEM; > >> - > >> - *ptr = indio_dev; > >> - > >> ret = iio_triggered_buffer_setup_ext(indio_dev, h, thread, ops, > >> buffer_attrs); > >> if (!ret) > >> - devres_add(dev, ptr); > >> - else > >> - devres_free(ptr); > >> + return ret; > > > > This looks inverted from what it should be. > > > > if (ret) > > return ret; > > > > return devm_add_action_or_reset()... > > > > yes. it does. will fix. I fixed it up and applied to the togreg branch of iio.git. Pushed out as testing for all the usual reasons. Thanks, Jonathan > > thanks > > >> > >> - return ret; > >> + return devm_add_action_or_reset(dev, devm_iio_triggered_buffer_clean, > >> + indio_dev); > >> } > >> EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup_ext); > >> > > > > > > . > > >
diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c index 92b8aea..63b4722 100644 --- a/drivers/iio/buffer/industrialio-triggered-buffer.c +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c @@ -92,9 +92,9 @@ void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev) } EXPORT_SYMBOL(iio_triggered_buffer_cleanup); -static void devm_iio_triggered_buffer_clean(struct device *dev, void *res) +static void devm_iio_triggered_buffer_clean(void *indio_dev) { - iio_triggered_buffer_cleanup(*(struct iio_dev **)res); + iio_triggered_buffer_cleanup(indio_dev); } int devm_iio_triggered_buffer_setup_ext(struct device *dev, @@ -104,24 +104,15 @@ int devm_iio_triggered_buffer_setup_ext(struct device *dev, const struct iio_buffer_setup_ops *ops, const struct attribute **buffer_attrs) { - struct iio_dev **ptr; int ret; - ptr = devres_alloc(devm_iio_triggered_buffer_clean, sizeof(*ptr), - GFP_KERNEL); - if (!ptr) - return -ENOMEM; - - *ptr = indio_dev; - ret = iio_triggered_buffer_setup_ext(indio_dev, h, thread, ops, buffer_attrs); if (!ret) - devres_add(dev, ptr); - else - devres_free(ptr); + return ret; - return ret; + return devm_add_action_or_reset(dev, devm_iio_triggered_buffer_clean, + indio_dev); } EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup_ext);
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-triggered-buffer.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)