From 58b7191c945918f85d5f41ea591111f741ad3a75 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 20 Dec 2011 04:02:15 -0200 Subject: [PATCH] Make section size constant since it's always the same --- libkmod/libkmod-elf.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index 30feb76..f8a4317 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -456,7 +456,7 @@ int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char * /* array will be allocated with strings in a single malloc, just free *array */ int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) { - uint64_t size, secsize, slen, off; + uint64_t size, slen, off; struct kmod_modversion *a; const void *buf; char *itr; @@ -469,27 +469,28 @@ int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion uint64_t crc; char name[64 - sizeof(uint64_t)]; }; +#define MODVERSION_SEC_SIZE (sizeof(struct kmod_modversion64)) + + assert(sizeof(struct kmod_modversion64) == + sizeof(struct kmod_modversion32)); *array = NULL; err = kmod_elf_get_section(elf, "__versions", &buf, &size); if (err < 0) return err; + if (buf == NULL || size == 0) return 0; - if (elf->class & KMOD_ELF_32) - secsize = sizeof(struct kmod_modversion32); - else - secsize = sizeof(struct kmod_modversion64); - - if (size % secsize != 0) + if (size % MODVERSION_SEC_SIZE != 0) return -EINVAL; - count = size / secsize; + + count = size / MODVERSION_SEC_SIZE; off = (const uint8_t *)buf - elf->memory; slen = 0; - for (i = 0; i < count; i++, off += secsize) { + for (i = 0; i < count; i++, off += MODVERSION_SEC_SIZE) { const char *symbol; if (elf->class & KMOD_ELF_32) { struct kmod_modversion32 *mv; @@ -509,7 +510,7 @@ int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion itr = (char *)(a + count); off = (const uint8_t *)buf - elf->memory; - for (i = 0; i < count; i++, off += secsize) { + for (i = 0; i < count; i++, off += MODVERSION_SEC_SIZE) { uint64_t crc; const char *symbol; size_t symbollen; -- 2.7.4