Re: [PATCH net-next V3] net: phy: microchip_t1: SQI support for LAN887x

From: Andrew Lunn
Date: Wed Sep 11 2024 - 12:48:19 EST


> + /* Keep inliers and discard outliers */
> + for (int i = ARRAY_SIZE(rawtable) / 5;
> + i < ARRAY_SIZE(rawtable) / 5 * 4; i++)
> + sqiavg += rawtable[i];
> +
> + /* Get SQI average */
> + sqiavg /= 120;

120?

Isn't that ARRAY_SIZE(rawtable) / 5 * 4 - ARRAY_SIZE(rawtable) / 5

Please think about the comments being given. I said you should not
assume 200, but use ARRAY_SIZE, so it is possible to change the size
of the array and not get buffer overruns etc. So you need to review
all the code.

Better still, change it to 50 and make sure you get sensible values
from it. The accuracy won't be as good, but i would expect it to be
still about right. But with the current code, i guess you get 7 no
matter what the actual quality is.

This is a general principle in C code, and coding in general. Don't
scatter the same knowledge repeatedly everywhere, because it makes it
error prone to change. You have to find and change them all, rather
than just one central value.

Andrew

---
pw-bot: cr