[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Yzqt0o0yWsfCGQ6I@smile.fi.intel.com>
Date: Mon, 3 Oct 2022 12:39:30 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Matti Vaittinen <mazziesaccount@...il.com>
Cc: Matti Vaittinen <matti.vaittinen@...rohmeurope.com>,
Lars-Peter Clausen <lars@...afoo.de>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Cosmin Tanislav <cosmin.tanislav@...log.com>,
Jonathan Cameron <jic23@...nel.org>,
Eugen Hristev <eugen.hristev@...rochip.com>,
Nicolas Ferre <nicolas.ferre@...rochip.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Claudiu Beznea <claudiu.beznea@...rochip.com>,
Benson Leung <bleung@...omium.org>,
Guenter Roeck <groeck@...omium.org>,
Alexandru Ardelean <alexandru.ardelean@...log.com>,
Nathan Chancellor <nathan@...nel.org>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Miaoqian Lin <linmq006@...il.com>,
Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>,
Paul Cercueil <paul@...pouillou.net>,
Mihail Chindris <mihail.chindris@...log.com>,
Gwendal Grignou <gwendal@...omium.org>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
chrome-platform@...ts.linux.dev
Subject: Re: [RFT PATCH v3 10/10] iio: Don't silently expect attribute types
On Mon, Oct 03, 2022 at 12:02:56PM +0300, Matti Vaittinen wrote:
> On 10/3/22 11:58, Matti Vaittinen wrote:
> > On 10/3/22 11:43, Andy Shevchenko wrote:
> > > On Mon, Oct 03, 2022 at 11:13:53AM +0300, Matti Vaittinen wrote:
...
> > > > + attr[ARRAY_SIZE(iio_buffer_attrs) + i] =
> > > > + (struct attribute *)&id_attr->dev_attr.attr;
> > >
> > > ...and explicit casting here. Isn't attr is already of a struct
> > > attribute?
> >
> > I am glad you asked :)
> > This is one of the "things" I was not really happy about. Here we hide
> > the fact that our array is full of pointers to _const_ data. If we don't
> > cast the compiler points this out. Old code did the same thing but it
> > did this by just doing a memcpy for the pointers - which I personally
> > consider even worse as it gets really easy to miss this. The cast at
> > least hints there is something slightly "fishy" going on.
> >
> > My "gut feeling" about the correct fix is we should check if some
> > attributes in the array (stored to the struct here) actually need to be
> > modified later (which I doubt). If I was keen on betting I'd bet we
> > could switch the struct definition to also contain pointers to const
> > attributes. I am afraid this would mean quite a few more changes to the
> > function signatures (changing struct attribute * to const struct
> > attribute *) here and there - and possibly also require some changes to
> > drivers. Thus I didn't even look at that option in the scope of this
> > fix. It should probably be a separate refactoring series. But yes - this
> > cast should catch attention as it did.
> >
>
> Actually, now that you pointed it out - do you think this would warrant a
> FIXME comment?
Makes sense to me, but I'm not a maintainer of IIO :-)
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists