misc: eeprom/idt_89hpesx: Use devm_kmemdup to replace devm_kmalloc + memcpy
authorLi Zetao <lizetao1@huawei.com>
Thu, 10 Aug 2023 11:50:49 +0000 (19:50 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Aug 2023 19:38:52 +0000 (21:38 +0200)
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>
drivers/misc/eeprom/idt_89hpesx.c

index 433a4bc..1d1f30b 100644 (file)
@@ -1288,14 +1288,15 @@ static int idt_create_sysfs_files(struct idt_89hpesx_dev *pdev)
                return 0;
        }
 
-       /* Allocate memory for attribute file */
-       pdev->ee_file = devm_kmalloc(dev, sizeof(*pdev->ee_file), GFP_KERNEL);
+       /*
+        * Allocate memory for attribute file and copy the declared EEPROM attr
+        * structure to change some of fields
+        */
+       pdev->ee_file = devm_kmemdup(dev, &bin_attr_eeprom,
+                                    sizeof(*pdev->ee_file), GFP_KERNEL);
        if (!pdev->ee_file)
                return -ENOMEM;
 
-       /* Copy the declared EEPROM attr structure to change some of fields */
-       memcpy(pdev->ee_file, &bin_attr_eeprom, sizeof(*pdev->ee_file));
-
        /* In case of read-only EEPROM get rid of write ability */
        if (pdev->eero) {
                pdev->ee_file->attr.mode &= ~0200;