can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL
authorFrank Jungclaus <frank.jungclaus@esd.eu>
Thu, 16 Feb 2023 19:04:49 +0000 (20:04 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 16 Feb 2023 19:59:48 +0000 (20:59 +0100)
commit9684b000a86299b5968fef8ffbf1484def37452a
tree7485ee066b89fb807f5af8e443006c0096b262f3
parent118469f88180438ef43dee93d71f77c00e7b425d
can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL

Start a rework initiated by Vincents remarks "You should not report
the greatest of txerr and rxerr but the one which actually increased."
[1] and "As far as I understand, those flags should be set only when
the threshold is reached" [2] .

Therefore make use of can_change_state() to (among others) set the
flags CAN_ERR_CRTL_[RT]X_WARNING and CAN_ERR_CRTL_[RT]X_PASSIVE,
maintain CAN statistic counters for error_warning, error_passive and
bus_off.

Relocate testing alloc_can_err_skb() for NULL to the end of
esd_usb_rx_event(), to have things like can_bus_off(),
can_change_state() working even in out of memory conditions.

Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
Link: [1] https://lore.kernel.org/all/CAMZ6RqKGBWe15aMkf8-QLf-cOQg99GQBebSm+1wEzTqHgvmNuw@mail.gmail.com/
Link: [2] https://lore.kernel.org/all/CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com/
Link: https://lore.kernel.org/all/20230216190450.3901254-3-frank.jungclaus@esd.eu
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/esd_usb.c