All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Jacopo Mondi <jacopo@jmondi.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Matt Ranostay <matt.ranostay@konsulko.com>,
	Magnus Damm <magnus.damm@gmail.com>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v3.1 2/3] iio: chemical: Add Senseair Sunrise 006-0-007 driver
Date: Sun, 29 Aug 2021 17:21:13 +0100	[thread overview]
Message-ID: <20210829172113.10f3cd27@jic23-huawei> (raw)
In-Reply-To: <CAHp75Vc4gSEn_3=5ixWr4WFyKwXDMMC8SaoBkZNotZ+GP6wMWA@mail.gmail.com>

On Mon, 23 Aug 2021 14:09:21 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Mon, Aug 23, 2021 at 1:20 PM Jacopo Mondi <jacopo@jmondi.org> wrote:
> > On Mon, Aug 23, 2021 at 12:40:00PM +0300, Andy Shevchenko wrote:  
> > > On Mon, Aug 23, 2021 at 11:06:10AM +0200, Jacopo Mondi wrote:  
> > > > On Mon, Aug 23, 2021 at 11:35:23AM +0300, Andy Shevchenko wrote:  
> > > > > On Mon, Aug 23, 2021 at 09:36:39AM +0200, Jacopo Mondi wrote:  
> 
> ...
> 
> > > > > > +       errors = (const unsigned long *)&value;  
> > > > >
> > > > > Yes, it takes a pointer, but in your case it will oops the kernel quite likely.  
> > > >
> > > > The usage of a pointer kind of puzzled me in first place, and I found
> > > > no pattern to copy in the existing code base. I have probbaly not
> > > > looked hard enough ?
> > > >  
> > > > >   unsigned long errors;
> > > > >
> > > > >   ...
> > > > >
> > > > >   errors = value;
> > > > >   for_each_set_bit(..., &errors, ...)  
> > > >
> > > > I can do so but, for my education mostly, why do you think it would
> > > > oops ? '*errors' is a pointer to a variable allocated on the stack as
> > > > much as 'errors' you suggested is a local stack variable. I might be a
> > > > bit slow today, but I'm missing the difference. FWIW I tested the
> > > > function, even if there were no error bits set at the moment I tested, but
> > > > the for_each_set_bit() macro was indeed run.  
> > >
> > > Because you theoretically access bytes behind 16-bit. That castings just ugly
> > > and compiler should warn you about if it is clever enough.  
> >
> > I don't think there's such a risk as I limit the search space to
> > ARRAY_SIZE(error_codes), but I agree the cast is ugly and I'll change
> > to what you suggested  
> 
> More for the sake of education. Actually it's not theoretical. Some
> architectures may not access longs on unaligned (16-bit) addresses.
> So, yes, oops is probable.
> Another example is reading the long to the register. This can cross
> the page boundary and produce fault (again) oops.

For extra giggles, (and I'm half asleep today so may have this backwards)
what it the platform is big endian and you do this?  I'm fairly sure it will
walk the bits from low to high and so the first access will be off the end
of your shorter type being as it will be at addr + sizeof (long) - 1 bit 7.

> 
> > > If you found it in the existing code, please, fix it there, so quite bad
> > > pattern won't spread.  
> >
> > My point was that I was not able to find any pattern to copy from :)
> >  
> > > > > > +       for_each_set_bit(i, errors, ARRAY_SIZE(error_codes))
> > > > > > +               len += sysfs_emit_at(buf, len, "%s ", sunrise_error_statuses[i]);  
> 


  reply	other threads:[~2021-08-29 16:18 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-22 18:49 [PATCH v3 0/3] iio: chemical: Add Senseair Sunrise CO2 sensor Jacopo Mondi
2021-08-22 18:49 ` [PATCH v3 1/3] dt-bindings: iio: chemical: Document senseair,sunrise " Jacopo Mondi
2021-08-24 12:28   ` Rob Herring
2021-08-22 18:49 ` [PATCH v3 2/3] iio: chemical: Add Sensteair Sunrise 006-0-007 driver Jacopo Mondi
2021-08-22 20:09   ` Andy Shevchenko
2021-08-23  7:36   ` [PATCH v3.1 2/3] iio: chemical: Add Senseair " Jacopo Mondi
2021-08-23  8:35     ` Andy Shevchenko
2021-08-23  9:06       ` Jacopo Mondi
2021-08-23  9:40         ` Andy Shevchenko
2021-08-23 10:19           ` Jacopo Mondi
2021-08-23 11:09             ` Andy Shevchenko
2021-08-29 16:21               ` Jonathan Cameron [this message]
2021-08-29 17:39                 ` Andy Shevchenko
2021-08-29 16:54     ` Jonathan Cameron
2021-08-30 16:20       ` Jacopo Mondi
2021-08-30 16:27         ` Jacopo Mondi
2021-08-30 17:11         ` Jonathan Cameron
2021-08-31  7:40           ` Jacopo Mondi
2021-09-05 10:04             ` Jonathan Cameron
2021-09-05 23:03               ` Peter Rosin
2021-09-06  6:56                 ` Peter Rosin
2021-09-08 11:00                 ` Jacopo Mondi
2021-09-08 15:29                   ` Peter Rosin
2021-09-08 15:58                     ` Andy Shevchenko
2021-09-08 16:08                     ` Jacopo Mondi
2021-08-22 18:49 ` [PATCH v3 3/3] iio: ABI: docs: Document Senseair Sunrise ABI Jacopo Mondi
2021-08-29 16:57   ` Jonathan Cameron
2021-08-30 16:24     ` Jacopo Mondi
2021-08-30 17:12       ` Jonathan Cameron
2021-08-22 20:11 ` [PATCH v3 0/3] iio: chemical: Add Senseair Sunrise CO2 sensor Andy Shevchenko
2021-08-23  7:16   ` Jacopo Mondi
2021-08-23  7:39     ` Andy Shevchenko

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=20210829172113.10f3cd27@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=jacopo@jmondi.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=matt.ranostay@konsulko.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.