Re: [PATCH] kdb: remove usage of static environment buffer

From: Doug Anderson
Date: Mon Feb 03 2025 - 16:13:55 EST


Hi,

On Mon, Feb 3, 2025 at 12:20 PM Nir Lichtman <nir@xxxxxxxxxxxx> wrote:
>
> @@ -348,9 +315,12 @@ static int kdb_setenv(const char *var, const char *val)
>
> varlen = strlen(var);
> vallen = strlen(val);
> - ep = kdballocenv(varlen + vallen + 2);
> - if (ep == (char *)0)
> - return KDB_ENVBUFFULL;
> + ep = kmalloc(varlen + vallen + 2, GFP_KDB);
> + if (!ep) {
> + kdb_printf("Could not allocate space for the env var: %s\n",
> + var);

You don't need the printout. kmalloc is already very shouty if memory
allocations fail.


> + return KDB_KMALLOCFAILED;
> + }
>
> sprintf(ep, "%s=%s", var, val);
>
> @@ -359,6 +329,7 @@ static int kdb_setenv(const char *var, const char *val)
> && ((strncmp(__env[i], var, varlen) == 0)
> && ((__env[i][varlen] == '\0')
> || (__env[i][varlen] == '=')))) {
> + kfree(__env[i]);

I haven't tested it, but shouldn't the above be kfree_const() instead
of kfree()? Otherwise won't you be trying to kfree() the initial
strings? ...or am I missing something?


-Doug