Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: wm0010: Use kmemdup rather than duplicating its implementation

kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
Acked-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20190703163224.1029-1-huangfq.daxian@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Fuqian Huang and committed by
Mark Brown
c01db8b0 17212e71

+1 -3
+1 -3
sound/soc/codecs/wm0010.c
··· 515 515 dev_dbg(component->dev, "Downloading %zu byte stage 2 loader\n", fw->size); 516 516 517 517 /* Copy to local buffer first as vmalloc causes problems for dma */ 518 - img = kzalloc(fw->size, GFP_KERNEL | GFP_DMA); 518 + img = kmemdup(&fw->data[0], fw->size, GFP_KERNEL | GFP_DMA); 519 519 if (!img) { 520 520 ret = -ENOMEM; 521 521 goto abort2; ··· 526 526 ret = -ENOMEM; 527 527 goto abort1; 528 528 } 529 - 530 - memcpy(img, &fw->data[0], fw->size); 531 529 532 530 spi_message_init(&m); 533 531 memset(&t, 0, sizeof(t));