The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc()
@ 2025-03-17 12:21 Ethan Carter Edwards
  2025-03-17 12:21 ` [PATCH v2 1/4] " Ethan Carter Edwards
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-03-17 12:21 UTC (permalink / raw)
  To: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
	Jaroslav Kysela, Takashi Iwai
  Cc: gustavoars, linux-sound, linux-kernel, linux-hardening,
	Ethan Carter Edwards

Open coded arithmetic in allocator arguments is discouraged. Helper
functions like kcalloc or, in this case, devm_kcalloc are preferred. Not
only for readability purposes but safety purposes.

The changes move `devm_kzalloc(dev, sizeof(var) * n, GFP_KERNEL)` to
the helper function `devm_kcalloc(dev, n, sizeof(var), GFP_KERNEL)`.

Here is a series of four patches within the Intel/avs drivers that make
these changes. They are all compile tested only but should have no
effect on runtime behaviour.
    
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Link: https://github.com/KSPP/linux/issues/162

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
Changes in v2:
- change subjects to include avs
- change commit message to Replace devm_kzalloc() with devm_kcalloc
- Change from Link: to [1]:
- Link to v1: https://lore.kernel.org/r/20250314-sound-avs-kcalloc-v1-0-985f2734c020@ethancedwards.com

---
Ethan Carter Edwards (4):
      ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc()
      ASoC: Intel: avs: ssm4567: Replace devm_kzalloc() with devm_kcalloc()
      ASoC: Intel: avs: max98373: Replace devm_kzalloc() with devm_kcalloc()
      ASoC: Intel: avs: max98927: Replace devm_kzalloc() with devm_kcalloc()

 sound/soc/intel/avs/boards/max98373.c | 2 +-
 sound/soc/intel/avs/boards/max98927.c | 2 +-
 sound/soc/intel/avs/boards/ssm4567.c  | 2 +-
 sound/soc/intel/avs/pcm.c             | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
---
base-commit: da920b7df701770e006928053672147075587fb2
change-id: 20250314-sound-avs-kcalloc-91cedbc47074

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


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

* [PATCH v2 1/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc()
  2025-03-17 12:21 [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc() Ethan Carter Edwards
@ 2025-03-17 12:21 ` Ethan Carter Edwards
  2025-03-17 12:21 ` [PATCH v2 2/4] ASoC: Intel: avs: ssm4567: " Ethan Carter Edwards
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-03-17 12:21 UTC (permalink / raw)
  To: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
	Jaroslav Kysela, Takashi Iwai
  Cc: gustavoars, linux-sound, linux-kernel, linux-hardening,
	Ethan Carter Edwards

Open coded arithmetic in allocator arguments is discouraged [1]. Helper
functions like kcalloc or, in this case, devm_kcalloc are preferred.

[1]: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 sound/soc/intel/avs/pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/intel/avs/pcm.c b/sound/soc/intel/avs/pcm.c
index 4bfbcb5a5ae8aff5a981389e61afb3c72b07b15c..dac463390da135d7972808cb55e1c2866dd736c7 100644
--- a/sound/soc/intel/avs/pcm.c
+++ b/sound/soc/intel/avs/pcm.c
@@ -1380,7 +1380,7 @@ int avs_i2s_platform_register(struct avs_dev *adev, const char *name, unsigned l
 		for_each_set_bit(i, &port_mask, ssp_count)
 			cpu_count += hweight_long(tdms[i]);
 
-	cpus = devm_kzalloc(adev->dev, sizeof(*cpus) * cpu_count, GFP_KERNEL);
+	cpus = devm_kcalloc(adev->dev, cpu_count, sizeof(*cpus), GFP_KERNEL);
 	if (!cpus)
 		return -ENOMEM;
 

-- 
2.48.1


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

* [PATCH v2 2/4] ASoC: Intel: avs: ssm4567: Replace devm_kzalloc() with devm_kcalloc()
  2025-03-17 12:21 [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc() Ethan Carter Edwards
  2025-03-17 12:21 ` [PATCH v2 1/4] " Ethan Carter Edwards
@ 2025-03-17 12:21 ` Ethan Carter Edwards
  2025-03-17 12:21 ` [PATCH v2 3/4] ASoC: Intel: avs: max98373: " Ethan Carter Edwards
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-03-17 12:21 UTC (permalink / raw)
  To: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
	Jaroslav Kysela, Takashi Iwai
  Cc: gustavoars, linux-sound, linux-kernel, linux-hardening,
	Ethan Carter Edwards

Open coded arithmetic in allocator arguments is discouraged [1]. Helper
functions like kcalloc or, in this case, devm_kcalloc are preferred.

[1]: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 sound/soc/intel/avs/boards/ssm4567.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/intel/avs/boards/ssm4567.c b/sound/soc/intel/avs/boards/ssm4567.c
index c9d89bfe7178cd6acba0797c56e56462d7c41d8d..7667790d52739b98b97d2bc9fc9496da82affef1 100644
--- a/sound/soc/intel/avs/boards/ssm4567.c
+++ b/sound/soc/intel/avs/boards/ssm4567.c
@@ -97,7 +97,7 @@ static int avs_create_dai_link(struct device *dev, const char *platform_name, in
 	dl->name = devm_kasprintf(dev, GFP_KERNEL,
 				  AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot));
 	dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
