Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2420563pxp; Mon, 7 Mar 2022 15:13:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4EAytFpEjgkI+hH0rfb6Z1262BnVO6ko3HwQWsTUaK51d5eUuJkcyFNWiuGeGRpJQgsRC X-Received: by 2002:a17:906:8a86:b0:6ae:9c35:35c7 with SMTP id mu6-20020a1709068a8600b006ae9c3535c7mr11171240ejc.494.1646694818209; Mon, 07 Mar 2022 15:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646694818; cv=none; d=google.com; s=arc-20160816; b=oMs5s4K+PfJRn6+Zj9h+eKOyEokX5TKzs3ZLA6pLjRG3mDOedTTeeXRIbnZMAxMkJ2 mznFbO43IrXtmpKHNU04aKWcy02N2WNCHq/15VMTNyNDwqCuV7uaaEongqX5ihm66VUX gF/799rFvs1cPCv8KGexGgfBp+ZCy7uxb45E61P4DaaRuW1ZuscL3jQD0H4xl6dp0JBb nomh1TbVNMnOHr6serBPqLClWGWadAlbnzb3gpQciROfAalAqwPXWDSvrjkH5jmWr+rh dM60FT14qHZGiyGQkKFYS+KJkPjwRJnxLJ7opMXWatBlYh7jI6GQYYDGGqyMtZOSASAW jL8A== 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=rHcxGsaNBv+rjDSvFBRQYlPBqVSidadDHyNZHMiQBGA=; b=KAt+L/lYeqp/m4j7N5c/opYMEq4qBAAEUvVIvgbm2bOWyUr6MLVHB4FPI8fmwb7152 Ly92IJR1/wY6ZsyHgTeIKZWxZUrkXOmAu1P3z3urv7cK9IXsEYIr8nj8yZ9mglkqF7Y3 o5l2eP2cSFNyTHEwAt+DxBBWH8OnD7qhL7eZu9Xi5Bu527AzYKsW9/AQVxgUQ0syev9J 42fwiXdJ1zKiV1txApibbjJZCq2ENlGrp1tIrtiB8UvYK9H7uwPtT/yxFVMjiISKx3GD IRBQniHtT2/BuKNOlM3if+esx5eojkD4x394IhIo06XdfCcau215UCAK/1JH7GfTiwQV 8yNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fEe3PIAd; 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 sd42-20020a1709076e2a00b006d97872f610si9451399ejc.21.2022.03.07.15.13.15; Mon, 07 Mar 2022 15:13:38 -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=fEe3PIAd; 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 S240628AbiCGKh2 (ORCPT + 99 others); Mon, 7 Mar 2022 05:37:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242096AbiCGKLO (ORCPT ); Mon, 7 Mar 2022 05:11:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9936F88781; Mon, 7 Mar 2022 01:54:25 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2E44160BB5; Mon, 7 Mar 2022 09:53:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F764C340F3; Mon, 7 Mar 2022 09:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646646827; bh=xKRWElij6OuQu68z/epaNC3rjgzBAHua+vCW4tVnPjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fEe3PIAdi/GcXXM3KssBt1CDtv/u80R4IH3b9XjNesSp/4LMdBaADZa3KJyzctA20 AMKJ4nZ2t/d2DYhBOUF5Zs3wZtwCVqQE+bQvok5TR6hw+7zWYIuyGXcei/06BSE8+V wFqseOJ2HnTYQOmYjU/bdEbevC6WIbDoPz4UFKtU= 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 5.16 104/186] can: gs_usb: change active_channelss type from atomic_t to u8 Date: Mon, 7 Mar 2022 10:19:02 +0100 Message-Id: <20220307091656.987735882@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091654.092878898@linuxfoundation.org> References: <20220307091654.092878898@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 @@ -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. @@ -590,7 +590,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; @@ -691,6 +691,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); @@ -706,7 +707,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 */ @@ -985,8 +987,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);