Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: core: Simplify IIO core managed APIs

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.

While at it, inline devm_iio_kfifo_allocate() into its only user.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andy Shevchenko and committed by
Jonathan Cameron
4d9fccb3 b40be056

+21 -44
+11 -30
drivers/iio/buffer/kfifo_buf.c
··· 224 224 } 225 225 EXPORT_SYMBOL(iio_kfifo_free); 226 226 227 - static void devm_iio_kfifo_release(struct device *dev, void *res) 227 + static void devm_iio_kfifo_release(void *buffer) 228 228 { 229 - iio_kfifo_free(*(struct iio_buffer **)res); 230 - } 231 - 232 - /** 233 - * devm_iio_kfifo_allocate - Resource-managed iio_kfifo_allocate() 234 - * @dev: Device to allocate kfifo buffer for 235 - * 236 - * RETURNS: 237 - * Pointer to allocated iio_buffer on success, NULL on failure. 238 - */ 239 - static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev) 240 - { 241 - struct iio_buffer **ptr, *r; 242 - 243 - ptr = devres_alloc(devm_iio_kfifo_release, sizeof(*ptr), GFP_KERNEL); 244 - if (!ptr) 245 - return NULL; 246 - 247 - r = iio_kfifo_allocate(); 248 - if (r) { 249 - *ptr = r; 250 - devres_add(dev, ptr); 251 - } else { 252 - devres_free(ptr); 253 - } 254 - 255 - return r; 229 + iio_kfifo_free(buffer); 256 230 } 257 231 258 232 /** ··· 236 262 * @setup_ops: The setup_ops required to configure the HW part of the buffer (optional) 237 263 * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer 238 264 * 239 - * This function allocates a kfifo buffer via devm_iio_kfifo_allocate() and 265 + * This function allocates a kfifo buffer via iio_kfifo_allocate() and 240 266 * attaches it to the IIO device via iio_device_attach_buffer(). 241 267 * This is meant to be a bit of a short-hand/helper function as there are a few 242 268 * drivers that seem to do this. 269 + * 270 + * Return: 0 on success, negative error code on failure. 243 271 */ 244 272 int devm_iio_kfifo_buffer_setup_ext(struct device *dev, 245 273 struct iio_dev *indio_dev, ··· 249 273 const struct iio_dev_attr **buffer_attrs) 250 274 { 251 275 struct iio_buffer *buffer; 276 + int ret; 252 277 253 - buffer = devm_iio_kfifo_allocate(dev); 278 + buffer = iio_kfifo_allocate(); 254 279 if (!buffer) 255 280 return -ENOMEM; 281 + 282 + ret = devm_add_action_or_reset(dev, devm_iio_kfifo_release, buffer); 283 + if (ret) 284 + return ret; 256 285 257 286 indio_dev->modes |= INDIO_BUFFER_SOFTWARE; 258 287 indio_dev->setup_ops = setup_ops;
+10 -14
drivers/iio/industrialio-trigger.c
··· 635 635 } 636 636 EXPORT_SYMBOL(iio_trigger_free); 637 637 638 - static void devm_iio_trigger_release(struct device *dev, void *res) 638 + static void devm_iio_trigger_release(void *trig) 639 639 { 640 - iio_trigger_free(*(struct iio_trigger **)res); 640 + iio_trigger_free(trig); 641 641 } 642 642 643 643 /** ··· 659 659 struct module *this_mod, 660 660 const char *fmt, ...) 661 661 { 662 - struct iio_trigger **ptr, *trig; 662 + struct iio_trigger *trig; 663 663 va_list vargs; 664 - 665 - ptr = devres_alloc(devm_iio_trigger_release, sizeof(*ptr), 666 - GFP_KERNEL); 667 - if (!ptr) 668 - return NULL; 664 + int ret; 669 665 670 666 /* use raw alloc_dr for kmalloc caller tracing */ 671 667 va_start(vargs, fmt); 672 668 trig = viio_trigger_alloc(parent, this_mod, fmt, vargs); 673 669 va_end(vargs); 674 - if (trig) { 675 - *ptr = trig; 676 - devres_add(parent, ptr); 677 - } else { 678 - devres_free(ptr); 679 - } 670 + if (!trig) 671 + return NULL; 672 + 673 + ret = devm_add_action_or_reset(parent, devm_iio_trigger_release, trig); 674 + if (ret) 675 + return NULL; 680 676 681 677 return trig; 682 678 }