Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1589751rdb; Thu, 7 Dec 2023 03:43:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1WfdxfIOagbIPJy3QhAGlwiwEce4UI2eQmvuPzlLooXSypzV+bkwLLy2imXJOlJzQPS0B X-Received: by 2002:a05:6870:7185:b0:1fb:75b:2fd9 with SMTP id d5-20020a056870718500b001fb075b2fd9mr2604187oah.112.1701949381636; Thu, 07 Dec 2023 03:43:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701949381; cv=none; d=google.com; s=arc-20160816; b=zZloryY3ytiaJf1vHIYhGNlQleGksK44rwEBswkTRXu3d3U0veUTEI0kVqtPzeLF5D OVN4YGvpNTvVai6HAyj8jbqd38Jsx8xMPfD8mO9CbLW7wmm2oewQOhnfLrZZBDE1tpoA QbMmp2aKdfJWUyGF6U5VmanyjOcZ6WevNu5VWQCX6lmtyQiAPdGC7Zl/LbrrlZLKOELz 14VLUvoMX8Enlv4Gr3txz+ThLX8BHXzdUgH0T1bFRvMex+nHBwNdfU4FOreNdY0KX3Jn 7EMtTrUlH4/XRIHLjKovXqYixas0TSj85s3wpCk6l6MkRyQbkX9A6bfjubJ+o0J3dAIj N8DQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gHxTURiY+BajALQ6jlUVzV1suGGc/R1HBwIs10ym2wE=; fh=IM3McWsM9WPthTZ9Z7peQVvYux4QqEk9HMDjS1JrRmU=; b=U5fJLFpWnttgNOpSkcFGW5rCMq07+nXYfEe02YciZOGrzkp9avHDE37ycjAGt7APzc t0f7KafJ1YXLv0qPGqgDvf2gI1zS1cQ391KJ2T2k4RwqCGW12JHIIEnFtX4ZPbGbFc+h 0lmFWIydiqXC2twcuDeBo3gMZFEQ09PoEbuta8jKJx8KB/vsztJ3QNbDnbLc0Zz6vq7l 8Pa8BiIhOJecYzgNuX2rUtIQYMm057eB/mFQ5MQryADK+zy1AO20Fwhp4qbS+dRAMCrV vZ9qzfjOWgdNy0JGgPFlI0tgMS8bAm/IEZ9u93lTFo7CXRco4vndoF/bqKdUBvu5N4nF pjKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DSvofPsf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id cb11-20020a056a02070b00b005a9debd7854si1069068pgb.828.2023.12.07.03.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 03:43:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DSvofPsf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 6280A809BE5B; Thu, 7 Dec 2023 03:42:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbjLGLmT (ORCPT + 99 others); Thu, 7 Dec 2023 06:42:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230234AbjLGLmS (ORCPT ); Thu, 7 Dec 2023 06:42:18 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F9C9A3 for ; Thu, 7 Dec 2023 03:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701949343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gHxTURiY+BajALQ6jlUVzV1suGGc/R1HBwIs10ym2wE=; b=DSvofPsf7MjzpC7z4ga3QOkkJmg6kyz6JXI8gKUoWWYyNbkwBY2ex/1+B+AFVWeQEiQyVS js8O06nr51n15xjxVYLL7Y75hAI9ZJWJaYdzNb6hJPprzv8juNz/qcWqXvj2qUVCOFWj5x 3gB4L7uWvZnwFBK3qzVXIMLwkH4wSIc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175-hiY-S404OzuPt_BL-Qw82w-1; Thu, 07 Dec 2023 06:42:21 -0500 X-MC-Unique: hiY-S404OzuPt_BL-Qw82w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5F8E8030C4; Thu, 7 Dec 2023 11:42:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.39.193.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 365F38CD0; Thu, 7 Dec 2023 11:42:18 +0000 (UTC) From: Jose Ignacio Tornos Martinez To: stern@rowland.harvard.edu Cc: davem@davemloft.net, edumazet@google.com, greg@kroah.com, jtornosm@redhat.com, kuba@kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org, oneukum@suse.com, pabeni@redhat.com, stable@vger.kernel.org Subject: [PATCH v5] net: usb: ax88179_178a: avoid failed operations when device is disconnected Date: Thu, 7 Dec 2023 12:42:09 +0100 Message-ID: <20231207114209.14595-1-jtornosm@redhat.com> In-Reply-To: <624ad05b-0b90-4d1c-b06b-7a75473401c3@rowland.harvard.edu> References: <624ad05b-0b90-4d1c-b06b-7a75473401c3@rowland.harvard.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 07 Dec 2023 03:42:58 -0800 (PST) When the device is disconnected we get the following messages showing failed operations: Nov 28 20:22:11 localhost kernel: usb 2-3: USB disconnect, device number 2 Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3: unregister 'ax88179_178a' usb-0000:02:00.0-3, ASIX AX88179 USB 3.0 Gigabit Ethernet Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3: Failed to read reg index 0x0002: -19 Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3: Failed to write reg index 0x0002: -19 Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3 (unregistered): Failed to write reg index 0x0002: -19 Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3 (unregistered): Failed to write reg index 0x0001: -19 Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3 (unregistered): Failed to write reg index 0x0002: -19 The reason is that although the device is detached, normal stop and unbind operations are commanded from the driver. These operations are not necessary in this situation, so avoid these logs when the device is detached if the result of the operation is -ENODEV and if the new flag informing about the disconnecting status is enabled. cc: stable@vger.kernel.org Fixes: e2ca90c276e1f ("ax88179_178a: ASIX AX88179_178A USB 3.0/2.0 to gigabit ethernet adapter driver") Signed-off-by: Jose Ignacio Tornos Martinez --- V1 -> V2: - Follow the suggestions from Alan Stern and Oliver Neukum to check the result of the operations (-ENODEV) and not the internal state of the USB layer (USB_STATE_NOTATTACHED). V2 -> V3 - Add cc: stable line in the signed-off-by area. V3 -> V4 - Follow the suggestions from Oliver Neukum to use only one flag when disconnecting and include barriers to avoid memory ordering issues. V4 -> V5 - Fix my misundestanding and follow the suggestion from Alan Stern to syncronize and not order the flag. drivers/net/usb/ax88179_178a.c | 47 +++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index 4ea0e155bb0d..e07614799f75 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -173,6 +173,8 @@ struct ax88179_data { u8 in_pm; u32 wol_supported; u32 wolopts; + u8 disconnecting; + struct mutex lock; }; struct ax88179_int_data { @@ -208,6 +210,8 @@ static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, { int ret; int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); + struct ax88179_data *ax179_data = dev->driver_priv; + u8 disconnecting; BUG_ON(!dev); @@ -219,9 +223,14 @@ static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, index, data, size); - if (unlikely(ret < 0)) - netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n", - index, ret); + if (unlikely(ret < 0)) { + mutex_lock(&ax179_data->lock); + disconnecting = ax179_data->disconnecting; + mutex_unlock(&ax179_data->lock); + if (!(ret == -ENODEV && disconnecting)) + netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n", + index, ret); + } return ret; } @@ -231,6 +240,8 @@ static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, { int ret; int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); + struct ax88179_data *ax179_data = dev->driver_priv; + u8 disconnecting; BUG_ON(!dev); @@ -242,9 +253,14 @@ static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, ret = fn(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, index, data, size); - if (unlikely(ret < 0)) - netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n", - index, ret); + if (unlikely(ret < 0)) { + mutex_lock(&ax179_data->lock); + disconnecting = ax179_data->disconnecting; + mutex_unlock(&ax179_data->lock); + if (!(ret == -ENODEV && disconnecting)) + netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n", + index, ret); + } return ret; } @@ -492,6 +508,22 @@ static int ax88179_resume(struct usb_interface *intf) return usbnet_resume(intf); } +static void ax88179_disconnect(struct usb_interface *intf) +{ + struct usbnet *dev = usb_get_intfdata(intf); + struct ax88179_data *ax179_data; + + if (!dev) + return; + + ax179_data = dev->driver_priv; + mutex_lock(&ax179_data->lock); + ax179_data->disconnecting = 1; + mutex_unlock(&ax179_data->lock); + + usbnet_disconnect(intf); +} + static void ax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) { @@ -1274,6 +1306,7 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) ax179_data = kzalloc(sizeof(*ax179_data), GFP_KERNEL); if (!ax179_data) return -ENOMEM; + mutex_init(&ax179_data->lock); dev->driver_priv = ax179_data; @@ -1906,7 +1939,7 @@ static struct usb_driver ax88179_178a_driver = { .suspend = ax88179_suspend, .resume = ax88179_resume, .reset_resume = ax88179_resume, - .disconnect = usbnet_disconnect, + .disconnect = ax88179_disconnect, .supports_autosuspend = 1, .disable_hub_initiated_lpm = 1, }; -- 2.43.0