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
This commit is contained in:
parent
fcdfe01616
commit
80ba361b2f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367296
@ -300,15 +300,17 @@ ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, struct ifmedia *ifm,
|
||||
* 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user