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; } _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"