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

iio: kfifo: Add resource management devm_iio_kfifo_allocate/free

iio kfifo allocate/free gained their devm_ wrappers.

Signed-off-by: Karol Wrona <k.wrona@samsung.com>
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Karol Wrona and committed by
Jonathan Cameron
780103fe 7ab374a0

+59
+2
Documentation/driver-model/devres.txt
··· 258 258 devm_iio_device_free() 259 259 devm_iio_device_register() 260 260 devm_iio_device_unregister() 261 + devm_iio_kfifo_allocate() 262 + devm_iio_kfifo_free() 261 263 devm_iio_trigger_alloc() 262 264 devm_iio_trigger_free() 263 265
+54
drivers/iio/kfifo_buf.c
··· 164 164 } 165 165 EXPORT_SYMBOL(iio_kfifo_free); 166 166 167 + static void devm_iio_kfifo_release(struct device *dev, void *res) 168 + { 169 + iio_kfifo_free(*(struct iio_buffer **)res); 170 + } 171 + 172 + static int devm_iio_kfifo_match(struct device *dev, void *res, void *data) 173 + { 174 + struct iio_buffer **r = res; 175 + 176 + if (WARN_ON(!r || !*r)) 177 + return 0; 178 + 179 + return *r == data; 180 + } 181 + 182 + /** 183 + * devm_iio_fifo_allocate - Resource-managed iio_kfifo_allocate() 184 + * @dev: Device to allocate kfifo buffer for 185 + * 186 + * RETURNS: 187 + * Pointer to allocated iio_buffer on success, NULL on failure. 188 + */ 189 + struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev) 190 + { 191 + struct iio_buffer **ptr, *r; 192 + 193 + ptr = devres_alloc(devm_iio_kfifo_release, sizeof(*ptr), GFP_KERNEL); 194 + if (!ptr) 195 + return NULL; 196 + 197 + r = iio_kfifo_allocate(); 198 + if (r) { 199 + *ptr = r; 200 + devres_add(dev, ptr); 201 + } else { 202 + devres_free(ptr); 203 + } 204 + 205 + return r; 206 + } 207 + EXPORT_SYMBOL(devm_iio_kfifo_allocate); 208 + 209 + /** 210 + * devm_iio_fifo_free - Resource-managed iio_kfifo_free() 211 + * @dev: Device the buffer belongs to 212 + * @r: The buffer associated with the device 213 + */ 214 + void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r) 215 + { 216 + WARN_ON(devres_release(dev, devm_iio_kfifo_release, 217 + devm_iio_kfifo_match, r)); 218 + } 219 + EXPORT_SYMBOL(devm_iio_kfifo_free); 220 + 167 221 MODULE_LICENSE("GPL");
+3
include/linux/iio/kfifo_buf.h
··· 8 8 struct iio_buffer *iio_kfifo_allocate(void); 9 9 void iio_kfifo_free(struct iio_buffer *r); 10 10 11 + struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev); 12 + void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r); 13 + 11 14 #endif