-	dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs) * 2, GFP_KERNEL);
+	dl->codecs = devm_kcalloc(dev, 2, sizeof(*dl->codecs), GFP_KERNEL);
 	if (!dl->name || !dl->cpus || !dl->codecs)
 		return -ENOMEM;
 

-- 
2.48.1


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

* [PATCH v2 3/4] ASoC: Intel: avs: max98373: Replace devm_kzalloc() with devm_kcalloc()
  2025-03-17 12:21 [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc() Ethan Carter Edwards
  2025-03-17 12:21 ` [PATCH v2 1/4] " Ethan Carter Edwards
  2025-03-17 12:21 ` [PATCH v2 2/4] ASoC: Intel: avs: ssm4567: " Ethan Carter Edwards
@ 2025-03-17 12:21 ` Ethan Carter Edwards
  2025-03-17 12:21 ` [PATCH v2 4/4] ASoC: Intel: avs: max98927: " Ethan Carter Edwards
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-03-17 12:21 UTC (permalink / raw)
  To: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
	Jaroslav Kysela, Takashi Iwai
  Cc: gustavoars, linux-sound, linux-kernel, linux-hardening,
	Ethan Carter Edwards

Open coded arithmetic in allocator arguments is discouraged [1]. Helper
functions like kcalloc or, in this case, devm_kcalloc are preferred.

[1]: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 sound/soc/intel/avs/boards/max98373.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/intel/avs/boards/max98373.c b/sound/soc/intel/avs/boards/max98373.c
index 6f25e66344b7a4b46d6598619b6b1362cad8c39e..970f82bf4ce8920b1965a0b81e8623ab5bf91ef1 100644
--- a/sound/soc/intel/avs/boards/max98373.c
+++ b/sound/soc/intel/avs/boards/max98373.c
@@ -111,7 +111,7 @@ static int avs_create_dai_link(struct device *dev, const char *platform_name, in
 	dl->name = devm_kasprintf(dev, GFP_KERNEL,
 				  AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot));
 	dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
-	dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs) * 2, GFP_KERNEL);
+	dl->codecs = devm_kcalloc(dev, 2, sizeof(*dl->codecs), GFP_KERNEL);
 	if (!dl->name || !dl->cpus || !dl->codecs)
 		return -ENOMEM;
 

-- 
2.48.1


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

