public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] misc: eeprom/idt_89hpesx: Use devm_kmemdup to replace devm_kmalloc + memcpy
@ 2023-08-10 11:50 Li Zetao
  2023-08-11 15:30 ` Luca Ceresoli
  0 siblings, 1 reply; 2+ messages in thread
From: Li Zetao @ 2023-08-10 11:50 UTC (permalink / raw)
  To: arnd, gregkh, u.kleine-koenig, wsa+renesas, luca.ceresoli,
	jdelvare
  Cc: yuancan, lizetao1, linux-kernel

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>
---
 drivers/misc/eeprom/idt_89hpesx.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/eeprom/idt_89hpesx.c b/drivers/misc/eeprom/idt_89hpesx.c
index 740c06382b83..043762c3b033 100644
--- a/drivers/misc/eeprom/idt_89hpesx.c
+++ b/drivers/misc/eeprom/idt_89hpesx.c
@@ -1294,14 +1294,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;
-- 
2.34.1


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

* Re: [PATCH -next] misc: eeprom/idt_89hpesx: Use devm_kmemdup to replace devm_kmalloc + memcpy
  2023-08-10 11:50 [PATCH -next] misc: eeprom/idt_89hpesx: Use devm_kmemdup to replace devm_kmalloc + memcpy Li Zetao
@ 2023-08-11 15:30 ` Luca Ceresoli
  0 siblings, 0 replies; 2+ messages in thread
From: Luca Ceresoli @ 2023-08-11 15:30 UTC (permalink / raw)
  To: Li Zetao
  Cc: arnd, gregkh, u.kleine-koenig, wsa+renesas, jdelvare, yuancan,
	linux-kernel

On Thu, 10 Aug 2023 19:50:49 +0800
Li Zetao <lizetao1@huawei.com> wrote:

> 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>

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2023-08-11 15:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10 11:50 [PATCH -next] misc: eeprom/idt_89hpesx: Use devm_kmemdup to replace devm_kmalloc + memcpy Li Zetao
2023-08-11 15:30 ` Luca Ceresoli

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