On Tue, Sep 22, 2020 at 11:24:24AM +0530, Vasundhara Volam wrote:
> On Mon, Sep 21, 2020 at 2:48 PM Michal Kubecek <[email protected]> wrote:
> > > + return -1;
> > > + }
> > > +
> > > + pcie_stats = (u16 *)(regs->data + BNXT_PXP_REG_LEN);
> > > + fprintf(stdout, "PCIe statistics:\n");
> > > + fprintf(stdout, "----------------\n");
> > > + for (i = 0; i < ARRAY_SIZE(bnxt_pcie_stats); i++) {
> > > + pcie_stat = 0;
> > > + memcpy(&pcie_stat, &pcie_stats[stats[i].offset],
> > > + stats[i].size * sizeof(u16));
> >
> > This will only work on little endian architectures.
>
> Data is already converted to host endian order by ETHTOOL_REGS, so it
> will not be an issue.
It does not work correctly. Assume we are on big endian architecture and
are reading a 16-bit value (stats[i].size = 1) 0x1234 which is laid out
in memory as
... 12 34 ...
Copying that by memcpy() to the address of 64-bit pcie_stat, you get
12 34 00 00 00 00 00 00
which represents 0x1234000000000000, not 0x1234. You will also have the
same problem with 32-bit values (stats[i].size = 2).
Michal