LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1] Input: ads7846: ads7846_get_value - fix unaligned pointer value warning
@ 2021-07-07 12:41 Oleksij Rempel
2021-09-10 5:04 ` Dmitry Torokhov
0 siblings, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2021-07-07 12:41 UTC (permalink / raw)
To: Dmitry Torokhov, Alexandru Ardelean, Mark Brown
Cc: Oleksij Rempel, kernel test robot, kernel, linux-kernel,
linux-input, linux-spi, David Jander
Fix warning reported by the kernel test robot:
drivers/input/touchscreen/ads7846.c:705:24: warning: taking address
of packed member 'data' of class or structure 'ads7846_buf' may result
in an unaligned pointer value [-Waddress-of-packed-member]
Fixes: 6965eece2a89 ("Input: ads7846 - convert to one message")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/input/touchscreen/ads7846.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index adb4c2230c31..1987dedac94f 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -702,7 +702,7 @@ static int ads7846_get_value(struct ads7846_buf *buf)
{
int value;
- value = be16_to_cpup(&buf->data);
+ value = get_unaligned_be16(&buf->data);
/* enforce ADC output is 12 bits width */
return (value >> 3) & 0xfff;
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] Input: ads7846: ads7846_get_value - fix unaligned pointer value warning
2021-07-07 12:41 [PATCH v1] Input: ads7846: ads7846_get_value - fix unaligned pointer value warning Oleksij Rempel
@ 2021-09-10 5:04 ` Dmitry Torokhov
2021-09-10 7:51 ` Oleksij Rempel
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2021-09-10 5:04 UTC (permalink / raw)
To: Oleksij Rempel
Cc: Alexandru Ardelean, Mark Brown, kernel test robot, kernel,
linux-kernel, linux-input, linux-spi, David Jander
Hi Oleksij,
On Wed, Jul 07, 2021 at 02:41:15PM +0200, Oleksij Rempel wrote:
> Fix warning reported by the kernel test robot:
> drivers/input/touchscreen/ads7846.c:705:24: warning: taking address
> of packed member 'data' of class or structure 'ads7846_buf' may result
> in an unaligned pointer value [-Waddress-of-packed-member]
>
> Fixes: 6965eece2a89 ("Input: ads7846 - convert to one message")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> drivers/input/touchscreen/ads7846.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> index adb4c2230c31..1987dedac94f 100644
> --- a/drivers/input/touchscreen/ads7846.c
> +++ b/drivers/input/touchscreen/ads7846.c
> @@ -702,7 +702,7 @@ static int ads7846_get_value(struct ads7846_buf *buf)
> {
> int value;
>
> - value = be16_to_cpup(&buf->data);
> + value = get_unaligned_be16(&buf->data);
ds7846_buf is declared as packed so I believe using be16_to_cpu(buf->data)
will suffice.
I can adjust on my side if you agree.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] Input: ads7846: ads7846_get_value - fix unaligned pointer value warning
2021-09-10 5:04 ` Dmitry Torokhov
@ 2021-09-10 7:51 ` Oleksij Rempel
2021-10-17 4:23 ` Dmitry Torokhov
0 siblings, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2021-09-10 7:51 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Alexandru Ardelean, Mark Brown, kernel test robot, kernel,
linux-kernel, linux-input, linux-spi, David Jander
Hi Dmitry,
On Thu, Sep 09, 2021 at 10:04:16PM -0700, Dmitry Torokhov wrote:
> Hi Oleksij,
>
> On Wed, Jul 07, 2021 at 02:41:15PM +0200, Oleksij Rempel wrote:
> > Fix warning reported by the kernel test robot:
> > drivers/input/touchscreen/ads7846.c:705:24: warning: taking address
> > of packed member 'data' of class or structure 'ads7846_buf' may result
> > in an unaligned pointer value [-Waddress-of-packed-member]
> >
> > Fixes: 6965eece2a89 ("Input: ads7846 - convert to one message")
> > Reported-by: kernel test robot <lkp@intel.com>
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> > drivers/input/touchscreen/ads7846.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> > index adb4c2230c31..1987dedac94f 100644
> > --- a/drivers/input/touchscreen/ads7846.c
> > +++ b/drivers/input/touchscreen/ads7846.c
> > @@ -702,7 +702,7 @@ static int ads7846_get_value(struct ads7846_buf *buf)
> > {
> > int value;
> >
> > - value = be16_to_cpup(&buf->data);
> > + value = get_unaligned_be16(&buf->data);
>
> ds7846_buf is declared as packed so I believe using be16_to_cpu(buf->data)
> will suffice.
The pointer to the data is is off by 8 bits, so it is not naturally
aligned. This is why we need to use function which is dealing with
unaligned pointers.
Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] Input: ads7846: ads7846_get_value - fix unaligned pointer value warning
2021-09-10 7:51 ` Oleksij Rempel
@ 2021-10-17 4:23 ` Dmitry Torokhov
0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2021-10-17 4:23 UTC (permalink / raw)
To: Oleksij Rempel
Cc: Alexandru Ardelean, Mark Brown, kernel test robot, kernel,
linux-kernel, linux-input, linux-spi, David Jander
On Fri, Sep 10, 2021 at 09:51:54AM +0200, Oleksij Rempel wrote:
> Hi Dmitry,
>
> On Thu, Sep 09, 2021 at 10:04:16PM -0700, Dmitry Torokhov wrote:
> > Hi Oleksij,
> >
> > On Wed, Jul 07, 2021 at 02:41:15PM +0200, Oleksij Rempel wrote:
> > > Fix warning reported by the kernel test robot:
> > > drivers/input/touchscreen/ads7846.c:705:24: warning: taking address
> > > of packed member 'data' of class or structure 'ads7846_buf' may result
> > > in an unaligned pointer value [-Waddress-of-packed-member]
> > >
> > > Fixes: 6965eece2a89 ("Input: ads7846 - convert to one message")
> > > Reported-by: kernel test robot <lkp@intel.com>
> > > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > > ---
> > > drivers/input/touchscreen/ads7846.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> > > index adb4c2230c31..1987dedac94f 100644
> > > --- a/drivers/input/touchscreen/ads7846.c
> > > +++ b/drivers/input/touchscreen/ads7846.c
> > > @@ -702,7 +702,7 @@ static int ads7846_get_value(struct ads7846_buf *buf)
> > > {
> > > int value;
> > >
> > > - value = be16_to_cpup(&buf->data);
> > > + value = get_unaligned_be16(&buf->data);
> >
> > ds7846_buf is declared as packed so I believe using be16_to_cpu(buf->data)
> > will suffice.
>
> The pointer to the data is is off by 8 bits, so it is not naturally
> aligned. This is why we need to use function which is dealing with
> unaligned pointers.
As I mentioned, the structure is packed, so the compiler will take care
of doing unaligned access safely on architectures that can not tolerate
it.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-17 4:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07 12:41 [PATCH v1] Input: ads7846: ads7846_get_value - fix unaligned pointer value warning Oleksij Rempel
2021-09-10 5:04 ` Dmitry Torokhov
2021-09-10 7:51 ` Oleksij Rempel
2021-10-17 4:23 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).