Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1775962pxp; Mon, 7 Mar 2022 02:03:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTMKNdtCEvA1WJ+AO4r0DEf6uNlAGjI6tD4QdLnwJNhyNfap59WSgSpvpFZQnBudZ16DpL X-Received: by 2002:a05:6402:2023:b0:416:2c7:945c with SMTP id ay3-20020a056402202300b0041602c7945cmr10443284edb.148.1646647388796; Mon, 07 Mar 2022 02:03:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647388; cv=none; d=google.com; s=arc-20160816; b=0e/IwNJRJhSCzcvg75kzkk8l4MuLY9tlbFLMXmLsOVs2Zf66HTTkh73Si2S9viYW/S rgqtAHnQUyjmWYN9Zmbgh3/pq/u7f3lyWcLAaYPQLeBUgZtKDZUq+W5wU+/iCUwXJjlA +qPtK+VVQLEslt/QDEnx5Gi0Kdfmbtx5gvxCIYVIlI1O0PXNmej2cs604wARhktoWEFX NXmDBhoPhe/nVtL3/28xEMuoNwvj71DG99sg6zObjtOLUY9SUrw6BIhKIhdwyDpyQs1g oPWsEIgWCDn/tmlI164876mKr0g6k7YxzNxQTHxHs90/LBgb2p5EMb3KUWxZBCH2q9pc WCkA== 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=6Uo43TU5qNJ5kQdW0d4zKij8EjKKbtQYctxlSMwt1jY=; b=ppvF2eA2F70StEZSbOea0O6FCe7sjUJGyOMqBKWASQ/X/z6jd3smOnWxe6Gwj221hz DjeA6h3Z0Nob/+n2O4YPI7Ni3VEMg/l0kqDVas4liSU244FVK4ea90rcpB3B+5vdUl2l o4rqNyTv7j3bMEI5YJ4YD3TKpDlAWA2+MdzIkIXxxVFH5hxFV+mEAgADZRo/aY5XnvuW i41OrLWdLpBS+SkWkqS04QTQVxR8YzIawLuwq8TFBUmadSYdpCIHoZrwn7xss1qqQqQt VIvehB1k+3A93eKAkGXAsUxguaJl+U6NeTJHLyAiYr8Vwhp6WhEgiITbxFExxEYzWhYF +1hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="v6K6d/cL"; 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 y20-20020a056402271400b004165f8c4481si212251edd.592.2022.03.07.02.02.45; Mon, 07 Mar 2022 02:03:08 -0800 (PST) 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="v6K6d/cL"; 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 S236867AbiCGJ0u (ORCPT + 99 others); Mon, 7 Mar 2022 04:26:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237317AbiCGJXn (ORCPT ); Mon, 7 Mar 2022 04:23:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C0DF2AE05; Mon, 7 Mar 2022 01:22:34 -0800 (PST) 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 EF99CB810B2; Mon, 7 Mar 2022 09:22:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C9C3C340E9; Mon, 7 Mar 2022 09:22:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644951; bh=9w7wfwKPGRpK9zkIDgGWdhu9dqbToz0KVbzKdvjnBHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v6K6d/cLjyOW4L2o1c5a1iajs0ww3I5R60fLNb+3VwwyOuvBiuybuahbsbp3w2KGP QNtQLyD9nbVp/xlnpWTT0C9PDeKwYUgiUFDAfJYH/o2cYMT5/6nwQTqvXz90HA3Hr/ WDex5rUoTnhtfJ9WARxyFwSY7yFKThb4tQwrPzT8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Mailhol , Marc Kleine-Budde Subject: [PATCH 4.14 33/42] can: gs_usb: change active_channelss type from atomic_t to u8 Date: Mon, 7 Mar 2022 10:19:07 +0100 Message-Id: <20220307091637.116146846@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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,T_SCC_BODY_TEXT_LINE 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: Vincent Mailhol commit 035b0fcf02707d3c9c2890dc1484b11aa5335eb1 upstream. The driver uses an atomic_t variable: gs_usb:active_channels to keep track of the number of opened channels in order to only allocate memory for the URBs when this count changes from zero to one. However, the driver does not decrement the counter when an error occurs in gs_can_open(). This issue is fixed by changing the type from atomic_t to u8 and by simplifying the logic accordingly. It is safe to use an u8 here because the network stack big kernel lock (a.k.a. rtnl_mutex) is being hold. For details, please refer to [1]. [1] https://lore.kernel.org/linux-can/CAMZ6Rq+sHpiw34ijPsmp7vbUpDtJwvVtdV7CvRZJsLixjAFfrg@mail.gmail.com/T/#t Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices") Link: https://lore.kernel.org/all/20220214234814.1321599-1-mailhol.vincent@wanadoo.fr Signed-off-by: Vincent Mailhol Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/usb/gs_usb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -198,8 +198,8 @@ struct gs_can { struct gs_usb { struct gs_can *canch[GS_MAX_INTF]; struct usb_anchor rx_submitted; - atomic_t active_channels; struct usb_device *udev; + u8 active_channels; }; /* 'allocate' a tx context. @@ -596,7 +596,7 @@ static int gs_can_open(struct net_device if (rc) return rc; - if (atomic_add_return(1, &parent->active_channels) == 1) { + if (!parent->active_channels) { for (i = 0; i < GS_MAX_RX_URBS; i++) { struct urb *urb; u8 *buf; @@ -697,6 +697,7 @@ static int gs_can_open(struct net_device dev->can.state = CAN_STATE_ERROR_ACTIVE; + parent->active_channels++; if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) netif_start_queue(netdev); @@ -712,7 +713,8 @@ static int gs_can_close(struct net_devic netif_stop_queue(netdev); /* Stop polling */ - if (atomic_dec_and_test(&parent->active_channels)) + parent->active_channels--; + if (!parent->active_channels) usb_kill_anchored_urbs(&parent->rx_submitted); /* Stop sending URBs */ @@ -991,8 +993,6 @@ static int gs_usb_probe(struct usb_inter init_usb_anchor(&dev->rx_submitted); - atomic_set(&dev->active_channels, 0); - usb_set_intfdata(intf, dev); dev->udev = interface_to_usbdev(intf);