From f82d79c984faa2f6cf20984121ea72d9313a9ee3 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 22 Aug 2013 16:44:20 +0200 Subject: [PATCH] * include/grub/mm.h (grub_extend_alloc): Remove. * grub-core/loader/i386/pc/plan9.c: Use own version of grub_extend_alloc with appropriate types. --- ChangeLog | 6 ++++++ grub-core/loader/i386/pc/plan9.c | 31 ++++++++++++++++++++++++------- include/grub/mm.h | 17 ----------------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6ef39a3b..77a4e423b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-08-22 Vladimir Serbinenko + + * include/grub/mm.h (grub_extend_alloc): Remove. + * grub-core/loader/i386/pc/plan9.c: Use own version of + grub_extend_alloc with appropriate types. + 2013-08-22 Vladimir Serbinenko * conf/Makefile.common (CFLAGS_GCRY): Add -Wno-redundant-decls. diff --git a/grub-core/loader/i386/pc/plan9.c b/grub-core/loader/i386/pc/plan9.c index 1c7b381c6..0d10b1c24 100644 --- a/grub-core/loader/i386/pc/plan9.c +++ b/grub-core/loader/i386/pc/plan9.c @@ -119,6 +119,23 @@ static const char prefixes[5][10] = { "dos", "plan9", "ntfs", "linux", "linuxswap" }; +#include + +static inline grub_err_t +grub_extend_alloc (grub_size_t sz, grub_size_t *allocated, char **ptr) +{ + void *n; + if (sz < *allocated) + return GRUB_ERR_NONE; + + *allocated = 2 * sz; + n = grub_realloc (*ptr, *allocated); + if (!n) + return grub_errno; + *ptr = n; + return GRUB_ERR_NONE; +} + /* Helper for grub_cmd_plan9. */ static int fill_partition (grub_disk_t disk, const grub_partition_t partition, void *data) @@ -130,7 +147,7 @@ fill_partition (grub_disk_t disk, const grub_partition_t partition, void *data) if (!fill_ctx->noslash) { if (grub_extend_alloc (fill_ctx->pmapptr + 1, &fill_ctx->pmapalloc, - (void **) &fill_ctx->pmap)) + &fill_ctx->pmap)) return 1; fill_ctx->pmap[fill_ctx->pmapptr++] = '/'; } @@ -149,7 +166,7 @@ fill_partition (grub_disk_t disk, const grub_partition_t partition, void *data) do { if (grub_extend_alloc (fill_ctx->pmapptr + 1, &fill_ctx->pmapalloc, - (void **) &fill_ctx->pmap)) + &fill_ctx->pmap)) return 1; err = grub_disk_read (disk, 1, ptr, 1, fill_ctx->pmap + fill_ctx->pmapptr); @@ -197,14 +214,14 @@ fill_partition (grub_disk_t disk, const grub_partition_t partition, void *data) fill_ctx->prefixescnt[c]); fill_ctx->prefixescnt[c]++; if (grub_extend_alloc (fill_ctx->pmapptr + grub_strlen (name) + 1, - &fill_ctx->pmapalloc, (void **) &fill_ctx->pmap)) + &fill_ctx->pmapalloc, &fill_ctx->pmap)) return 1; grub_strcpy (fill_ctx->pmap + fill_ctx->pmapptr, name); fill_ctx->pmapptr += grub_strlen (name); } pend = fill_ctx->pmapptr; if (grub_extend_alloc (fill_ctx->pmapptr + 2 + 25 + 5 + 25, - &fill_ctx->pmapalloc, (void **) &fill_ctx->pmap)) + &fill_ctx->pmapalloc, &fill_ctx->pmap)) return 1; fill_ctx->pmap[fill_ctx->pmapptr++] = ' '; grub_snprintf (fill_ctx->pmap + fill_ctx->pmapptr, 25 + 5 + 25, @@ -329,7 +346,7 @@ fill_disk (const char *name, void *data) } if (grub_extend_alloc (fill_ctx->pmapptr + grub_strlen (plan9name) + sizeof ("part="), &fill_ctx->pmapalloc, - (void **) &fill_ctx->pmap)) + &fill_ctx->pmap)) { grub_free (plan9name); return 1; @@ -351,7 +368,7 @@ fill_disk (const char *name, void *data) if (grub_partition_iterate (dev->disk, fill_partition, fill_ctx)) return 1; if (grub_extend_alloc (fill_ctx->pmapptr + 1, &fill_ctx->pmapalloc, - (void **) &fill_ctx->pmap)) + &fill_ctx->pmap)) return 1; fill_ctx->pmap[fill_ctx->pmapptr++] = '\n'; @@ -399,7 +416,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[]) goto fail; if (grub_extend_alloc (fill_ctx.pmapptr + 1, &fill_ctx.pmapalloc, - (void **) &fill_ctx.pmap)) + &fill_ctx.pmap)) goto fail; fill_ctx.pmap[fill_ctx.pmapptr] = 0; diff --git a/include/grub/mm.h b/include/grub/mm.h index 82b200c27..047006944 100644 --- a/include/grub/mm.h +++ b/include/grub/mm.h @@ -72,21 +72,4 @@ void *EXPORT_FUNC(grub_debug_memalign) (const char *file, int line, grub_size_t align, grub_size_t size); #endif /* MM_DEBUG && ! GRUB_UTIL */ -#include - -static inline grub_err_t -grub_extend_alloc (grub_size_t sz, grub_size_t *allocated, void **ptr) -{ - void *n; - if (sz < *allocated) - return GRUB_ERR_NONE; - - *allocated = 2 * sz; - n = grub_realloc (*ptr, *allocated); - if (!n) - return grub_errno; - *ptr = n; - return GRUB_ERR_NONE; -} - #endif /* ! GRUB_MM_H */