* [PATCH] kconfig: allow long lines in config file @ 2012-07-10 23:47 cody 2012-07-13 13:07 ` Michal Marek 0 siblings, 1 reply; 6+ messages in thread From: cody @ 2012-07-10 23:47 UTC (permalink / raw) To: Michal Marek; +Cc: Cody Schafer, linux-kbuild, linux-kernel From: Cody Schafer <cody@linux.vnet.ibm.com> For some config options (CONFIG_EXTRA_FIRMWARE, for example), the length of a config file line can exceed the 1024 byte buffer. Switch from fgets to getline to fix. Signed-off-by: Cody Schafer <cody@linux.vnet.ibm.com> --- scripts/kconfig/confdata.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 52577f0..175037f 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -185,7 +185,8 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) int conf_read_simple(const char *name, int def) { FILE *in = NULL; - char line[1024]; + char *line = NULL; + size_t line_asize = 0; char *p, *p2; struct symbol *sym; int i, def_flags; @@ -247,7 +248,7 @@ load: } } - while (fgets(line, sizeof(line), in)) { + while (getline(&line, &line_asize, in) != -1) { conf_lineno++; sym = NULL; if (line[0] == '#') { @@ -335,6 +336,7 @@ setsym: cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri); } } + free(line); fclose(in); if (modules_sym) -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] kconfig: allow long lines in config file 2012-07-10 23:47 [PATCH] kconfig: allow long lines in config file cody @ 2012-07-13 13:07 ` Michal Marek 2012-07-13 18:27 ` [PATCH v2] " cody 2012-07-13 18:30 ` [PATCH] " cody 0 siblings, 2 replies; 6+ messages in thread From: Michal Marek @ 2012-07-13 13:07 UTC (permalink / raw) To: cody; +Cc: linux-kbuild, linux-kernel On 11.7.2012 01:47, cody@linux.vnet.ibm.com wrote: > From: Cody Schafer <cody@linux.vnet.ibm.com> > > For some config options (CONFIG_EXTRA_FIRMWARE, for example), the length > of a config file line can exceed the 1024 byte buffer. > > Switch from fgets to getline to fix. getline() is not a portable function and kconfig is an essential part of kernel build. Could you please change it to a loop over fgets that terminates when the last character is '\n'? Thanks, Michal ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] kconfig: allow long lines in config file 2012-07-13 13:07 ` Michal Marek @ 2012-07-13 18:27 ` cody 2012-07-13 20:54 ` Michal Marek 2012-07-13 18:30 ` [PATCH] " cody 1 sibling, 1 reply; 6+ messages in thread From: cody @ 2012-07-13 18:27 UTC (permalink / raw) To: Michal Marek; +Cc: Cody Schafer, linux-kbuild, linux-kernel From: Cody Schafer <cody@linux.vnet.ibm.com> For some config options (CONFIG_EXTRA_FIRMWARE, for example), the length of a config file line can exceed the 1024 byte buffer. Switch from fgets to compat_getline to fix. compat_getline is an internally implimented getline work-alike for portability purposes. Signed-off-by: Cody Schafer <cody@linux.vnet.ibm.com> --- scripts/kconfig/confdata.c | 61 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 52577f0..13ddf11 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -182,10 +182,66 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) return 0; } +#define LINE_GROWTH 16 +static int add_byte(int c, char **lineptr, size_t slen, size_t *n) +{ + char *nline; + size_t new_size = slen + 1; + if (new_size > *n) { + new_size += LINE_GROWTH - 1; + new_size *= 2; + nline = realloc(*lineptr, new_size); + if (!nline) + return -1; + + *lineptr = nline; + *n = new_size; + } + + (*lineptr)[slen] = c; + + return 0; +} + +static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream) +{ + char *line = *lineptr; + size_t slen = 0; + + for (;;) { + int c = getc(stream); + + switch (c) { + case '\n': + if (add_byte(c, &line, slen, n) < 0) + goto e_out; + slen++; + /* fall through */ + case EOF: + if (add_byte('\0', &line, slen, n) < 0) + goto e_out; + *lineptr = line; + if (slen == 0) + return -1; + return slen; + default: + if (add_byte(c, &line, slen, n) < 0) + goto e_out; + slen++; + } + } + +e_out: + line[slen-1] = '\0'; + *lineptr = line; + return -1; +} + int conf_read_simple(const char *name, int def) { FILE *in = NULL; - char line[1024]; + char *line = NULL; + size_t line_asize = 0; char *p, *p2; struct symbol *sym; int i, def_flags; @@ -247,7 +303,7 @@ load: } } - while (fgets(line, sizeof(line), in)) { + while (compat_getline(&line, &line_asize, in) != -1) { conf_lineno++; sym = NULL; if (line[0] == '#') { @@ -335,6 +391,7 @@ setsym: cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri); } } + free(line); fclose(in); if (modules_sym) -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] kconfig: allow long lines in config file 2012-07-13 18:27 ` [PATCH v2] " cody @ 2012-07-13 20:54 ` Michal Marek 0 siblings, 0 replies; 6+ messages in thread From: Michal Marek @ 2012-07-13 20:54 UTC (permalink / raw) To: cody; +Cc: linux-kbuild, linux-kernel On Fri, Jul 13, 2012 at 11:27:12AM -0700, cody@linux.vnet.ibm.com wrote: > From: Cody Schafer <cody@linux.vnet.ibm.com> > > For some config options (CONFIG_EXTRA_FIRMWARE, for example), the length > of a config file line can exceed the 1024 byte buffer. > > Switch from fgets to compat_getline to fix. compat_getline is an > internally implimented getline work-alike for portability purposes. > > Signed-off-by: Cody Schafer <cody@linux.vnet.ibm.com> Applied to kbuild.git#kconfig, thanks. Michal ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] kconfig: allow long lines in config file 2012-07-13 13:07 ` Michal Marek 2012-07-13 18:27 ` [PATCH v2] " cody @ 2012-07-13 18:30 ` cody 2012-07-13 20:39 ` Michal Marek 1 sibling, 1 reply; 6+ messages in thread From: cody @ 2012-07-13 18:30 UTC (permalink / raw) To: Michal Marek; +Cc: linux-kbuild, linux-kernel Do we have any strict standards for what is and is not portable? (I'm aware 'getline' was only added to posix ~4 years ago in 2008). -- Cody ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] kconfig: allow long lines in config file 2012-07-13 18:30 ` [PATCH] " cody @ 2012-07-13 20:39 ` Michal Marek 0 siblings, 0 replies; 6+ messages in thread From: Michal Marek @ 2012-07-13 20:39 UTC (permalink / raw) To: cody; +Cc: linux-kbuild, linux-kernel Dne 13.7.2012 20:30, cody napsal(a): > Do we have any strict standards for what is and is not portable? We don't. I only checked the existing userspace code and except for perf, there is no other usage of getline(). > (I'm aware 'getline' was only added to posix ~4 years ago in 2008). Ah, good to know. Nevetheless, let's stay conservative for some more time. Thanks for sending the updated patch, btw. Michal ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-07-13 20:54 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-07-10 23:47 [PATCH] kconfig: allow long lines in config file cody 2012-07-13 13:07 ` Michal Marek 2012-07-13 18:27 ` [PATCH v2] " cody 2012-07-13 20:54 ` Michal Marek 2012-07-13 18:30 ` [PATCH] " cody 2012-07-13 20:39 ` Michal Marek
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox