diff mbox series

[-next] scsi: ufs: Use kmemdup in ufshcd_read_string_desc()

Message ID 20190831124424.18642-1-yuehaibing@huawei.com (mailing list archive)
State Mainlined
Commit 5f57704dbcfe8ed718fc7cef0b1699c3aad7739c
Headers show
Series [-next] scsi: ufs: Use kmemdup in ufshcd_read_string_desc() | expand

Commit Message

Yue Haibing Aug. 31, 2019, 12:44 p.m. UTC
Use kmemdup rather than duplicating its implementation

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/scsi/ufs/ufshcd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Winkler, Tomas Aug. 31, 2019, 7:37 p.m. UTC | #1
> Use kmemdup rather than duplicating its implementation
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
LGTM, ACK.
Tomas
 
> ---
>  drivers/scsi/ufs/ufshcd.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index
> acf298da054c..6d5e2f5d8468 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -3309,12 +3309,11 @@ int ufshcd_read_string_desc(struct ufs_hba *hba,
> u8 desc_index,
>  		str[ret++] = '\0';
> 
>  	} else {
> -		str = kzalloc(uc_str->len, GFP_KERNEL);
> +		str = kmemdup(uc_str, uc_str->len, GFP_KERNEL);
>  		if (!str) {
>  			ret = -ENOMEM;
>  			goto out;
>  		}
> -		memcpy(str, uc_str, uc_str->len);
>  		ret = uc_str->len;
>  	}
>  out:
> 
>
Martin K. Petersen Sept. 7, 2019, 8:40 p.m. UTC | #2
YueHaibing,

> Use kmemdup rather than duplicating its implementation

Applied to 5.4/scsi-queue. Thanks!
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index acf298da054c..6d5e2f5d8468 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -3309,12 +3309,11 @@  int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
 		str[ret++] = '\0';
 
 	} else {
-		str = kzalloc(uc_str->len, GFP_KERNEL);
+		str = kmemdup(uc_str, uc_str->len, GFP_KERNEL);
 		if (!str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-		memcpy(str, uc_str, uc_str->len);
 		ret = uc_str->len;
 	}
 out: