Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp827502rwb; Mon, 26 Sep 2022 06:24:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69KvpA2p9kpAS47FKGiuKvbSy1ewICAm/35YM1x3ew6pPhBPBzfju384qAhWUjvbQOwAiv X-Received: by 2002:a05:6402:2756:b0:443:4a6d:f05a with SMTP id z22-20020a056402275600b004434a6df05amr22940139edd.396.1664198695467; Mon, 26 Sep 2022 06:24:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198695; cv=none; d=google.com; s=arc-20160816; b=0hStJ2wI0p0B9XHlspHynXIiIhFOxQLA/ZQIdphO6djAlo1hL51KB5/V8ewDGA/aBa iU+mZF+K6XWThq7AgnQP07+PwCnIh9UTOktfKSfC8Vi+EcB3NLHa5RIKmoO4L8poV8Nx lPCaLwm0QaHW0CdXJLlaon5ZWa9g2dabQ+cS9f4h+1NJBO8jdHEogvDzLgUVb/3oJPaC 5eD/B2wrHFhuTDEyfxDJDz5svgbEs6ZxWz9uL03mdBlyCqycmIxYWpj+ZjA2WYrPYyyM RTYrJES4u7gGPGEtHr8a8APzhUHCKF+V+J36ENq8fzl4wADU/mpit10xdz8lPw1sPuux uwkQ== 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=bLENfW7jbcR3fHGlnv3YB14ML0CYeT+huM55+NElF+s=; b=yT57AsBbqcIXzAKqZp63PKqoFrNBmaRlZRzIafY2+m6EfwtXbBThC15lViqXX25/SI UnD0IlpWsNv+892ZiADGtdDOp+tYLbo9B9HJ7VcQ1z55Sn/qI9u23OkgB8H19c1HR0rJ Ul/cO/sB45UPAaVCOpDXgiwMbKTWiAUsDdC8Q6EnVjy2kDCDX4fLUkDNbmeGk7nQuPsU 6dgW0yf3WxdhORxCoyG0n70Mq0MH33bc3ktxLg/qCspQcz+T/PLS/9wpELPhbl44+occ FIY4qiOYFRCiMq07H8J3hFddYn4dUU/GipylrqX8kBY3RGtg9AwSMBAig389zIZkw8iQ Aq0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mW+1mlja; 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 ht8-20020a170907608800b0078331a3b123si685993ejc.572.2022.09.26.06.24.29; Mon, 26 Sep 2022 06:24:55 -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=mW+1mlja; 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 S238334AbiIZLvT (ORCPT + 99 others); Mon, 26 Sep 2022 07:51:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238780AbiIZLts (ORCPT ); Mon, 26 Sep 2022 07:49:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FB7E75FF7; Mon, 26 Sep 2022 03:48:30 -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 84D6FB802C7; Mon, 26 Sep 2022 10:48:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D73D3C433D6; Mon, 26 Sep 2022 10:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189309; bh=zluzXjF/oF3xR44I3+gJzSJtEsdyJheyxQR6K6shb3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mW+1mlja95+FNIsN1iXSU5BPzzpDw/xBc2P5vZTK6VhkjZ+4loNHqZa6A3PMlF9py +AQP/eERv6kmOjDjyb05HoAyzyD+ed08AIV7imVGbNNrFdDwG2nxKsgNivQitJcjZ/ h2BsCWF7WpZBUzF94xaIYOisM5Zq4vldptTdcZ6s= 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 5.19 144/207] can: gs_usb: gs_can_open(): fix race dev->can.state condition Date: Mon, 26 Sep 2022 12:12:13 +0200 Message-Id: <20220926100812.954667396@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@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 d3a658b444b5..092cd51b3926 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -824,6 +824,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), @@ -835,13 +836,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