Skip to contentSkip to conversation

drivers/hid/hid-thrustmaster.c:178 thrustmaster_interrupts() warn: possible memory leak of 'send_buf'

PATCH New Dan Carpenter 1 participant 1 message Mar 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 2060/2060 drivers/hid/hid-thrustmaster.c:178 thrustmaster_interrupts() warn: possible memory leak of 'send_buf'

tree:   https://gitee.com/openeuler/kernel.git OLK-6.6
head:   b28aab59b06935f0d1c9bce8f013f25b4094764d
commit: 477cfc70d964fafd811f91a889f14c356f937b8e [2060/2060] HID: hid-thrustmaster: Fix warning in thrustmaster_probe by adding endpoint check
config: x86_64-randconfig-161-20250326 (https://download.01.org/0day-ci/archive/20250327/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/hid/hid-thrustmaster.c:178 thrustmaster_interrupts() warn: possible memory leak of 'send_buf'

vim +/send_buf +178 drivers/hid/hid-thrustmaster.c

c49c33637802a2 Dario Pagani     2021-01-31  150  static void thrustmaster_interrupts(struct hid_device *hdev)
c49c33637802a2 Dario Pagani     2021-01-31  151  {
c49c33637802a2 Dario Pagani     2021-01-31  152  	int ret, trans, i, b_ep;
c49c33637802a2 Dario Pagani     2021-01-31  153  	u8 *send_buf = kmalloc(256, GFP_KERNEL);
c49c33637802a2 Dario Pagani     2021-01-31  154  	struct usb_host_endpoint *ep;
c49c33637802a2 Dario Pagani     2021-01-31  155  	struct device *dev = &hdev->dev;
c49c33637802a2 Dario Pagani     2021-01-31  156  	struct usb_interface *usbif = to_usb_interface(dev->parent);
c49c33637802a2 Dario Pagani     2021-01-31  157  	struct usb_device *usbdev = interface_to_usbdev(usbif);
c49c33637802a2 Dario Pagani     2021-01-31  158  
c49c33637802a2 Dario Pagani     2021-01-31  159  	if (!send_buf) {
c49c33637802a2 Dario Pagani     2021-01-31  160  		hid_err(hdev, "failed allocating send buffer\n");
c49c33637802a2 Dario Pagani     2021-01-31  161  		return;
c49c33637802a2 Dario Pagani     2021-01-31  162  	}
c49c33637802a2 Dario Pagani     2021-01-31  163  
fc3ef2e3297b3c Pavel Skripkin   2022-02-20  164  	if (usbif->cur_altsetting->desc.bNumEndpoints < 2) {
fc3ef2e3297b3c Pavel Skripkin   2022-02-20  165  		kfree(send_buf);
fc3ef2e3297b3c Pavel Skripkin   2022-02-20  166  		hid_err(hdev, "Wrong number of endpoints?\n");
fc3ef2e3297b3c Pavel Skripkin   2022-02-20  167  		return;
fc3ef2e3297b3c Pavel Skripkin   2022-02-20  168  	}
fc3ef2e3297b3c Pavel Skripkin   2022-02-20  169  
c49c33637802a2 Dario Pagani     2021-01-31  170  	ep = &usbif->cur_altsetting->endpoint[1];
c49c33637802a2 Dario Pagani     2021-01-31  171  	b_ep = ep->desc.bEndpointAddress;
c49c33637802a2 Dario Pagani     2021-01-31  172  
477cfc70d964fa Karol Przybylski 2024-12-05  173  	/* Are the expected endpoints present? */
477cfc70d964fa Karol Przybylski 2024-12-05  174  	u8 ep_addr[1] = {b_ep};
477cfc70d964fa Karol Przybylski 2024-12-05  175  
477cfc70d964fa Karol Przybylski 2024-12-05  176  	if (!usb_check_int_endpoints(usbif, ep_addr)) {
477cfc70d964fa Karol Przybylski 2024-12-05  177  		hid_err(hdev, "Unexpected non-int endpoint\n");

477cfc70d964fa Karol Przybylski 2024-12-05 @178 return;

kfree(send_buf);

477cfc70d964fa Karol Przybylski 2024-12-05  179  	}
477cfc70d964fa Karol Przybylski 2024-12-05  180  
c49c33637802a2 Dario Pagani     2021-01-31  181  	for (i = 0; i < ARRAY_SIZE(setup_arr); ++i) {
c49c33637802a2 Dario Pagani     2021-01-31  182  		memcpy(send_buf, setup_arr[i], setup_arr_sizes[i]);
c49c33637802a2 Dario Pagani     2021-01-31  183  
c49c33637802a2 Dario Pagani     2021-01-31  184  		ret = usb_interrupt_msg(usbdev,
c49c33637802a2 Dario Pagani     2021-01-31  185  			usb_sndintpipe(usbdev, b_ep),
c49c33637802a2 Dario Pagani     2021-01-31  186  			send_buf,
c49c33637802a2 Dario Pagani     2021-01-31  187  			setup_arr_sizes[i],
c49c33637802a2 Dario Pagani     2021-01-31  188  			&trans,
c49c33637802a2 Dario Pagani     2021-01-31  189  			USB_CTRL_SET_TIMEOUT);
c49c33637802a2 Dario Pagani     2021-01-31  190  
c49c33637802a2 Dario Pagani     2021-01-31  191  		if (ret) {
c49c33637802a2 Dario Pagani     2021-01-31  192  			hid_err(hdev, "setup data couldn't be sent\n");
c3800eed22d21c Evgeny Novikov   2021-07-30  193  			kfree(send_buf);
c49c33637802a2 Dario Pagani     2021-01-31  194  			return;
c49c33637802a2 Dario Pagani     2021-01-31  195  		}
c49c33637802a2 Dario Pagani     2021-01-31  196  	}
c49c33637802a2 Dario Pagani     2021-01-31  197  
c49c33637802a2 Dario Pagani     2021-01-31  198  	kfree(send_buf);
c49c33637802a2 Dario Pagani     2021-01-31  199  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki