[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAC9-QvATLW0uCzGpeY1kLXs5BBsfNBF_BKCnCz+38_f+STJhog@mail.gmail.com>
Date: Thu, 25 Jul 2019 18:41:41 +0200
From: Sergej Benilov <sergej.benilov@...glemail.com>
To: Andrew Lunn <andrew@...n.ch>
Cc: venza@...wnhat.org, netdev@...r.kernel.org
Subject: Re: [PATCH] sis900: add support for ethtool --eeprom-dump
On Thu, 25 Jul 2019 at 18:25, Andrew Lunn <andrew@...n.ch> wrote:
>
> > +static int sis900_read_eeprom(struct net_device *net_dev, u8 *buf)
> > +{
> > + struct sis900_private *sis_priv = netdev_priv(net_dev);
> > + void __iomem *ioaddr = sis_priv->ioaddr;
> > + int wait, ret = -EAGAIN;
> > + u16 signature;
> > + u16 *ebuf = (u16 *)buf;
> > + int i;
> > +
> > + if (sis_priv->chipset_rev == SIS96x_900_REV) {
> > + sw32(mear, EEREQ);
> > + for (wait = 0; wait < 2000; wait++) {
> > + if (sr32(mear) & EEGNT) {
> > + /* read 16 bits, and index by 16 bits */
> > + for (i = 0; i < sis_priv->eeprom_size / 2; i++)
> > + ebuf[i] = (u16)read_eeprom(ioaddr, i);
> > + ret = 0;
> > + break;
> > + }
> > + udelay(1);
> > + }
> > + sw32(mear, EEDONE);
>
> The indentation looks all messed up here.
This has passed ./scripts/checkpatch.pl, as you had suggested for the
previous patch.
>
> > + } else {
> > + signature = (u16)read_eeprom(ioaddr, EEPROMSignature);
> > + if (signature != 0xffff && signature != 0x0000) {
> > + /* read 16 bits, and index by 16 bits */
> > + for (i = 0; i < sis_priv->eeprom_size / 2; i++)
> > + ebuf[i] = (u16)read_eeprom(ioaddr, i);
> > + ret = 0;
> > + }
> > + }
> > + return ret;
> > +}
> > +
> > +#define SIS900_EEPROM_MAGIC 0xBABE
> > +static int sis900_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
> > +{
> > + struct sis900_private *sis_priv = netdev_priv(dev);
> > + u8 *eebuf;
> > + int res;
> > +
> > + eebuf = kmalloc(sis_priv->eeprom_size, GFP_KERNEL);
> > + if (!eebuf)
> > + return -ENOMEM;
> > +
> > + eeprom->magic = SIS900_EEPROM_MAGIC;
> > + spin_lock_irq(&sis_priv->lock);
> > + res = sis900_read_eeprom(dev, eebuf);
> > + spin_unlock_irq(&sis_priv->lock);
> > + if (!res)
> > + memcpy(data, eebuf + eeprom->offset, eeprom->len);
> > + kfree(eebuf);
>
> Why do you not put the data directly into data and avoid this memory
> allocation, and memcpy?
Because EEPROM data from 'eeprom->offset' offset and of 'eeprom->len'
length only is expected to be returned in 'data'.
>
> Andrew
Powered by blists - more mailing lists