🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21081

Re: [PATCH net v5 5/5] net: qualcomm: rmnet: Resize endpoints with dev_set_mtu() and restore on failure

#21081
From: Simon Horman
Date: Mon, 23 Nov 2026 14:35
136 lines
12637 bytes
On Mon, Nov 16, 2026 at 10:07:38PM -0800, Subash Abhinov Kasiviswanathan wrote:
> When the real device MTU or the data format requires a smaller MTU,
> existing endpoints are shrunk by writing dev->mtu directly. No MTU
> notifiers run and userspace gets no link notification.
> 
> Resize the endpoints with dev_set_mtu() so that the normal notifiers
> and link notifications are delivered. If resizing an endpoint fails,
> restore the endpoints which were already resized, ignoring any errors
> from the restore, so that a failed request does not leave some of them
> shrunk. The data format is not yet published while the endpoints are
> resized, so the restore is validated against the format the endpoints
> were sized for. The error from the failing dev_set_mtu() call is
> returned to the caller.
> 
> Fixes: b7f5eb6ba21b ("net: qualcomm: rmnet: Update rmnet device MTU based on real device")
> Co-developed-by: Sean Tranchetti <sean.tranchetti@oss.qualcomm.com>
> Signed-off-by: Sean Tranchetti <sean.tranchetti@oss.qualcomm.com>
> Signed-off-by: Subash Abhinov Kasiviswanathan <subash.a.kasiviswanathan@oss.qualcomm.com>
> ---
>  .../ethernet/qualcomm/rmnet/rmnet_config.h    |  1 +
>  .../net/ethernet/qualcomm/rmnet/rmnet_vnd.c   | 30 +++++++++++++++----
>  2 files changed, 25 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h
> index 5adda0323dda..47b8db3206b9 100644
> --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h
> +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h
> @@ -19,6 +19,7 @@ struct rmnet_endpoint {
>  	struct net_device *egress_dev;
>  	struct hlist_node hlnode;
>  	struct rcu_head rcu;
> +	int saved_mtu;
>  };
>  
>  struct rmnet_egress_agg_params {
> diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
> index 8bf87c5ecb43..dce436e4c630 100644
> --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
> +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
> @@ -433,24 +433,42 @@ int rmnet_vnd_validate_real_dev_mtu(struct net_device *real_dev)
>  int rmnet_vnd_update_dev_mtu(struct rmnet_port *port,
>  			     struct net_device *real_dev, u32 data_format)
>  {
> +	struct rmnet_endpoint *fail_ep = NULL;
>  	struct hlist_node *tmp_ep;
>  	struct rmnet_endpoint *ep;
>  	unsigned long bkt_ep;
>  	int new_mtu;
> -	int err;
> +	int err = 0;
>  
>  	new_mtu = rmnet_vnd_target_mtu(real_dev, data_format);
>  	if (new_mtu < 0)
>  		return new_mtu;
>  
>  	hash_for_each_safe(port->muxed_ep, bkt_ep, tmp_ep, ep, hlnode) {
> -		if (ep->egress_dev->mtu <= new_mtu)
> +		ep->saved_mtu = ep->egress_dev->mtu;
> +		if (ep->saved_mtu <= new_mtu)
>  			continue;
>  
> -		err = rmnet_vnd_change_mtu(ep->egress_dev, new_mtu);
> -		if (err)
> -			return err;
> +		err = dev_set_mtu(ep->egress_dev, new_mtu);
> +		if (err) {
> +			fail_ep = ep;
> +			break;
> +		}
>  	}
>  
> -	return 0;
> +	if (!err)
> +		return 0;
> +
> +	/* Restore the endpoints which were already resized. Failures here
> +	 * are ignored since the original error is the one to report.
> +	 */
> +	hash_for_each_safe(port->muxed_ep, bkt_ep, tmp_ep, ep, hlnode) {
> +		if (ep == fail_ep)
> +			break;
> +
> +		if (ep->egress_dev->mtu != ep->saved_mtu)
> +			dev_set_mtu(ep->egress_dev, ep->saved_mtu);
> +	}
> +
> +	return err;
>  }

The preferred idiom in Networking code is to:
1. Keep the happy path in the main unconditional path of execution.
2. Use goto for unwind on error

I think that can be achieved here with this incremental change
(compile tested only!).

diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
index dce436e4c630..6b147ef5211e 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
@@ -433,12 +433,12 @@ int rmnet_vnd_validate_real_dev_mtu(struct net_device *real_dev)
 int rmnet_vnd_update_dev_mtu(struct rmnet_port *port,
 			     struct net_device *real_dev, u32 data_format)
 {
-	struct rmnet_endpoint *fail_ep = NULL;
+	struct rmnet_endpoint *fail_ep;
 	struct hlist_node *tmp_ep;
 	struct rmnet_endpoint *ep;
 	unsigned long bkt_ep;
 	int new_mtu;
-	int err = 0;
+	int err;
 
 	new_mtu = rmnet_vnd_target_mtu(real_dev, data_format);
 	if (new_mtu < 0)
@@ -452,13 +452,13 @@ int rmnet_vnd_update_dev_mtu(struct rmnet_port *port,
 		err = dev_set_mtu(ep->egress_dev, new_mtu);
 		if (err) {
 			fail_ep = ep;
-			break;
+			goto restore_mtu;
 		}
 	}
 
-	if (!err)
-		return 0;
+	return 0;
 
+restore_mtu:
 	/* Restore the endpoints which were already resized. Failures here
 	 * are ignored since the original error is the one to report.
 	 */

-- 
pw-bot: changes-requested
Technical Details
Message-ID: <20261123143538.GD31322@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369481-linux-kernel-netdev=dewy.ru
References: <20261117060737.2764327-1-subash.a.kasiviswanathan@oss.qualcomm.com> <20261117060737.2764327-6-subash.a.kasiviswanathan@oss.qualcomm.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369481-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v5 5/5] net: qualcomm: rmnet: Resize endpoints with
 dev_set_mtu() and restore on failure
Date: Mon, 23 Nov 2026 14:35:38 +0000
Organization: Usenet Network
Message-ID: <20261123143538.GD31322@horms.kernel.org>
References: <20261117060737.2764327-1-subash.a.kasiviswanathan@oss.qualcomm.com>
 <20261117060737.2764327-6-subash.a.kasiviswanathan@oss.qualcomm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="3902368"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:sKaFaUiIWG8ZYZe1Zcsb9eSGbBE= sha256:W5Bvy5c0pbQguzTq93xrrGuz96MeeNMUr4rABnEnRso=
	sha1:dtpwFPXrFFOCrKpD8POqqtI1RkY= sha256:kCVtkOw2JaISOFZJ9zyt2ovQH9LKSDdbsFvbHJJG+Es=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 7457C125DB9; Mon, 23 Nov 2026 17:36:02 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id YNomF5LfbCcQ;
	Mon, 23 Nov 2026 17:35:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369481-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9E0D6125DB3; Mon, 23 Nov 2026 17:35:46 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id AB342244DB; Mon, 23 Nov 2026 14:35:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795444543;
	b=ItLXfAJMc+ulxKp23P049Fh4KPWRdR2IjmoLn7iLfPsATRR2RZw42kITzgxuNZl5+kN+
	 usTxSDPhTV/j/+qIgRhvlkiWdXre26wh7+wcBQqEi6SNm9wsy0BV4VikjZ9q0BtWIGKXY
	 zr2ZxU97elxYbAt8N17lENDb6TuDwnOnOCFmKSYpFcVuKZYDaBPVG0k2elGt0Hv2706QN
	 lZGnZFiNrTY57UKfB90VhCrujztaGrGh9jaquqtajN+AAfuP+2aloWZefPf9uYeVbXQ89
	 VvxhjAlOj1NhD3FQsu07doiINTge/17HP4mCmI71jih9I2VA4btsiWEeBaMgODJ9Tjw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795444543;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=mBim/Hkn0bG2Xgqqehb5DNOIciJ6suXgpAyGSHCaxzk=;
	b=mU5Al39icuUM953iqj9hoPMkoGF87pAS5IJT9gyTS/MJ7371O8e5wLw4AgW3gGpro0+2
	 UkcrADngibyZWLIYgd+l643gYiPk+4sSaqEvQG+bvdORaPvv1NphFvIr7vCPinSRvEB00
	 9F+aeJQeq6zBIetGEkmhXjfTDcxWgxis1kXy8tGsfmBLvwMhuLUrpOzv07830ixdK8CWs
	 2UZwTlWQFpX7CIjSuNk2owxgJG0C/t8bRXuPAjwUSnKyFdo/vFPcEQwdUDWdh1Bd1vmDB
	 HW2QeceG5x3U5Anz6I7WFZQCeYi15fTw+pQQMKb8qtvFYlAyRnjWcMY9qPv1REsRGDQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Kz2HxZH9;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E48D606A334;
	Mon, 23 Nov 2026 14:35:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Kz2HxZH9
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795444542;
	b=SsPjfoslYSDbPrwhrc8WL/QcLWGtuCWbU/qVWtg67ytLxXr9QHC8Ns+EXVPLMK/+cOv4
	 8jt6itrkbk3Qr+Qtuz2dBjxC8UqfyZU5+DBmh8a63s6IECD3jEQY0O1rqcYI4W4MtuoUM
	 w7c9cn/Axh4rJvIjbhZvPZLzGu/dBNKdK1Xc+/wZPl7xFUpT3qvohKwAQ/hy1iV//gzbU
	 QD5Vz9xLfjn81HiCj/shbHtVdco6lFXJ26mU2G6ueNbH3O0VbEFyEViIm0sm0bGOi7kbn
	 UcmR7KkBOBHUnnclQacMBSQzzMnc9kz0Ry7Qvk38rrRYgd8ewGZWWbmAMTkNL8V/47A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795444542;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=mBim/Hkn0bG2Xgqqehb5DNOIciJ6suXgpAyGSHCaxzk=;
	b=r9WhplUaVla27GdDlgkH7jp6lVOlHURMEckAa1oC53+/JLoPIpeqQt2Pu9y37yG+dfoL
	 anMGXyffu9RXu5/ZnejwbyU3EbP9SKtpcSYHac97NIShdldCniwifb2BO+SsoVeSHIGAe
	 1w5O4Zo32XxxcrU01A7NvWP9W04PII3E47fxL7lfik47kZmb53PrFPQGDDGX5sD0xsAvv
	 yPAvsxV9fCq110DeXSI84rnuj4s8v5DfuhoDdhlxIO/m7BF4Vy4+hA28+YFKIEXk2OiUb
	 ZJBouXbn8X6iuLrJvKlrAAUWzvVeVVvEzszcCAozT7G/LqoovkMFzvxbUgSnxUTeu9g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Kz2HxZH9;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DDE6606A31E;
	Mon, 23 Nov 2026 14:35:42 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C44B1F000C4;
	Mon, 23 Nov 2026 14:35:40 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795444542;
	bh=mBim/Hkn0bG2Xgqqehb5DNOIciJ6suXgpAyGSHCaxzk=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=Kz2HxZH9Wm9+GwaAPXZUssHWGF/nGt5FCqgEiB45Mt5BMwdY3iF/mjLOaoCeck1Al
	 hMkgxiNrFGo++1VjrLOqyNhy95tsGKjxrCsTFXWlqTZox4k+S4g3wIIo++MPysep6M
	 kC3XgX560Nd02tY2a4IphH1QqsAzT/J9uQNFQk8atFO/xcbSUydnC0AZ+htXNzydQj
	 lw9z6RqpHxsmZJg42lvp05Wxnn7yrXYWnsAFK1YHLNP/O/DfISEI7c0oSOsz9iUDtN
	 vE4PfH8AUMVhcTO7vAUjLLvjPzYaSBxcYe+QIj9igXVSSpBQn7ba1kDvqRE7GSQyoM
	 Ef7Yi0KkelMTA==
X-Cc: sean.tranchetti@oss.qualcomm.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261117060737.2764327-6-subash.a.kasiviswanathan@oss.qualcomm.com>