Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Nov 2020 14:33:04 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r367296 - head/sys/net
Message-ID:  <202011031433.0A3EX4DB036313@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Tue Nov  3 14:33:04 2020
New Revision: 367296
URL: https://svnweb.freebsd.org/changeset/base/367296

Log:
  if_media.c SIOCGMEDIAX handler: improve loop
  
  Stop advancing counter past the current iteration number at the start
  of iteration.  This removes the need of subtracting one when
  calculating index for copyout, and arguably fixes off-by-one reporting
  of copied out elements when copyout failed.
  
  Reviewed by:	hselasky
  Sponsored by:	Mellanox Technologies / NVidia Networking
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D27073

Modified:
  head/sys/net/if_media.c

Modified: head/sys/net/if_media.c
==============================================================================
--- head/sys/net/if_media.c	Tue Nov  3 13:26:00 2020	(r367295)
+++ head/sys/net/if_media.c	Tue Nov  3 14:33:04 2020	(r367296)
@@ -300,15 +300,17 @@ ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, st
 		 * allocate.
 		 */
 		i = 0;
-		LIST_FOREACH(ep, &ifm->ifm_list, ifm_list)
-			if (i++ < ifmr->ifm_count) {
+		LIST_FOREACH(ep, &ifm->ifm_list, ifm_list) {
+			if (i < ifmr->ifm_count) {
 				error = copyout(&ep->ifm_media,
-				    ifmr->ifm_ulist + i - 1, sizeof(int));
-				if (error)
+				    ifmr->ifm_ulist + i, sizeof(int));
+				if (error != 0)
 					break;
 			}
+			i++;
+		}
 		if (error == 0 && i > ifmr->ifm_count)
-			error = ifmr->ifm_count ? E2BIG : 0;
+			error = ifmr->ifm_count != 0 ? E2BIG : 0;
 		ifmr->ifm_count = i;
 		break;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202011031433.0A3EX4DB036313>