On Tue, 2019-08-06 at 17:46 +0200, Andrew Lunn wrote: > [External] > > On Tue, Aug 06, 2019 at 07:11:57AM +0000, Ardelean, Alexandru wrote: > > On Mon, 2019-08-05 at 17:28 +0200, Andrew Lunn wrote: > > > [External] > > > > > > > +struct adin_hw_stat { > > > > + const char *string; > > > > +static void adin_get_strings(struct phy_device *phydev, u8 *data) > > > > +{ > > > > + int i; > > > > + > > > > + for (i = 0; i < ARRAY_SIZE(adin_hw_stats); i++) { > > > > + memcpy(data + i * ETH_GSTRING_LEN, > > > > + adin_hw_stats[i].string, ETH_GSTRING_LEN); > > > > > > You define string as a char *. So it will be only as long as it should > > > be. However memcpy always copies ETH_GSTRING_LEN bytes, doing off the > > > end of the string and into whatever follows. > > > > > > > hmm, will use strlcpy() > > i blindedly copied memcpy() from some other driver > > Hopefully that driver used const char string[ETH_GSTRING_LEN]. Then a > memcpy is safe. If not, please let me know what driver you copied. It was an older Marvell PHY driver (marvell.c) ; in version 4.14. I used that as an initial work-base for writing the driver. Then I did the conversion to a newer kernel, then I also had to also consider an older kernel, then I got confused :) Well, in any case, I am solely considering net-next master (now) for upstreaming this. > > > i'm afraid i don't understand about the snapshot feature you are mentioning; > > i.e. i don't remember seeing it in other chips; > > It is frequency done at the MAC layer for statistics. You tell the > hardware to snapshot all the statistics. It atomically makes a copy of > all the statistics into a set of registers. These values are then > static, and consistent between counters. You can read them out knowing > they are not going to change. > > > regarding the danger that stat->reg1 rolls over, i guess that is > > possible, but it's a bit hard to guard against; > > The normal solution is the read the MSB, the LSB and then the MSB > again. If the MSB value has changed between the two reads, you know a > roll over has happened, and you need to do it all again. hmm; ok I'll try to look for an existing example for this. > > Andrew