* [PATCH -next v2] ALSA: pcm: replace simple_strtoul to kstrtoul
@ 2024-08-31 8:06 Hongbo Li
2024-08-31 10:58 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Hongbo Li @ 2024-08-31 8:06 UTC (permalink / raw)
To: perex, tiwai; +Cc: lihongbo22, linux-sound
As mentioned in [1], "...simple_strtol(), simple_strtoll(),
simple_strtoul(), and simple_strtoull() functions explicitly
ignore overflows, which may lead to unexpected results in callers."
Hence, the use of those functions is discouraged.
This patch replace the use of the simple_strtoul with the safer
alternatives kstrtoul.
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
v2:
- Avoid introducing the ret variable, suggested by Takashi.
v1: https://lore.kernel.org/all/1e4bee4b-023c-40e2-ac4a-f71299fa2efd@huawei.com/T/
---
sound/core/pcm_memory.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c
index 8e4c68e3bbd0..73d4fc49a0ca 100644
--- a/sound/core/pcm_memory.c
+++ b/sound/core/pcm_memory.c
@@ -193,7 +193,10 @@ static void snd_pcm_lib_preallocate_proc_write(struct snd_info_entry *entry,
}
if (!snd_info_get_line(buffer, line, sizeof(line))) {
snd_info_get_str(str, line, sizeof(str));
- size = simple_strtoul(str, NULL, 10) * 1024;
+ buffer->error = kstrtoul(str, 10, &size);
+ if (buffer->error != 0)
+ return;
+ size *= 1024;
if ((size != 0 && size < 8192) || size > substream->dma_max) {
buffer->error = -EINVAL;
return;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH -next v2] ALSA: pcm: replace simple_strtoul to kstrtoul
2024-08-31 8:06 [PATCH -next v2] ALSA: pcm: replace simple_strtoul to kstrtoul Hongbo Li
@ 2024-08-31 10:58 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-08-31 10:58 UTC (permalink / raw)
To: Hongbo Li; +Cc: perex, tiwai, linux-sound
On Sat, 31 Aug 2024 10:06:39 +0200,
Hongbo Li wrote:
>
> As mentioned in [1], "...simple_strtol(), simple_strtoll(),
> simple_strtoul(), and simple_strtoull() functions explicitly
> ignore overflows, which may lead to unexpected results in callers."
> Hence, the use of those functions is discouraged.
>
> This patch replace the use of the simple_strtoul with the safer
> alternatives kstrtoul.
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull
>
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
>
> ---
> v2:
> - Avoid introducing the ret variable, suggested by Takashi.
>
> v1: https://lore.kernel.org/all/1e4bee4b-023c-40e2-ac4a-f71299fa2efd@huawei.com/T/
Applied now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-31 10:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-31 8:06 [PATCH -next v2] ALSA: pcm: replace simple_strtoul to kstrtoul Hongbo Li
2024-08-31 10:58 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox