iio: buffer: Use roundup() instead of open-coding it
Makes the code slightly shorter and a bit easier to understand.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 2952ee0..7462f12 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -979,9 +979,7 @@
else
length = ch->scan_type.storagebits / 8;
/* Make sure we are aligned */
- in_loc += length;
- if (in_loc % length)
- in_loc += length - in_loc % length;
+ in_loc = roundup(in_loc, length) + length;
}
p = kmalloc(sizeof(*p), GFP_KERNEL);
if (p == NULL) {
@@ -994,10 +992,8 @@
ch->scan_type.repeat;
else
length = ch->scan_type.storagebits / 8;
- if (out_loc % length)
- out_loc += length - out_loc % length;
- if (in_loc % length)
- in_loc += length - in_loc % length;
+ out_loc = roundup(out_loc, length);
+ in_loc = roundup(in_loc, length);
p->from = in_loc;
p->to = out_loc;
p->length = length;
@@ -1019,10 +1015,8 @@
ch->scan_type.repeat;
else
length = ch->scan_type.storagebits / 8;
- if (out_loc % length)
- out_loc += length - out_loc % length;
- if (in_loc % length)
- in_loc += length - in_loc % length;
+ out_loc = roundup(out_loc, length);
+ in_loc = roundup(in_loc, length);
p->from = in_loc;
p->to = out_loc;
p->length = length;