summaryrefslogtreecommitdiff
path: root/libkmod/libkmod-elf.c
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2011-12-20 04:02:15 -0200
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2011-12-20 11:35:17 -0200
commit58b7191c945918f85d5f41ea591111f741ad3a75 (patch)
tree2a2d1e7122a33e7dfd4573e2c3ccebc0dee4de39 /libkmod/libkmod-elf.c
parentf8fa525c7ffa0c700eab437baa8cdb4ba779b603 (diff)
downloadkmod-58b7191c945918f85d5f41ea591111f741ad3a75.tar.gz
Make section size constant since it's always the same
Diffstat (limited to 'libkmod/libkmod-elf.c')
-rw-r--r--libkmod/libkmod-elf.c21
1 files 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;