Skip to content

Commit 002dcfd

Browse files
committed
Merge tag 'kgdb-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux
Pull kgdb updates from Daniel Thompson: "Two cleanups this cycle. The larger of which is the removal of a private allocator within kdb and replacing it with regular memory allocation. The other adopts the simplified version of strscpy() in a couple of places in kdb" * tag 'kgdb-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux: kdb: Remove optional size arguments from strscpy() calls kdb: remove usage of static environment buffer
2 parents 2985dae + afdbe49 commit 002dcfd

File tree

3 files changed

+11
-43
lines changed

3 files changed

+11
-43
lines changed

include/linux/kdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extern int kdb_initial_cpu;
104104
#define KDB_NOENVVALUE (-6)
105105
#define KDB_NOTIMP (-7)
106106
#define KDB_ENVFULL (-8)
107-
#define KDB_ENVBUFFULL (-9)
107+
#define KDB_KMALLOCFAILED (-9)
108108
#define KDB_TOOMANYBPT (-10)
109109
#define KDB_TOOMANYDBREGS (-11)
110110
#define KDB_DUPBPT (-12)

kernel/debug/kdb/kdb_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
334334
*cp = '\0';
335335
p_tmp = strrchr(buffer, ' ');
336336
p_tmp = (p_tmp ? p_tmp + 1 : buffer);
337-
strscpy(tmpbuffer, p_tmp, sizeof(tmpbuffer));
337+
strscpy(tmpbuffer, p_tmp);
338338
*cp = tmp;
339339

340340
len = strlen(tmpbuffer);
@@ -452,7 +452,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
452452
char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)
453453
{
454454
if (prompt && kdb_prompt_str != prompt)
455-
strscpy(kdb_prompt_str, prompt, CMD_BUFLEN);
455+
strscpy(kdb_prompt_str, prompt);
456456
kdb_printf("%s", kdb_prompt_str);
457457
kdb_nextline = 1; /* Prompt and input resets line number */
458458
return kdb_read(buffer, bufsize);

kernel/debug/kdb/kdb_main.c

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static kdbmsg_t kdbmsgs[] = {
105105
KDBMSG(NOENVVALUE, "Environment variable should have value"),
106106
KDBMSG(NOTIMP, "Command not implemented"),
107107
KDBMSG(ENVFULL, "Environment full"),
108-
KDBMSG(ENVBUFFULL, "Environment buffer full"),
108+
KDBMSG(KMALLOCFAILED, "Failed to allocate memory"),
109109
KDBMSG(TOOMANYBPT, "Too many breakpoints defined"),
110110
#ifdef CONFIG_CPU_XSCALE
111111
KDBMSG(TOOMANYDBREGS, "More breakpoints than ibcr registers defined"),
@@ -130,13 +130,9 @@ static const int __nkdb_err = ARRAY_SIZE(kdbmsgs);
130130

131131

132132
/*
133-
* Initial environment. This is all kept static and local to
134-
* this file. We don't want to rely on the memory allocation
135-
* mechanisms in the kernel, so we use a very limited allocate-only
136-
* heap for new and altered environment variables. The entire
137-
* environment is limited to a fixed number of entries (add more
138-
* to __env[] if required) and a fixed amount of heap (add more to
139-
* KDB_ENVBUFSIZE if required).
133+
* Initial environment. This is all kept static and local to this file.
134+
* The entire environment is limited to a fixed number of entries
135+
* (add more to __env[] if required)
140136
*/
141137

142138
static char *__env[31] = {
@@ -258,35 +254,6 @@ char *kdbgetenv(const char *match)
258254
return NULL;
259255
}
260256

261-
/*
262-
* kdballocenv - This function is used to allocate bytes for
263-
* environment entries.
264-
* Parameters:
265-
* bytes The number of bytes to allocate in the static buffer.
266-
* Returns:
267-
* A pointer to the allocated space in the buffer on success.
268-
* NULL if bytes > size available in the envbuffer.
269-
* Remarks:
270-
* We use a static environment buffer (envbuffer) to hold the values
271-
* of dynamically generated environment variables (see kdb_set). Buffer
272-
* space once allocated is never free'd, so over time, the amount of space
273-
* (currently 512 bytes) will be exhausted if env variables are changed
274-
* frequently.
275-
*/
276-
static char *kdballocenv(size_t bytes)
277-
{
278-
#define KDB_ENVBUFSIZE 512
279-
static char envbuffer[KDB_ENVBUFSIZE];
280-
static int envbufsize;
281-
char *ep = NULL;
282-
283-
if ((KDB_ENVBUFSIZE - envbufsize) >= bytes) {
284-
ep = &envbuffer[envbufsize];
285-
envbufsize += bytes;
286-
}
287-
return ep;
288-
}
289-
290257
/*
291258
* kdbgetulenv - This function will return the value of an unsigned
292259
* long-valued environment variable.
@@ -348,9 +315,9 @@ static int kdb_setenv(const char *var, const char *val)
348315

349316
varlen = strlen(var);
350317
vallen = strlen(val);
351-
ep = kdballocenv(varlen + vallen + 2);
352-
if (ep == (char *)0)
353-
return KDB_ENVBUFFULL;
318+
ep = kmalloc(varlen + vallen + 2, GFP_KDB);
319+
if (!ep)
320+
return KDB_KMALLOCFAILED;
354321

355322
sprintf(ep, "%s=%s", var, val);
356323

@@ -359,6 +326,7 @@ static int kdb_setenv(const char *var, const char *val)
359326
&& ((strncmp(__env[i], var, varlen) == 0)
360327
&& ((__env[i][varlen] == '\0')
361328
|| (__env[i][varlen] == '=')))) {
329+
kfree_const(__env[i]);
362330
__env[i] = ep;
363331
return 0;
364332
}

0 commit comments

Comments
 (0)