Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/firmware/ihex2fw: Replace explicit alignment with ALIGN

(X + 3) & ~3 is the same as ALIGN(X, 4), so replace all of the
instances of the formwer in the code with the latter. While at it,
introduce a helper variable 'record_size' to avoid duplicating length
calculatin code. No functional change intended.

Cc: Chris Healy <cphealy@gmail.com>
Cc: Kyle McMartin <kyle@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andrey Smirnov and committed by
Greg Kroah-Hartman
925f8d4a 2ef8179b

+4 -2
+4 -2
tools/firmware/ihex2fw.c
··· 135 135 static int process_ihex(uint8_t *data, ssize_t size) 136 136 { 137 137 struct ihex_binrec *record; 138 + size_t record_size; 138 139 uint32_t offset = 0; 139 140 uint32_t data32; 140 141 uint8_t type, crc = 0, crcbyte = 0; ··· 162 161 len <<= 8; 163 162 len += hex(data + i, &crc); i += 2; 164 163 } 165 - record = malloc((sizeof (*record) + len + 3) & ~3); 164 + record_size = ALIGN(sizeof(*record) + len, 4); 165 + record = malloc(record_size); 166 166 if (!record) { 167 167 fprintf(stderr, "out of memory for records\n"); 168 168 return -ENOMEM; 169 169 } 170 - memset(record, 0, (sizeof(*record) + len + 3) & ~3); 170 + memset(record, 0, record_size); 171 171 record->len = len; 172 172 173 173 /* now check if we have enough data to read everything */