mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 19:07:52 +00:00
[PATCH] dmi: make dmi_string() behave like strdup()
This patch changes dmi_string() function to allocate string copy by itself, to avoid code duplication in the next patch. Signed-off-by: Andrey Panin <pazke@donpac.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
4e70b9a3d6
commit
c3c7120d55
1 changed files with 23 additions and 16 deletions
|
@ -16,15 +16,25 @@ struct dmi_header {
|
||||||
static char * __init dmi_string(struct dmi_header *dm, u8 s)
|
static char * __init dmi_string(struct dmi_header *dm, u8 s)
|
||||||
{
|
{
|
||||||
u8 *bp = ((u8 *) dm) + dm->length;
|
u8 *bp = ((u8 *) dm) + dm->length;
|
||||||
|
char *str = "";
|
||||||
|
|
||||||
if (!s)
|
if (s) {
|
||||||
return "";
|
|
||||||
s--;
|
|
||||||
while (s > 0 && *bp) {
|
|
||||||
bp += strlen(bp) + 1;
|
|
||||||
s--;
|
s--;
|
||||||
}
|
while (s > 0 && *bp) {
|
||||||
return bp;
|
bp += strlen(bp) + 1;
|
||||||
|
s--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*bp != 0) {
|
||||||
|
str = alloc_bootmem(strlen(bp) + 1);
|
||||||
|
if (str != NULL)
|
||||||
|
strcpy(str, bp);
|
||||||
|
else
|
||||||
|
printk(KERN_ERR "dmi_string: out of memory.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -84,19 +94,16 @@ static char *dmi_ident[DMI_STRING_MAX];
|
||||||
*/
|
*/
|
||||||
static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
|
static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
|
||||||
{
|
{
|
||||||
char *d = (char*)dm;
|
char *p, *d = (char*) dm;
|
||||||
char *p = dmi_string(dm, d[string]);
|
|
||||||
|
|
||||||
if (p == NULL || *p == 0)
|
|
||||||
return;
|
|
||||||
if (dmi_ident[slot])
|
if (dmi_ident[slot])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dmi_ident[slot] = alloc_bootmem(strlen(p) + 1);
|
p = dmi_string(dm, d[string]);
|
||||||
if(dmi_ident[slot])
|
if (p == NULL)
|
||||||
strcpy(dmi_ident[slot], p);
|
return;
|
||||||
else
|
|
||||||
printk(KERN_ERR "dmi_save_ident: out of memory.\n");
|
dmi_ident[slot] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue