[PATCH 21/30] usb: Use kmemdup rather than duplicating its implementation
From: Fuqian Huang
Date: Wed Jul 03 2019 - 09:17:17 EST
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memset, 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 + memset.
Signed-off-by: Fuqian Huang <huangfq.daxian@xxxxxxxxx>
---
drivers/usb/class/cdc-acm.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 183b41753c98..cc4a96d59ffc 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1410,12 +1410,11 @@ static int acm_probe(struct usb_interface *intf,
struct usb_cdc_country_functional_desc * cfd =
h.usb_cdc_country_functional_desc;
- acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
+ acm->country_codes = kmemdup((u8 *)&cfd->wCountyCode0,
+ cfd->bLength - 4, GFP_KERNEL);
if (!acm->country_codes)
goto skip_countries;
acm->country_code_size = cfd->bLength - 4;
- memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
- cfd->bLength - 4);
acm->country_rel_date = cfd->iCountryCodeRelDate;
i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
--
2.11.0