* [PATCH][next] um: Malloc just enough space for fitting pid file
@ 2024-10-26 3:46 Paulo Miguel Almeida
2024-10-26 7:44 ` Johannes Berg
0 siblings, 1 reply; 4+ messages in thread
From: Paulo Miguel Almeida @ 2024-10-26 3:46 UTC (permalink / raw)
To: richard, anton.ivanov, johannes, kees, tiwei.btw, linux-um,
linux-kernel
Cc: paulo.miguel.almeida.rodenas
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
Signed-off-by: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
---
arch/um/os-Linux/umid.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/um/os-Linux/umid.c b/arch/um/os-Linux/umid.c
index eb523ab1e218..513a2cce38db 100644
--- a/arch/um/os-Linux/umid.c
+++ b/arch/um/os-Linux/umid.c
@@ -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;
--
2.47.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH][next] um: Malloc just enough space for fitting pid file
2024-10-26 3:46 [PATCH][next] um: Malloc just enough space for fitting pid file Paulo Miguel Almeida
@ 2024-10-26 7:44 ` Johannes Berg
2024-10-26 7:59 ` Paulo Miguel Almeida
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2024-10-26 7:44 UTC (permalink / raw)
To: Paulo Miguel Almeida, richard, anton.ivanov, kees, tiwei.btw,
linux-um, linux-kernel
On Sat, 2024-10-26 at 16:46 +1300, Paulo Miguel Almeida wrote:
> 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
OK, I guess that's maybe all true, but can you say _why_ in the commit
log?
johannes
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][next] um: Malloc just enough space for fitting pid file
2024-10-26 7:44 ` Johannes Berg
@ 2024-10-26 7:59 ` Paulo Miguel Almeida
2024-10-26 8:03 ` Johannes Berg
0 siblings, 1 reply; 4+ messages in thread
From: Paulo Miguel Almeida @ 2024-10-26 7:59 UTC (permalink / raw)
To: Johannes Berg
Cc: richard, anton.ivanov, kees, tiwei.btw, linux-um, linux-kernel
On Sat, Oct 26, 2024 at 09:44:53AM +0200, Johannes Berg wrote:
Hi!
> On Sat, 2024-10-26 at 16:46 +1300, Paulo Miguel Almeida wrote:
> > 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
>
> OK, 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][next] um: Malloc just enough space for fitting pid file
2024-10-26 7:59 ` Paulo Miguel Almeida
@ 2024-10-26 8:03 ` Johannes Berg
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2024-10-26 8:03 UTC (permalink / raw)
To: Paulo Miguel Almeida
Cc: richard, anton.ivanov, kees, tiwei.btw, linux-um, linux-kernel
On Sat, 2024-10-26 at 20:59 +1300, Paulo Miguel Almeida wrote:
>
> 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.
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-26 8:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-26 3:46 [PATCH][next] um: Malloc just enough space for fitting pid file Paulo Miguel Almeida
2024-10-26 7:44 ` Johannes Berg
2024-10-26 7:59 ` Paulo Miguel Almeida
2024-10-26 8:03 ` Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox