[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAD=FV=WoS+WZ-OX5FnAUuab8re0ovrN9jEm4uADo1XmP5DAGQQ@mail.gmail.com>
Date: Mon, 3 Feb 2025 13:13:31 -0800
From: Doug Anderson <dianders@...omium.org>
To: Nir Lichtman <nir@...htman.org>
Cc: jason.wessel@...driver.com, danielt@...nel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] kdb: remove usage of static environment buffer
Hi,
On Mon, Feb 3, 2025 at 12:20 PM Nir Lichtman <nir@...htman.org> 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
Powered by blists - more mailing lists