Skip to content

Commit

Permalink
x86, boot: Move memset() definition in compressed/string.c
Browse files Browse the repository at this point in the history
Currently compressed/misc.c needs to link against memset(). I think one of
the reasons of this need is inclusion of various header files which define
static inline functions and use memset() inside these. For example,
include/linux/bitmap.h

I think trying to include "../string.h" and using builtin version of memset
does not work because by the time "#define memset" shows up, it is too
late. Some other header file has already used memset() and expects to
find a definition during link phase.

Currently we have a C definitoin of memset() in misc.c. Move it to
compressed/string.c so that others can use it if need be.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Link: http://lkml.kernel.org/r/1395170800-11059-6-git-send-email-vgoyal@redhat.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
  • Loading branch information
Vivek Goyal authored and H. Peter Anvin committed Mar 19, 2014
1 parent fb4cac5 commit 0499955
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 7 additions & 13 deletions arch/x86/boot/compressed/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@
*/
#define STATIC static

#undef memset
#undef memcpy

/*
* Use a normal definition of memset() from string.c. There are already
* included header files which expect a definition of memset() and by
* the time we define memset macro, it is too late.
*/
#undef memset
#define memzero(s, n) memset((s), 0, (n))


Expand All @@ -110,8 +116,6 @@ static void error(char *m);
*/
struct boot_params *real_mode; /* Pointer to real-mode data */

void *memset(void *s, int c, size_t n);

memptr free_mem_ptr;
memptr free_mem_end_ptr;

Expand Down Expand Up @@ -216,16 +220,6 @@ void __putstr(const char *s)
outb(0xff & (pos >> 1), vidport+1);
}

void *memset(void *s, int c, size_t n)
{
int i;
char *ss = s;

for (i = 0; i < n; i++)
ss[i] = c;
return s;
}

static void error(char *x)
{
error_putstr("\n\n");
Expand Down
10 changes: 10 additions & 0 deletions arch/x86/boot/compressed/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ void *memcpy(void *dest, const void *src, size_t n)
return dest;
}
#endif

void *memset(void *s, int c, size_t n)
{
int i;
char *ss = s;

for (i = 0; i < n; i++)
ss[i] = c;
return s;
}

0 comments on commit 0499955

Please sign in to comment.