Re: [PATCH 1/2] net: dsa: ksz9477: add I2C managed mode support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 17, 2018 at 8:11 PM Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
>
> On Mon, Dec 17, 2018 at 07:22:51PM +0100, Sergio Paracuellos wrote:
> > > > +static int ksz_i2c_write(struct ksz_device *dev, u32 reg, u8 *val,
> > > > +                      unsigned int len)
> > > > +{
> > > > +     struct i2c_client *client = dev->priv;
> > > > +     unsigned int cnt = len;
> > > > +     int i = 0;
> > > > +     u8 txb[4];
> > > > +
> > > > +     do {
> > > > +             txb[i++] = (u8)(*val >> (8 * (cnt - 1)));
> > >                                               ^^^^^^^
> > >
> > > Can "cnt" be zero from ksz_i2c_set()?  If so this loop will corrupt
> > > memory.
> >
> > This get and set interface seems to be introduced recently but it is
> > not being used yet, so
> > in this moment the answer is not. For me, there is no sense in call
> > 'set' with no len. Should
> > I add a check for zero len and return EINVAL just in case?
> >
>
> Yes, please.

Done. v3 with this change already sent.

>
> > > > +static int ksz_i2c_probe(struct i2c_client *client,
> > > > +                      const struct i2c_device_id *id)
> > > > +{
> > > > +     struct ksz_device *dev;
> > > > +     int ret;
> > > > +
> > > > +     dev = ksz_switch_alloc(&client->dev, &ksz_i2c_ops, client);
> > > > +     if (!dev)
> > > > +             return -ENOMEM;
> > > > +
> > > > +     if (client->dev.platform_data)
> > > > +             dev->pdata = client->dev.platform_data;
> > > > +
> > > > +     i2c_set_clientdata(client, dev);
> > > > +
> > > > +     ret = ksz9477_switch_register(dev);
> > > > +     if (ret) {
> > > > +             dev_err(&client->dev, "registering switch (ret: %d)\n", ret);
> > >
> > >
> > > free dev on this error path?
> >
> > Internally all of this are using devm_* funcions, so I think is there
> > is no need to free anything. Also, the
> > spi managed driver for this does nothing also about this.
>
> You're right.  My bad.  I should have looked at this.
>
> regards,
> dan carpenter
>

Best regards,
    Sergio Paracuellos
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux