From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BAB7ECAAD1 for ; Thu, 1 Sep 2022 12:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233399AbiIAM3i (ORCPT ); Thu, 1 Sep 2022 08:29:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233493AbiIAM3U (ORCPT ); Thu, 1 Sep 2022 08:29:20 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 883521299CE for ; Thu, 1 Sep 2022 05:28:25 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id p7so13027027lfu.3 for ; Thu, 01 Sep 2022 05:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kvaser.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ObDdDFOLMCLX49e9Dz8m19/kfoj8bcT+DCUdtyONIzw=; b=pbMiNXjGILHP9JP6IoHUBh5JaJClDFgzOYOkq+FHgAMJPC+WQrj9lFT+YzBS80QyUZ L3drJYEcpmIlp2CNwwk/kw2gzAFHzfmq2W0Q9hh3n/hF639EGQeyQ8HVyiWaLOg1181H jG1BDjHpwDU6zi8hX2UgiLxZFHb2eATy02MWeJK8OdivXimpDDAQPrAEQjHhL739maXN dDPErH1nI9NiHLB20xL+/DuGi7YX3B2flGv/FeycLI+qM9DrmINroPVDYb3MYH1OI9zx QH+ZnE6UxIzUcMvDIs3AjxC3nQ7EYJqgH84ItLEh0i8HnkZEhHN1bYNHlIq37WsBRcgu rqmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ObDdDFOLMCLX49e9Dz8m19/kfoj8bcT+DCUdtyONIzw=; b=ewO5Vairp5+IKMNTkq/2j/Mub73ePAJPP3Cm/kgl6AYIwOvU6PDhk2GQo7+vFOeCvu nykoGpIb/aWQR0s41TPZTpTV0ACNTQo7RFyQe2D6VswhuxySgsqLYZjX1QPjrPZH10Rg vBuPLFZrVnhCt279LNYPOX5iaJcLk5Kh4uDVeqr7f9GIDRAmEEf13SAJfj+3i3q6M+wd nLK+gli+f6q7bosyrTM4kpia/J7paj8vVqoUiNKrUqtYUKD5Vx7LkEBV1unjzLK8PWTv +6Gdn9t2RkWg5sEhsCFlBzRht0iqO71dWSe98kvJ3cXx6+GDEApGR5t9aSIjPNKw66N2 yopQ== X-Gm-Message-State: ACgBeo08ivNqJEt78s44jeNPpKBFnTQlP3A7MfGh378cbHjAcd9yQiNJ IsR6cvIyTeA22leA0wACbIqkRewuxWs0jZ69 X-Google-Smtp-Source: AA6agR5PRnic4KG19yhUeJ82bF+mT2IoKUHiuYjNYtP5zHtTKG5Tem0vXZm9OjNX/WjkTZ6mlpGVDQ== X-Received: by 2002:a05:6512:2214:b0:494:85d0:f6c2 with SMTP id h20-20020a056512221400b0049485d0f6c2mr2779065lfu.493.1662035303096; Thu, 01 Sep 2022 05:28:23 -0700 (PDT) Received: from fb10a0c5d590.. (h-155-4-68-234.A785.priv.bahnhof.se. [155.4.68.234]) by smtp.gmail.com with ESMTPSA id s12-20020a056512202c00b00492c2394ea5sm125935lfs.165.2022.09.01.05.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 05:28:22 -0700 (PDT) From: Jimmy Assarsson To: linux-can@vger.kernel.org, Marc Kleine-Budde , Anssi Hannula Cc: Jimmy Assarsson , stable@vger.kernel.org, Jimmy Assarsson Subject: [PATCH v3 03/15] can: kvaser_usb: Fix possible completions during init_completion Date: Thu, 1 Sep 2022 14:27:17 +0200 Message-Id: <20220901122729.271-4-extja@kvaser.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220901122729.271-1-extja@kvaser.com> References: <20220901122729.271-1-extja@kvaser.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-can@vger.kernel.org From: Anssi Hannula 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. Cc: stable@vger.kernel.org Fixes: 080f40a6fa28 ("can: kvaser_usb: Add support for Kvaser CAN/USB devices") Tested-by: Jimmy Assarsson Signed-off-by: Anssi Hannula Signed-off-by: Jimmy Assarsson --- Changes in v3: - Rebased on 1d5eeda23f36 ("can: kvaser_usb: advertise timestamping capabilities and add ioctl support") - Add stable to CC - Add S-o-b Changes in v2: - Rebased on b3b6df2c56d8 ("can: kvaser_usb: kvaser_usb_leaf: fix bittiming limits") drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 4 ++-- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c index 3dcd35979e6f..3abfaa77e893 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c @@ -1875,7 +1875,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); @@ -1893,7 +1893,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() diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index 8e11cda85624..9683bc5e8257 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -1320,7 +1320,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); @@ -1338,7 +1338,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); -- 2.37.3