]> git.karo-electronics.de Git - linux-beck.git/commitdiff
iio: buffer: Use roundup() instead of open-coding it
authorLars-Peter Clausen <lars@metafoo.de>
Thu, 17 Jul 2014 15:59:00 +0000 (16:59 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sun, 27 Jul 2014 18:13:08 +0000 (19:13 +0100)
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>
drivers/iio/industrialio-buffer.c

index 2952ee038477a2322c217ba0fe0a4d625a46367d..7462f1233974b16da35a0f0f7275cfa1c1ba757d 100644 (file)
@@ -979,9 +979,7 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
                        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 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
                                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 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
                                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;