Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: ctxfi: change dao_set_input functions from kzalloc to kcalloc
@ 2025-03-08 18:52 Ethan Carter Edwards
  2025-03-08 19:10 ` Markus Elfring
  2025-03-10 10:28 ` Takashi Iwai
  0 siblings, 2 replies; 3+ messages in thread
From: Ethan Carter Edwards @ 2025-03-08 18:52 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, linux-sound, linux-kernel, linux-hardening,
	Ethan Carter Edwards

We are trying to get rid of all multiplications from allocation
functions to prevent potential integer overflows. Here the
multiplication is probably safe, but using kcalloc() is more
appropriate and improves readability. This patch has no effect
on runtime behavior.

Link: https://github.com/KSPP/linux/issues/162 [1]
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 sound/pci/ctxfi/ctdaio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index 9993b02d2968c6c6858475f7ab98d4e90e7ffe2a..806c4d7543877ed74f8ec2dd894cf6b76af6f314 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -159,7 +159,7 @@ static int dao_set_left_input(struct dao *dao, struct rsc *input)
 	struct daio *daio = &dao->daio;
 	int i;
 
-	entry = kzalloc((sizeof(*entry) * daio->rscl.msr), GFP_KERNEL);
+	entry = kcalloc(daio->rscl.msr, sizeof(*entry), GFP_KERNEL);
 	if (!entry)
 		return -ENOMEM;
 
@@ -188,7 +188,7 @@ static int dao_set_right_input(struct dao *dao, struct rsc *input)
 	struct daio *daio = &dao->daio;
 	int i;
 
-	entry = kzalloc((sizeof(*entry) * daio->rscr.msr), GFP_KERNEL);
+	entry = kcalloc(daio->rscr.msr, sizeof(*entry), GFP_KERNEL);
 	if (!entry)
 		return -ENOMEM;
 

---
base-commit: 0a2f889128969dab41861b6e40111aa03dc57014
change-id: 20250308-ctdaio-kzalloc-fcf47b8c4f74

Best regards,
-- 
Ethan Carter Edwards <ethan@ethancedwards.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: ctxfi: change dao_set_input functions from kzalloc to kcalloc
  2025-03-08 18:52 [PATCH] ALSA: ctxfi: change dao_set_input functions from kzalloc to kcalloc Ethan Carter Edwards
@ 2025-03-08 19:10 ` Markus Elfring
  2025-03-10 10:28 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-03-08 19:10 UTC (permalink / raw)
  To: Ethan Carter Edwards, linux-sound, linux-hardening
  Cc: LKML, Jaroslav Kysela, Takashi Iwai

> We are trying to get rid of all multiplications from allocation
…

Please improve such a change description another bit.

See also:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14-rc5#n94

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: ctxfi: change dao_set_input functions from kzalloc to kcalloc
  2025-03-08 18:52 [PATCH] ALSA: ctxfi: change dao_set_input functions from kzalloc to kcalloc Ethan Carter Edwards
  2025-03-08 19:10 ` Markus Elfring
@ 2025-03-10 10:28 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2025-03-10 10:28 UTC (permalink / raw)
  To: Ethan Carter Edwards
  Cc: Takashi Iwai, Jaroslav Kysela, linux-sound, linux-kernel,
	linux-hardening

On Sat, 08 Mar 2025 19:52:59 +0100,
Ethan Carter Edwards wrote:
> 
> We are trying to get rid of all multiplications from allocation
> functions to prevent potential integer overflows. Here the
> multiplication is probably safe, but using kcalloc() is more
> appropriate and improves readability. This patch has no effect
> on runtime behavior.
> 
> Link: https://github.com/KSPP/linux/issues/162 [1]
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> 
> Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>

Thanks, applied now.


Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-10 10:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-08 18:52 [PATCH] ALSA: ctxfi: change dao_set_input functions from kzalloc to kcalloc Ethan Carter Edwards
2025-03-08 19:10 ` Markus Elfring
2025-03-10 10:28 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox