diff mbox series

usb: isp1760: Use devm_kcalloc

Message ID 20240910072642.39396-1-zhangjiao2@cmss.chinamobile.com (mailing list archive)
State New
Headers show
Series usb: isp1760: Use devm_kcalloc | expand

Commit Message

zhangjiao2 Sept. 10, 2024, 7:26 a.m. UTC
From: zhang jiao <zhangjiao2@cmss.chinamobile.com>

Use devm_kcalloc to simplify code.

Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
 drivers/usb/isp1760/isp1760-hcd.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Greg KH Sept. 10, 2024, 9:04 a.m. UTC | #1
On Tue, Sep 10, 2024 at 03:26:42PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> Use devm_kcalloc to simplify code.

In what way?

Are you sure it's safe to do this?  How was this tested?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c
index 0e5e4cb74c87..593ce841ae53 100644
--- a/drivers/usb/isp1760/isp1760-hcd.c
+++ b/drivers/usb/isp1760/isp1760-hcd.c
@@ -2572,18 +2572,18 @@  int isp1760_hcd_register(struct isp1760_hcd *priv, struct resource *mem,
 
 	priv->hcd = hcd;
 
-	priv->atl_slots = kcalloc(mem_layout->slot_num,
+	priv->atl_slots = devm_kcalloc(dev, mem_layout->slot_num,
 				  sizeof(struct isp1760_slotinfo), GFP_KERNEL);
 	if (!priv->atl_slots) {
 		ret = -ENOMEM;
 		goto put_hcd;
 	}
 
-	priv->int_slots = kcalloc(mem_layout->slot_num,
+	priv->int_slots = devm_kcalloc(dev, mem_layout->slot_num,
 				  sizeof(struct isp1760_slotinfo), GFP_KERNEL);
 	if (!priv->int_slots) {
 		ret = -ENOMEM;
-		goto free_atl_slots;
+		goto put_hcd;
 	}
 
 	init_memory(priv);
@@ -2597,16 +2597,12 @@  int isp1760_hcd_register(struct isp1760_hcd *priv, struct resource *mem,
 
 	ret = usb_add_hcd(hcd, irq, irqflags);
 	if (ret)
-		goto free_int_slots;
+		goto put_hcd;
 
 	device_wakeup_enable(hcd->self.controller);
 
 	return 0;
 
-free_int_slots:
-	kfree(priv->int_slots);
-free_atl_slots:
-	kfree(priv->atl_slots);
 put_hcd:
 	usb_put_hcd(hcd);
 	return ret;
@@ -2619,6 +2615,4 @@  void isp1760_hcd_unregister(struct isp1760_hcd *priv)
 
 	usb_remove_hcd(priv->hcd);
 	usb_put_hcd(priv->hcd);
-	kfree(priv->atl_slots);
-	kfree(priv->int_slots);
 }