diff options
author | Karol Wrona <k.wrona@samsung.com> | 2014-12-19 12:39:25 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-12-26 06:39:57 -0500 |
commit | 780103fef5c88a97fb9c8d0079bf326ed6147f1f (patch) | |
tree | 7d3f317dabc20607a14439e426955b66361bc216 /drivers/iio | |
parent | 7ab374a053a43050117eb452306b6cd9dcb58cfd (diff) |
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>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/kfifo_buf.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c index 7f6fad658e83..b2beea01c49b 100644 --- a/drivers/iio/kfifo_buf.c +++ b/drivers/iio/kfifo_buf.c | |||
@@ -164,4 +164,58 @@ void iio_kfifo_free(struct iio_buffer *r) | |||
164 | } | 164 | } |
165 | EXPORT_SYMBOL(iio_kfifo_free); | 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 | MODULE_LICENSE("GPL"); | 221 | MODULE_LICENSE("GPL"); |