mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] ASoC: SOF: topology: Use kmemdup_array instead of kmemdup for multiple allocation
@ 2024-08-26  5:44 Shen Lichuan
  2024-08-26 18:35 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Shen Lichuan @ 2024-08-26  5:44 UTC (permalink / raw)
  To: pierre-louis.bossart, lgirdwood, peter.ujfalusi, yung-chuan.liao,
	ranjani.sridharan, daniel.baluta, broonie, perex, tiwai
  Cc: kai.vehmanen, sound-open-firmware, linux-sound, linux-kernel,
	opensource.kernel, Shen Lichuan

Let the kmemdup_array() take care about multiplication
and possible overflows.

Using kmemdup_array() is more appropriate and makes the code
easier to audit.

Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
---
 sound/soc/sof/topology.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index b54382131991..996c3234eaee 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -1349,7 +1349,7 @@ static int sof_parse_pin_binding(struct snd_sof_widget *swidget,
 
 	/* copy pin binding array to swidget only if it is defined in topology */
 	if (pin_binding[0]) {
-		pb = kmemdup(pin_binding, num_pins * sizeof(char *), GFP_KERNEL);
+		pb = kmemdup_array(pin_binding, num_pins, sizeof(char *), GFP_KERNEL);
 		if (!pb) {
 			ret = -ENOMEM;
 			goto err;
@@ -1889,9 +1889,9 @@ static int sof_link_load(struct snd_soc_component *scomp, int index, struct snd_
 		return -ENOMEM;
 
 	slink->num_hw_configs = le32_to_cpu(cfg->num_hw_configs);
-	slink->hw_configs = kmemdup(cfg->hw_config,
-				    sizeof(*slink->hw_configs) * slink->num_hw_configs,
-				    GFP_KERNEL);
+	slink->hw_configs = kmemdup_array(cfg->hw_config,
+					  slink->num_hw_configs, sizeof(*slink->hw_configs),
+					  GFP_KERNEL);
 	if (!slink->hw_configs) {
 		kfree(slink);
 		return -ENOMEM;
-- 
2.17.1


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

* Re: [PATCH v1] ASoC: SOF: topology: Use kmemdup_array instead of kmemdup for multiple allocation
  2024-08-26  5:44 [PATCH v1] ASoC: SOF: topology: Use kmemdup_array instead of kmemdup for multiple allocation Shen Lichuan
@ 2024-08-26 18:35 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2024-08-26 18:35 UTC (permalink / raw)
  To: pierre-louis.bossart, lgirdwood, peter.ujfalusi, yung-chuan.liao,
	ranjani.sridharan, daniel.baluta, perex, tiwai, Shen Lichuan
  Cc: kai.vehmanen, sound-open-firmware, linux-sound, linux-kernel,
	opensource.kernel

On Mon, 26 Aug 2024 13:44:02 +0800, Shen Lichuan wrote:
> Let the kmemdup_array() take care about multiplication
> and possible overflows.
> 
> Using kmemdup_array() is more appropriate and makes the code
> easier to audit.
> 
> 
> [...]

Applied to

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

Thanks!

[1/1] ASoC: SOF: topology: Use kmemdup_array instead of kmemdup for multiple allocation
      commit: 69a8d0edb9d78bb5515133b7c08f399d6eaff37a

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] 2+ messages in thread

end of thread, other threads:[~2024-08-26 18:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-26  5:44 [PATCH v1] ASoC: SOF: topology: Use kmemdup_array instead of kmemdup for multiple allocation Shen Lichuan
2024-08-26 18:35 ` Mark Brown

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

all inboxes | Powered by JetHome®