]> git.baikalelectronics.ru Git - kernel.git/commitdiff
can: kvaser_usb: Fix possible completions during init_completion
authorAnssi Hannula <anssi.hannula@bitwise.fi>
Mon, 10 Oct 2022 18:52:27 +0000 (20:52 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Nov 2022 14:56:53 +0000 (23:56 +0900)
commit 9975e58d217bbdf08d8e1ba2b61703a61c3c02e5 upstream.

kvaser_usb uses completions to signal when a response event is received
for outgoing commands.

However, it uses init_completion() to reinitialize the start_comp and
stop_comp completions before sending the start/stop commands.

In case the device sends the corresponding response just before the
actual command is sent, complete() may be called concurrently with
init_completion() which is not safe.

This might be triggerable even with a properly functioning device by
stopping the interface (CMD_STOP_CHIP) just after it goes bus-off (which
also causes the driver to send CMD_STOP_CHIP when restart-ms is off),
but that was not tested.

Fix the issue by using reinit_completion() instead.

Fixes: d9f21bf91c45 ("can: kvaser_usb: Add support for Kvaser CAN/USB devices")
Tested-by: Jimmy Assarsson <extja@kvaser.com>
Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
Link: https://lore.kernel.org/all/20221010185237.319219-2-extja@kvaser.com
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c

index 5d642458bac547f1c9823b9eacda5e4dceb7d9d4..45d27872488395c09b78bae8e05a0227ce7957a9 100644 (file)
@@ -1845,7 +1845,7 @@ static int kvaser_usb_hydra_start_chip(struct kvaser_usb_net_priv *priv)
 {
        int err;
 
-       init_completion(&priv->start_comp);
+       reinit_completion(&priv->start_comp);
 
        err = kvaser_usb_hydra_send_simple_cmd(priv->dev, CMD_START_CHIP_REQ,
                                               priv->channel);
@@ -1863,7 +1863,7 @@ static int kvaser_usb_hydra_stop_chip(struct kvaser_usb_net_priv *priv)
 {
        int err;
 
-       init_completion(&priv->stop_comp);
+       reinit_completion(&priv->stop_comp);
 
        /* Make sure we do not report invalid BUS_OFF from CMD_CHIP_STATE_EVENT
         * see comment in kvaser_usb_hydra_update_state()
index 78d52a5e8fd5d80c4c64ac720dc94a6989634218..15380cc08ee69ad72317b7d1fb0d3f350b473d40 100644 (file)
@@ -1324,7 +1324,7 @@ static int kvaser_usb_leaf_start_chip(struct kvaser_usb_net_priv *priv)
 {
        int err;
 
-       init_completion(&priv->start_comp);
+       reinit_completion(&priv->start_comp);
 
        err = kvaser_usb_leaf_send_simple_cmd(priv->dev, CMD_START_CHIP,
                                              priv->channel);
@@ -1342,7 +1342,7 @@ static int kvaser_usb_leaf_stop_chip(struct kvaser_usb_net_priv *priv)
 {
        int err;
 
-       init_completion(&priv->stop_comp);
+       reinit_completion(&priv->stop_comp);
 
        err = kvaser_usb_leaf_send_simple_cmd(priv->dev, CMD_STOP_CHIP,
                                              priv->channel);