um: Malloc just enough space for fitting pid file
PATCH 1/1 um: Malloc just enough space for fitting pid file
umid is already generated during make_umid_init __initcall so there is no need to allocate UMID_LEN bytes to accommodate the max possible name for the umid segment of the filepath
This patch replaces UMID_LEN occurences in which it's redundant
--- arch/um/os-Linux/umid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/os-Linux/umid.c +2 -2
@@ -212,7 +212,7 @@ static void __init create_pid_file(void)char pid[sizeof ("nnnnnnnnn" )], *file;int fd, n; - n =strlen (uml_dir) +UMID_LEN +sizeof ("/pid" ); + n =strlen (uml_dir) +strlen (umid) +sizeof ("/pid" ); file =malloc (n);if (!file)return ;
@@ -394,7 +394,7 @@ static void remove_umid_dir(void) {char *dir, err; - dir =malloc (strlen (uml_dir) +UMID_LEN +1 ); + dir =malloc (strlen (uml_dir) +strlen (umid) +1 );if (!dir)return ;
Signature · 1 line
2.47.0
Johannes Berg
maintainerQuoted 5 lines · Paulo Miguel Almeida
umid is already generated during
make_umid_init__initcallso there is no need to allocateUMID_LENbytes to accommodate the max possible name for the umid segment of the filepathThis patch replaces
UMID_LENoccurences in which it's redundant
OK, I guess that's maybe all true, but can you say _why_ in the commit log?
johannes
On Sat, Oct 26, 2024 at 09:44:53AM +0200, Johannes Berg wrote:
Hi!
Quoted 5 lines · Paulo Miguel Almeida
Quoted 4 lines
umid is already generated during
make_umid_init__initcallso there is no need to allocateUMID_LENbytes to accommodate the max possible name for the umid segment of the filepath
Quoted 7 lines
Quoted 1 line
This patch replaces
UMID_LENoccurences in which it's redundantOK, I guess that's maybe all true, but can you say _why_ in the commit log?
johannes
thanks for taking the time to review this patch. :-)
when I said that "umid is already generated during make_umid_init __initcall", from my humble point of view, I was explaining the 'why' using UMID_LEN for calculation buffer sizes was redundant. Then again, once we know the size of char* umid, we can use strlen(umid) instead.
I'm happy to amend the commit message to a better one but I'm not sure if I got 100% what I'm missing.
- Paulo
Johannes Berg
maintainerQuoted 5 lines · Paulo Miguel Almeida
when I said that "umid is already generated during
make_umid_init__initcall", from my humble point of view, I was explaining the 'why' usingUMID_LENfor calculation buffer sizes was redundant. Then again, once we know the size of char* umid, we can use strlen(umid) instead.
That's not "why am I changing it" though, that's "why does it work".
The only reasonable explanation I could come up with is that you're trying to save memory ... but why go to the trouble for a function that's called exactly once?
johannes