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.

spi: ch341: fix devres lifetime

USB drivers bind to USB interfaces and any device managed resources
should have their lifetime tied to the interface rather than parent USB
device. This avoids issues like memory leaks when drivers are unbound
without their devices being physically disconnected (e.g. on probe
deferral or configuration changes).

Fix the controller and driver data lifetime so that they are released
on driver unbind.

Note that this also makes sure that the SPI controller is placed
correctly under the USB interface in the device tree.

Fixes: 8846739f52af ("spi: add ch341a usb2spi driver")
Cc: stable@vger.kernel.org # 6.11
Cc: Johannes Thumshirn <jth@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260327104305.1309915-3-johan@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Johan Hovold and committed by
Mark Brown
abe572f6 b99e3ddb

+3 -4
+3 -4
drivers/spi/spi-ch341.c
··· 152 152 if (ret) 153 153 return ret; 154 154 155 - ctrl = devm_spi_alloc_host(&udev->dev, sizeof(struct ch341_spi_dev)); 155 + ctrl = devm_spi_alloc_host(&intf->dev, sizeof(struct ch341_spi_dev)); 156 156 if (!ctrl) 157 157 return -ENOMEM; 158 158 ··· 163 163 ch341->read_pipe = usb_rcvbulkpipe(udev, usb_endpoint_num(in)); 164 164 165 165 ch341->rx_len = usb_endpoint_maxp(in); 166 - ch341->rx_buf = devm_kzalloc(&udev->dev, ch341->rx_len, GFP_KERNEL); 166 + ch341->rx_buf = devm_kzalloc(&intf->dev, ch341->rx_len, GFP_KERNEL); 167 167 if (!ch341->rx_buf) 168 168 return -ENOMEM; 169 169 ··· 171 171 if (!ch341->rx_urb) 172 172 return -ENOMEM; 173 173 174 - ch341->tx_buf = 175 - devm_kzalloc(&udev->dev, CH341_PACKET_LENGTH, GFP_KERNEL); 174 + ch341->tx_buf = devm_kzalloc(&intf->dev, CH341_PACKET_LENGTH, GFP_KERNEL); 176 175 if (!ch341->tx_buf) { 177 176 ret = -ENOMEM; 178 177 goto err_free_urb;