* [PATCH v2 4/4] ASoC: Intel: avs: max98927: Replace devm_kzalloc() with devm_kcalloc()
  2025-03-17 12:21 [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc() Ethan Carter Edwards
                   ` (2 preceding siblings ...)
  2025-03-17 12:21 ` [PATCH v2 3/4] ASoC: Intel: avs: max98373: " Ethan Carter Edwards
@ 2025-03-17 12:21 ` Ethan Carter Edwards
  2025-03-17 12:30 ` [PATCH v2 0/4] ASoC: Intel: avs: " Cezary Rojewski
  2025-03-18 16:28 ` Mark Brown
  5 siblings, 0 replies; 7+ messages in thread
From: Ethan Carter Edwards @ 2025-03-17 12:21 UTC (permalink / raw)
  To: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
	Jaroslav Kysela, Takashi Iwai
  Cc: gustavoars, linux-sound, linux-kernel, linux-hardening,
	Ethan Carter Edwards

Open coded arithmetic in allocator arguments is discouraged [1]. Helper
functions like kcalloc or, in this case, devm_kcalloc are preferred.

[1]: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
---
 sound/soc/intel/avs/boards/max98927.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/intel/avs/boards/max98927.c b/sound/soc/intel/avs/boards/max98927.c
index e8e5d1c717cd398aeca506bf7d20b5819d8dd1a2..e4ce553bf1d6432b4c11ce44857d969ca6b54c83 100644
--- a/sound/soc/intel/avs/boards/max98927.c
+++ b/sound/soc/intel/avs/boards/max98927.c
@@ -108,7 +108,7 @@ static int avs_create_dai_link(struct device *dev, const char *platform_name, in
 	dl->name = devm_kasprintf(dev, GFP_KERNEL,
 				  AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot));
 	dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
-	dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs) * 2, GFP_KERNEL);
+	dl->codecs = devm_kcalloc(dev, 2, sizeof(*dl->codecs), GFP_KERNEL);
 	if (!dl->name || !dl->cpus || !dl->codecs)
 		return -ENOMEM;
 

-- 
2.48.1


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

* Re: [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc()
  2025-03-17 12:21 [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc() Ethan Carter Edwards
                   ` (3 preceding siblings ...)
  2025-03-17 12:21 ` [PATCH v2 4/4] ASoC: Intel: avs: max98927: " Ethan Carter Edwards
@ 2025-03-17 12:30 ` Cezary Rojewski
  2025-03-18 16:28 ` Mark Brown
  5 siblings, 0 replies; 7+ messages in thread
From: Cezary Rojewski @ 2025-03-17 12:30 UTC (permalink / raw)
  To: Ethan Carter Edwards
  Cc: gustavoars, linux-sound, linux-kernel, linux-hardening,
	Liam Girdwood, Peter Ujfalusi, Bard Liao, Ranjani Sridharan,
	Kai Vehmanen, Pierre-Louis Bossart, Mark Brown, Jaroslav Kysela,
	Takashi Iwai

On 2025-03-17 1:21 PM, Ethan Carter Edwards wrote:
> Open coded arithmetic in allocator arguments is discouraged. Helper
> functions like kcalloc or, in this case, devm_kcalloc are preferred. Not
> only for readability purposes but safety purposes.
> 
> The changes move `devm_kzalloc(dev, sizeof(var) * n, GFP_KERNEL)` to
> the helper function `devm_kcalloc(dev, n, sizeof(var), GFP_KERNEL)`.
> 
> Here is a series of four patches within the Intel/avs drivers that make
> these changes. They are all compile tested only but should have no
> effect on runtime behaviour.
>      
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
> Link: https://github.com/KSPP/linux/issues/162
> 
> Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>

Thank you for addressing the review comments.

Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>

> ---
> Changes in v2:
> - change subjects to include avs
> - change commit message to Replace devm_kzalloc() with devm_kcalloc
> - Change from Link: to [1]:
> - Link to v1: https://lore.kernel.org/r/20250314-sound-avs-kcalloc-v1-0-985f2734c020@ethancedwards.com
> 
> ---
> Ethan Carter Edwards (4):
>        ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc()
>        ASoC: Intel: avs: ssm4567: Replace devm_kzalloc() with devm_kcalloc()
>        ASoC: Intel: avs: max98373: Replace devm_kzalloc() with devm_kcalloc()
>        ASoC: Intel: avs: max98927: Replace devm_kzalloc() with devm_kcalloc()
> 
>   sound/soc/intel/avs/boards/max98373.c | 2 +-
>   sound/soc/intel/avs/boards/max98927.c | 2 +-
>   sound/soc/intel/avs/boards/ssm4567.c  | 2 +-
>   sound/soc/intel/avs/pcm.c             | 2 +-
>   4 files changed, 4 insertions(+), 4 deletions(-)
> ---
> base-commit: da920b7df701770e006928053672147075587fb2
> change-id: 20250314-sound-avs-kcalloc-91cedbc47074
> 
> Best regards,


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

* Re: [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc()
  2025-03-17 12:21 [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc() Ethan Carter Edwards
                   ` (4 preceding siblings ...)
  2025-03-17 12:30 ` [PATCH v2 0/4] ASoC: Intel: avs: " Cezary Rojewski
@ 2025-03-18 16:28 ` Mark Brown
  5 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2025-03-18 16:28 UTC (permalink / raw)
  To: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart,
	Jaroslav Kysela, Takashi Iwai, Ethan Carter Edwards
  Cc: gustavoars, linux-sound, linux-kernel, linux-hardening

On Mon, 17 Mar 2025 08:21:55 -0400, Ethan Carter Edwards wrote:
> Open coded arithmetic in allocator arguments is discouraged. Helper
> functions like kcalloc or, in this case, devm_kcalloc are preferred. Not
> only for readability purposes but safety purposes.
> 
> The changes move `devm_kzalloc(dev, sizeof(var) * n, GFP_KERNEL)` to
> the helper function `devm_kcalloc(dev, n, sizeof(var), GFP_KERNEL)`.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc()
      commit: 6d9d66626c58bcd9b949574aca7d47149b8ad9e1
[2/4] ASoC: Intel: avs: ssm4567: Replace devm_kzalloc() with devm_kcalloc()
      commit: 61b1a1bddf7d166946d7ca7054b6cbced29b72f5
[3/4] ASoC: Intel: avs: max98373: Replace devm_kzalloc() with devm_kcalloc()
      commit: bde479694a7da7c127bb5bba98e2e4773f1d7951
[4/4] ASoC: Intel: avs: max98927: Replace devm_kzalloc() with devm_kcalloc()
      commit: 3602571baf9a6864bde89422d179e422a3ea4d8d

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

end of thread, other threads:[~2025-03-18 16:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 12:21 [PATCH v2 0/4] ASoC: Intel: avs: Replace devm_kzalloc() with devm_kcalloc() Ethan Carter Edwards
2025-03-17 12:21 ` [PATCH v2 1/4] " Ethan Carter Edwards
2025-03-17 12:21 ` [PATCH v2 2/4] ASoC: Intel: avs: ssm4567: " Ethan Carter Edwards
2025-03-17 12:21 ` [PATCH v2 3/4] ASoC: Intel: avs: max98373: " Ethan Carter Edwards
2025-03-17 12:21 ` [PATCH v2 4/4] ASoC: Intel: avs: max98927: " Ethan Carter Edwards
2025-03-17 12:30 ` [PATCH v2 0/4] ASoC: Intel: avs: " Cezary Rojewski
2025-03-18 16:28 ` Mark Brown

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