lkml.org 
[lkml]   [2019]   [Jul]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 23/35] scsi: Use kmemdup rather than duplicating its implementation
Date
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>
---
Changes in v2:
- Fix a typo in commit message (memset -> memcpy)

drivers/scsi/myrb.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
index 539ac8ce4fcd..5e6b5e7ae93a 100644
--- a/drivers/scsi/myrb.c
+++ b/drivers/scsi/myrb.c
@@ -1658,14 +1658,12 @@ static int myrb_ldev_slave_alloc(struct scsi_device *sdev)
if (!ldev_info)
return -ENXIO;

- sdev->hostdata = kzalloc(sizeof(*ldev_info), GFP_KERNEL);
+ sdev->hostdata = kmemdup(ldev_info, sizeof(*ldev_info), GFP_KERNEL);
if (!sdev->hostdata)
return -ENOMEM;
dev_dbg(&sdev->sdev_gendev,
"slave alloc ldev %d state %x\n",
ldev_num, ldev_info->state);
- memcpy(sdev->hostdata, ldev_info,
- sizeof(*ldev_info));
switch (ldev_info->raid_level) {
case MYRB_RAID_LEVEL0:
level = RAID_LEVEL_LINEAR;
--
2.11.0
\
 
 \ /
  Last update: 2019-07-03 18:30    [W:0.022 / U:1.960 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site