Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp754680rwb; Mon, 26 Sep 2022 05:34:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7kqxv2UfEbmJTT7j41yoIQOeo8bk1VbLAWBl/mQ9BiVXUZxVWuBHX9+jccikJyztVZNo70 X-Received: by 2002:a17:907:3f85:b0:733:3f0e:2f28 with SMTP id hr5-20020a1709073f8500b007333f0e2f28mr17406034ejc.376.1664195654911; Mon, 26 Sep 2022 05:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664195654; cv=none; d=google.com; s=arc-20160816; b=QEGovO7I02FI8EQJP3lbkNn2CuWN985yYjNFwCsWdINZv5rfs9EEsZ+YW/KHGCav9E lt+7WLDVnXDDEGXH6TbMHoBfaF1bgJMVffJnwA77EJxgZ8lrLYoZBN38pxsgtIzrdQIc i+UZALJ6F/6EOkbAg0o54fpSRtoQLrjhdhQNB1NdhXfa+1A1ehffVVrb2WPkvIrd0kXg E1ILqhK+3EnW4yjOZI8GLeh8dtAbQJutN3fW1QKA6ISh1A6z5gr6ACV52LHqqX2t5vl0 MexUmiVRpr940Udu/2BfVHj7YBIxYWlBTkDo4oINNi1xGxBima989vqbv/BjN4MhE7OU GDhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7hw1gRTIkh5r9UTYoqs6iQFIzq3/9Eys6xRESDe/yVI=; b=yvqwzMFPEzWtVVjwwLOrbwFhW93Wg8ZF28pIKEKFwg0ekhRWM5udc+TAIQT4XdQdS0 eTqaBAUPMx8k6UZlMBpAEztnXQvL40H1lsyQoxQyEp8AUwBPaG/AnK/TvYvQEzdiO5ap +88Px36ErWKV69IEReI0HCLZAU8ayunjHTzSYiSRnynyiv1JcebC6x9RnnLViXtJ9+2Z IidWciD4QkOPUK+h5TwbYdcXsgyleNH7Ko5v4GBoLg9jwsGm+MDAGjco2NZBuPSYsOa9 ElnqfViybxYlv2dQ3jj02oo/ZG3Ty4kTE4CIkEX88XU394+Ej3VA+U0fnxEqWpyPnXR9 c2KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C3NN1oQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eg42-20020a05640228aa00b00457563c4196si1828115edb.595.2022.09.26.05.33.49; Mon, 26 Sep 2022 05:34:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C3NN1oQh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235717AbiIZKby (ORCPT + 99 others); Mon, 26 Sep 2022 06:31:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235853AbiIZK3Z (ORCPT ); Mon, 26 Sep 2022 06:29:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B024F1A3; Mon, 26 Sep 2022 03:19:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 53395B8092B; Mon, 26 Sep 2022 10:19:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4ABAC433D7; Mon, 26 Sep 2022 10:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187562; bh=ymJG0BjZD0x8Z2sX6CSifbF+Ybf81aI2fY5y2fBtQcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C3NN1oQhxYNeth8wX20CknnydicgyZtLpk+8G+81blmb9bfZhuByjs7XyomNaA9il FghQWaInmj52mWGBlRhFeehI+OCMNwhuGgnsjCFxMrjda3KbFxbJSuaPZ2MAvacTR7 c/Z5fxcABAsCydkFe8sd4HUamj1G383zfM72uRew= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Kleine-Budde , Sasha Levin Subject: [PATCH 4.19 46/58] can: gs_usb: gs_can_open(): fix race dev->can.state condition Date: Mon, 26 Sep 2022 12:12:05 +0200 Message-Id: <20220926100743.135293511@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100741.430882406@linuxfoundation.org> References: <20220926100741.430882406@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Kleine-Budde [ Upstream commit 5440428b3da65408dba0241985acb7a05258b85e ] The dev->can.state is set to CAN_STATE_ERROR_ACTIVE, after the device has been started. On busy networks the CAN controller might receive CAN frame between and go into an error state before the dev->can.state is assigned. Assign dev->can.state before starting the controller to close the race window. Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices") Link: https://lore.kernel.org/all/20220920195216.232481-1-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/usb/gs_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index 2101b2fab7df..62ca4964a863 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -686,6 +686,7 @@ static int gs_can_open(struct net_device *netdev) flags |= GS_CAN_MODE_TRIPLE_SAMPLE; /* finally start device */ + dev->can.state = CAN_STATE_ERROR_ACTIVE; dm->mode = cpu_to_le32(GS_CAN_MODE_START); dm->flags = cpu_to_le32(flags); rc = usb_control_msg(interface_to_usbdev(dev->iface), @@ -702,13 +703,12 @@ static int gs_can_open(struct net_device *netdev) if (rc < 0) { netdev_err(netdev, "Couldn't start device (err=%d)\n", rc); kfree(dm); + dev->can.state = CAN_STATE_STOPPED; return rc; } kfree(dm); - dev->can.state = CAN_STATE_ERROR_ACTIVE; - parent->active_channels++; if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) netif_start_queue(netdev); -- 2.35.1