mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
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
1 changed files with 7 additions and 5 deletions
|
|
@ -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 a new issue