Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6153439pxb; Mon, 14 Feb 2022 17:05:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy06gfJO6f9n5YllHhlKjYIXBtjixfBBHwfSHMSui0CLuGHtN0x7JIJH9qsHFJMoIaaxMOW X-Received: by 2002:aa7:cdc9:: with SMTP id h9mr1526585edw.27.1644887103679; Mon, 14 Feb 2022 17:05:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644887103; cv=none; d=google.com; s=arc-20160816; b=jp4ohAWOwFxRu1qBFqBhv//p5MbHv2EOGIDCzlmBQ5OH8sxzsvNzh6TZPzn3Sxs6gh B3C/+zCX1uPy/UvpYE6bxRxsww66iOG0W1ujxwU9or1d/me5TS+puESdjWcW6+fCd/Ne v76wGbCSyh5sg6sFpP1/x0GuI9BuBUoNMI8szBERucF/pyS0LBUcPCG2Dm0jr5qd/xln DTZx4cUwf1uuFHX+gWDFQg50x5cLg5abx9ZNbMcXUE3p+nW6UNSJXRGd70Xx23dXBk2P EndI/hmqbaCpjS+RoPbzEmuyHs2d+KueUIOpr/f5rd4bHGDKuGaRYtYN4Mv14cZviZ4+ H3gw== 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 :message-id:date:subject:cc:to:from; bh=ckSHkEUfy/fSDCRUD0T2PPYwSd8UNi3iCBfq3RiCNPM=; b=KJBxIY3yXHtucYWVWeZL/rQWdWXMOiSk55YZ0N7OvwvjFw42act/Jxr36lom/U1KPK NQ/Syjj0uwx6FBEsLGLZRiuHaFk/aw1vnZlpkK8sqsbcw2OtVcWsB6lh1I/dQAOZxA12 T3uoXWnRy9HK9lhfa/K9G9t4gSa/1TMOvVXaFFYYHNp8+RwqpXJOAtNglyGnH7Uc0MNa bgV4WjiRzJj7otLEG2lEFtba+of/cTLFtzv/0yKdPI9XKrYKlVJaxykSvbgBaulFQDUT Wuhevp76NlTyy0catgBRTGzl8zmIwPNwinfNtGclmdW6xARFGOzsTjxdVb6WtPbH161j 98Kw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr3si20355765ejc.955.2022.02.14.17.04.32; Mon, 14 Feb 2022 17:05:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229588AbiBNXsv (ORCPT + 99 others); Mon, 14 Feb 2022 18:48:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbiBNXsu (ORCPT ); Mon, 14 Feb 2022 18:48:50 -0500 Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918F71402E for ; Mon, 14 Feb 2022 15:48:40 -0800 (PST) Received: from localhost.localdomain ([124.33.176.97]) by smtp.orange.fr with ESMTPA id Jl4ynKYlVPEU7Jl59na5Tp; Tue, 15 Feb 2022 00:48:37 +0100 X-ME-Helo: localhost.localdomain X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Tue, 15 Feb 2022 00:48:37 +0100 X-ME-IP: 124.33.176.97 From: Vincent Mailhol To: netdev@vger.kernel.org, linux-can@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Marc Kleine-Budde , Maximilian Schneider , Vincent Mailhol Subject: [RFC PATCH v1] can: gs_usb: change active_channels's type from atomic_t to u8 Date: Tue, 15 Feb 2022 08:48:14 +0900 Message-Id: <20220214234814.1321599-1-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 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") Signed-off-by: Vincent Mailhol --- drivers/net/can/usb/gs_usb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index b487e3fe770a..d35749fad1ef 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -191,8 +191,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. @@ -589,7 +589,7 @@ static int gs_can_open(struct net_device *netdev) 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; @@ -690,6 +690,7 @@ static int gs_can_open(struct net_device *netdev) dev->can.state = CAN_STATE_ERROR_ACTIVE; + parent->active_channels++; if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) netif_start_queue(netdev); @@ -705,7 +706,8 @@ static int gs_can_close(struct net_device *netdev) 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 */ @@ -984,8 +986,6 @@ static int gs_usb_probe(struct usb_interface *intf, init_usb_anchor(&dev->rx_submitted); - atomic_set(&dev->active_channels, 0); - usb_set_intfdata(intf, dev); dev->udev = interface_to_usbdev(intf); -- 2.34.1