Re: [PATCH 6/6] can: esd_usb: Avoid errors triggered from USB disconnect
From: Stefan Mätje <stefan.maetje@esd.eu>
Date: 2025-08-16 13:11:11
Also in:
linux-can
Am Mittwoch, dem 13.08.2025 um 10:09 +0200 schrieb Marc Kleine-Budde:
On 11.08.2025 23:06:11, Stefan Mätje wrote:quoted
The USB stack calls during disconnect the esd_usb_disconnect() callback. esd_usb_disconnect() calls netdev_unregister() for each network which in turn calls the net_device_ops::ndo_stop callback esd_usb_close() if the net device is up. The esd_usb_close() callback tries to disable all CAN Ids and to reset the CAN controller of the device sending appropriate control messages. Sending these messages in .disconnect() is moot and always fails because either the device is gone or the USB communication is already torn down by the USB stack in the course of a rmmod operation. This patch moves the code that sends these control messages to a new function esd_usb_stop() which is approximately the counterpart of esd_usb_start() to make code structure less convoluted. It then changes esd_usb_close() not to send the control messages at all if the ndo_stop() callback is executed from the USB .disconnect() callback. A new flag in_usb_disconnect is added to the struct esd_usb device structure to mark this condition which is checked by esd_usb_close() whether to skip the send operations in esd_usb_start().I cannot find the reference anymore, but I remember that Greg said, that USB devices should just be quiet when being unplugged. I removed the error prints from the gs_usb's close function, see: 5c6c313acdfc ("can: gs_usb: gs_can_close(): don't complain about failed device reset during ndo_stop")
Hello Marc, I think this patch fulfills the requirement not to print (bogus) error messages during device disconnnect. This is the purpose of the patch. It does this by not trying to communicate with the device during USB disconnect at all. Therefore no error messages can be triggered. On the other hand I would like to bring the device in an idle state during "ip link set down" going through ndo_stop(). In this case the USB communication should still be ok and any errors should be printed in my opinion. What do you think? Stefan