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

media: media/tuners: 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>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Fuqian Huang and committed by
Mauro Carvalho Chehab
48059784 771560e5

+2 -4
+1 -2
drivers/media/tuners/tuner-xc2028.c
··· 381 381 goto corrupt; 382 382 } 383 383 384 - priv->firm[n].ptr = kzalloc(size, GFP_KERNEL); 384 + priv->firm[n].ptr = kmemdup(p, size, GFP_KERNEL); 385 385 if (priv->firm[n].ptr == NULL) { 386 386 tuner_err("Not enough memory to load firmware file.\n"); 387 387 rc = -ENOMEM; ··· 394 394 type, (unsigned long long)id, size); 395 395 } 396 396 397 - memcpy(priv->firm[n].ptr, p, size); 398 397 priv->firm[n].type = type; 399 398 priv->firm[n].id = id; 400 399 priv->firm[n].size = size;
+1 -2
drivers/media/tuners/xc4000.c
··· 812 812 goto corrupt; 813 813 } 814 814 815 - priv->firm[n].ptr = kzalloc(size, GFP_KERNEL); 815 + priv->firm[n].ptr = kmemdup(p, size, GFP_KERNEL); 816 816 if (priv->firm[n].ptr == NULL) { 817 817 printk(KERN_ERR "Not enough memory to load firmware file.\n"); 818 818 rc = -ENOMEM; ··· 826 826 type, (unsigned long long)id, size); 827 827 } 828 828 829 - memcpy(priv->firm[n].ptr, p, size); 830 829 priv->firm[n].type = type; 831 830 priv->firm[n].id = id; 832 831 priv->firm[n].size = size;