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

misc: eeprom/idt_89hpesx: Use devm_kmemdup to replace devm_kmalloc + memcpy

Use the helper function devm_kmemdup() rather than duplicating its
implementation, which helps to enhance code readability.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://lore.kernel.org/r/20230810115049.2104099-1-lizetao1@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Li Zetao and committed by
Greg Kroah-Hartman
60df28ac 183238ff

+6 -5
+6 -5
drivers/misc/eeprom/idt_89hpesx.c
··· 1288 1288 return 0; 1289 1289 } 1290 1290 1291 - /* Allocate memory for attribute file */ 1292 - pdev->ee_file = devm_kmalloc(dev, sizeof(*pdev->ee_file), GFP_KERNEL); 1291 + /* 1292 + * Allocate memory for attribute file and copy the declared EEPROM attr 1293 + * structure to change some of fields 1294 + */ 1295 + pdev->ee_file = devm_kmemdup(dev, &bin_attr_eeprom, 1296 + sizeof(*pdev->ee_file), GFP_KERNEL); 1293 1297 if (!pdev->ee_file) 1294 1298 return -ENOMEM; 1295 - 1296 - /* Copy the declared EEPROM attr structure to change some of fields */ 1297 - memcpy(pdev->ee_file, &bin_attr_eeprom, sizeof(*pdev->ee_file)); 1298 1299 1299 1300 /* In case of read-only EEPROM get rid of write ability */ 1300 1301 if (pdev->eero) {