mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Tarun Alle <tarun.alle@microchip.com>
Cc: arun.ramadoss@microchip.com, UNGLinuxDriver@microchip.com,
	hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next V3] net: phy: microchip_t1: SQI support for LAN887x
Date: Wed, 11 Sep 2024 18:47:57 +0200	[thread overview]
Message-ID: <a7e330fd-9000-4b23-bec6-ae2bbfe487a9@lunn.ch> (raw)
In-Reply-To: <20240911131124.203290-1-tarun.alle@microchip.com>

> +	/* 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

  reply	other threads:[~2024-09-11 16:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11 13:11 Tarun Alle
2024-09-11 16:47 ` Andrew Lunn [this message]
2024-09-13  7:17   ` Tarun.Alle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a7e330fd-9000-4b23-bec6-ae2bbfe487a9@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=arun.ramadoss@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tarun.alle@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®