All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: imu: st_lsm6dsx: do not use a fixed read len in read_oneshot
Date: Sat, 17 Nov 2018 16:27:59 +0000	[thread overview]
Message-ID: <20181117162759.1ae5272f@archlinux> (raw)
In-Reply-To: <CAJ0CqmUf8O1xkb8O_Ka7ENLgNB0wAbLpYen0qquF-+bO1R6VTA@mail.gmail.com>

On Fri, 16 Nov 2018 19:31:47 +0100
Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:

> > On Sun, 11 Nov 2018 23:28:28 +0100
> > Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:
> >  
> 
> [...]
> 
> > > -     __le16 data;
> > > +     int ret, delay, len = ch->scan_type.realbits >> 3;
> > > +     u8 *data;
> > >
> > > -     err = st_lsm6dsx_shub_set_enable(sensor, true);
> > > -     if (err < 0)
> > > -             return err;
> > > +     ret = st_lsm6dsx_shub_set_enable(sensor, true);
> > > +     if (ret < 0)
> > > +             return ret;
> > > +
> > > +     data = kmalloc(len, GFP_KERNEL);
> > > +     if (!data)
> > > +             return -ENOMEM;  
> >
> > Do we not want to disable should this fail?
> > Easier might be to just do the allocation before the set_enable
> > call.
> >
> > I'd also be tempted to just put a big enough buffer on the stack, or
> > into the sensor structure.
> >  
> 
> ack, right. I will fix it in v2 using a u8 data[4] on the stack.
> I guess it is reasonable, agree?
Can always be expanded later if we need it!

Thanks,

Jonathan

> 
> Regards,
> Lorenzo
> 
> > Also, I haven't checked but is there potential for DMA into this
> > buffer?
> >
> >  
> > >
> > >       delay = 1000000 / sensor->odr;
> > >       usleep_range(delay, 2 * delay);
> > >
> > > -     err = st_lsm6dsx_shub_read(sensor, ch->address, (u8 *)&data, len);
> > > -     if (err < 0)
> > > -             return err;
> > > +     ret = st_lsm6dsx_shub_read(sensor, ch->address, data, len);
> > > +     if (ret < 0)
> > > +             goto out;
> > >
> > >       st_lsm6dsx_shub_set_enable(sensor, false);
> > >
> > >       switch (len) {
> > >       case 2:
> > > -             *val = (s16)le16_to_cpu(data);
> > > +             *val = (s16)le16_to_cpu(*((__le16 *)data));
> > > +             ret = IIO_VAL_INT;
> > >               break;
> > >       default:
> > > -             return -EINVAL;
> > > +             ret = -EINVAL;
> > > +             break;
> > >       }
> > >
> > > -     return IIO_VAL_INT;
> > > +out:
> > > +     kfree(data);
> > > +     return ret;
> > >  }
> > >
> > >  static int  
> >  

      reply	other threads:[~2018-11-18  2:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1541975146.git.lorenzo.bianconi@redhat.com>
2018-11-11 22:28 ` [PATCH] iio: imu: st_lsm6dsx: do not use a fixed read len in read_oneshot Lorenzo Bianconi
2018-11-16 18:21   ` Jonathan Cameron
2018-11-16 18:31     ` Lorenzo Bianconi
2018-11-17 16:27       ` Jonathan Cameron [this message]

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=20181117162759.1ae5272f@archlinux \
    --to=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=lorenzo.bianconi@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.