From 091dfa0c26a022cc66a2a23520a8db4461a8fd67 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Mon, 30 Nov 2015 16:44:22 +0100 Subject: [PATCH] Slight code style improvements for blockwise functions. --- lib/internal.h | 2 +- lib/utils.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/internal.h b/lib/internal.h index 3ce52046..fd52fa19 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -101,7 +101,7 @@ uint64_t crypt_dev_partition_offset(const char *dev_path); ssize_t write_buffer(int fd, const void *buf, size_t count); ssize_t read_buffer(int fd, void *buf, size_t count); ssize_t write_blockwise(int fd, int bsize, void *buf, size_t count); -ssize_t read_blockwise(int fd, int bsize, void *_buf, size_t count); +ssize_t read_blockwise(int fd, int bsize, void *buf, size_t count); ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset); ssize_t read_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset); diff --git a/lib/utils.c b/lib/utils.c index 4460cb6b..79bd32d6 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -56,13 +56,14 @@ static void *aligned_malloc(void **base, int size, int alignment) /* Credits go to Michal's padlock patches for this alignment code */ char *ptr; - ptr = malloc(size + alignment); - if(ptr == NULL) return NULL; + ptr = malloc(size + alignment); + if (!ptr) + return NULL; *base = ptr; - if(alignment > 1 && ((long)ptr & (alignment - 1))) { + if (alignment > 1 && ((long)ptr & (alignment - 1))) ptr += alignment - ((long)(ptr) & (alignment - 1)); - } + return ptr; #endif } @@ -171,7 +172,8 @@ out: return ret; } -ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count) { +ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count) +{ void *hangover_buf, *hangover_buf_base = NULL; void *buf, *buf_base = NULL; int r, alignment; @@ -193,7 +195,7 @@ ssize_t read_blockwise(int fd, int bsize, void *orig_buf, size_t count) { buf = orig_buf; r = read_buffer(fd, buf, solid); - if(r < 0 || r != (ssize_t)solid) + if (r < 0 || r != (ssize_t)solid) goto out; if (hangover) { @@ -222,7 +224,8 @@ out: * is implicitly included in the read/write offset, which can not be set to non-aligned * boundaries. Hence, we combine llseek with write. */ -ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset) { +ssize_t write_lseek_blockwise(int fd, int bsize, char *buf, size_t count, off_t offset) +{ char *frontPadBuf; void *frontPadBuf_base = NULL; int r, frontHang;