Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: renesas_usbhs: use kzalloc_flex

Removes one allocation and one free by using a flexible array member.

Also added __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260311232043.18025-1-rosenp@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rosen Penev and committed by
Greg Kroah-Hartman
341434a4 a1678c4e

+3 -13
+3 -13
drivers/usb/renesas_usbhs/mod_gadget.c
··· 40 40 struct usb_gadget gadget; 41 41 struct usbhs_mod mod; 42 42 43 - struct usbhsg_uep *uep; 44 43 int uep_size; 45 44 46 45 struct usb_gadget_driver *driver; ··· 52 53 #define USBHSG_STATUS_WEDGE (1 << 2) 53 54 #define USBHSG_STATUS_SELF_POWERED (1 << 3) 54 55 #define USBHSG_STATUS_SOFT_CONNECT (1 << 4) 56 + struct usbhsg_uep uep[] __counted_by(uep_size); 55 57 }; 56 58 57 59 struct usbhsg_recip_handle { ··· 1084 1084 int i; 1085 1085 int ret; 1086 1086 1087 - gpriv = kzalloc_obj(struct usbhsg_gpriv); 1087 + gpriv = kzalloc_flex(*gpriv, uep, pipe_size); 1088 1088 if (!gpriv) 1089 1089 return -ENOMEM; 1090 1090 1091 - uep = kzalloc_objs(struct usbhsg_uep, pipe_size); 1092 - if (!uep) { 1093 - ret = -ENOMEM; 1094 - goto usbhs_mod_gadget_probe_err_gpriv; 1095 - } 1091 + gpriv->uep_size = pipe_size; 1096 1092 1097 1093 gpriv->transceiver = devm_usb_get_phy(dev, USB_PHY_TYPE_UNDEFINED); 1098 1094 dev_info(dev, "%stransceiver found\n", ··· 1111 1115 gpriv->mod.name = "gadget"; 1112 1116 gpriv->mod.start = usbhsg_start; 1113 1117 gpriv->mod.stop = usbhsg_stop; 1114 - gpriv->uep = uep; 1115 - gpriv->uep_size = pipe_size; 1116 1118 usbhsg_status_init(gpriv); 1117 1119 1118 1120 /* ··· 1169 1175 return 0; 1170 1176 1171 1177 err_add_udc: 1172 - kfree(gpriv->uep); 1173 - 1174 - usbhs_mod_gadget_probe_err_gpriv: 1175 1178 kfree(gpriv); 1176 1179 1177 1180 return ret; ··· 1180 1189 1181 1190 usb_del_gadget_udc(&gpriv->gadget); 1182 1191 1183 - kfree(gpriv->uep); 1184 1192 kfree(gpriv); 1185 1193 }