* [RFC PATCH 1/2] iio: kfifo: Remove unused argument in iio_kfifo_allocate
2014-12-09 19:29 [RFC PATCH 0/2] iio: kfifo: Add resource management alloc/free Karol Wrona
@ 2014-12-09 19:29 ` Karol Wrona
2014-12-18 16:42 ` Lars-Peter Clausen
2014-12-09 19:29 ` [RFC PATCH 2/2] iio: kfifo: Add resource management devm_iio_kfifo_allocate/free Karol Wrona
1 sibling, 1 reply; 5+ messages in thread
From: Karol Wrona @ 2014-12-09 19:29 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Hartmut Knaack, linux-kernel
Cc: Bartlomiej Zolnierkiewicz, Kyungmin Park, Karol Wrona,
Karol Wrona
indio_dev was unused in function body plus some small style fix - add new
lines after "if(sth) return sth" and before the last return statement.
Change-Id: I9495c778dc7bc87cc4503e890397b576966c44fd
Signed-off-by: Karol Wrona <k.wrona@samsung.com>
---
drivers/iio/kfifo_buf.c | 4 +++-
include/linux/iio/kfifo_buf.h | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
index 7134e8a..5b5387c 100644
--- a/drivers/iio/kfifo_buf.c
+++ b/drivers/iio/kfifo_buf.c
@@ -166,19 +166,21 @@ static const struct iio_buffer_access_funcs kfifo_access_funcs = {
.release = &iio_kfifo_buffer_release,
};
-struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev)
+struct iio_buffer *iio_kfifo_allocate(void)
{
struct iio_kfifo *kf;
kf = kzalloc(sizeof *kf, GFP_KERNEL);
if (!kf)
return NULL;
+
kf->update_needed = true;
iio_buffer_init(&kf->buffer);
kf->buffer.attrs = &iio_kfifo_attribute_group;
kf->buffer.access = &kfifo_access_funcs;
kf->buffer.length = 2;
mutex_init(&kf->user_lock);
+
return &kf->buffer;
}
EXPORT_SYMBOL(iio_kfifo_allocate);
diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h
index 25eeac7..1a8d57a 100644
--- a/include/linux/iio/kfifo_buf.h
+++ b/include/linux/iio/kfifo_buf.h
@@ -5,7 +5,7 @@
#include <linux/iio/iio.h>
#include <linux/iio/buffer.h>
-struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev);
+struct iio_buffer *iio_kfifo_allocate(void);
void iio_kfifo_free(struct iio_buffer *r);
#endif
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [RFC PATCH 2/2] iio: kfifo: Add resource management devm_iio_kfifo_allocate/free
2014-12-09 19:29 [RFC PATCH 0/2] iio: kfifo: Add resource management alloc/free Karol Wrona
2014-12-09 19:29 ` [RFC PATCH 1/2] iio: kfifo: Remove unused argument in iio_kfifo_allocate Karol Wrona
@ 2014-12-09 19:29 ` Karol Wrona
2014-12-18 16:46 ` Lars-Peter Clausen
1 sibling, 1 reply; 5+ messages in thread
From: Karol Wrona @ 2014-12-09 19:29 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio, Hartmut Knaack, linux-kernel
Cc: Bartlomiej Zolnierkiewicz, Kyungmin Park, Karol Wrona,
Karol Wrona
iio kfifo allocate/free gained their devm_ wrappers.
Change-Id: I10c19ccd7c01491caf088b3629137425ddccd29c
Signed-off-by: Karol Wrona <k.wrona@samsung.com>
Suggested-by: Jonathan Cameron <jic23@kernel.org>
---
drivers/iio/kfifo_buf.c | 54 +++++++++++++++++++++++++++++++++++++++++
include/linux/iio/kfifo_buf.h | 3 +++
2 files changed, 57 insertions(+)
diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
index 5b5387c..03a133f 100644
--- a/drivers/iio/kfifo_buf.c
+++ b/drivers/iio/kfifo_buf.c
@@ -191,4 +191,58 @@ void iio_kfifo_free(struct iio_buffer *r)
}
EXPORT_SYMBOL(iio_kfifo_free);
+static void devm_iio_kfifo_release(struct device *dev, void *res)
+{
+ iio_kfifo_free(*(struct iio_buffer **)res);
+}
+
+static int devm_iio_kfifo_match(struct device *dev, void *res, void *data)
+{
+ struct iio_buffer **r = res;
+
+ if (WARN_ON(!r || !*r))
+ return 0;
+
+ return *r == data;
+}
+
+/**
+ * devm_iio_fifo_allocate - Resource-managed iio_kfifo_allocate()
+ * @dev: Device to allocate kfifo buffer for
+ *
+ * RETURNS:
+ * Pointer to allocated iio_buffer on success, NULL on failure.
+ */
+struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
+{
+ struct iio_buffer **ptr, *r;
+
+ ptr = devres_alloc(devm_iio_kfifo_release, sizeof *ptr, GFP_KERNEL);
+ if (!ptr)
+ return NULL;
+
+ r = iio_kfifo_allocate();
+ if (r) {
+ *ptr = r;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return r;
+}
+EXPORT_SYMBOL(devm_iio_kfifo_allocate);
+
+/**
+ * devm_iio_fifo_free - Resource-managed iio_kfifo_free()
+ * @dev: Device the buffer belongs to
+ * @r: the buffer associated with the device
+ */
+void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r)
+{
+ WARN_ON(devres_release(dev, devm_iio_kfifo_release,
+ devm_iio_kfifo_match, r));
+}
+EXPORT_SYMBOL(devm_iio_kfifo_free);
+
MODULE_LICENSE("GPL");
diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h
index 1a8d57a..1683bc7 100644
--- a/include/linux/iio/kfifo_buf.h
+++ b/include/linux/iio/kfifo_buf.h
@@ -8,4 +8,7 @@
struct iio_buffer *iio_kfifo_allocate(void);
void iio_kfifo_free(struct iio_buffer *r);
+struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev);
+void devm_iio_kfifo_free(struct device *dev, struct iio_buffer *r);
+
#endif
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread