diff mbox series

[4/8] iio: chemical: pms7003: use aligned_s64 for timestamp

Message ID 20250417-iio-more-timestamp-alignment-v1-4-eafac1e22318@baylibre.com (mailing list archive)
State New
Headers show
Series iio: more timestamp alignment | expand

Commit Message

David Lechner April 17, 2025, 4:52 p.m. UTC
Follow the pattern of other drivers and use aligned_s64 for the
timestamp. This will ensure that the timestamp is correctly aligned on
all architectures.

Also move the unaligned.h header while touching this since it was the
only one not in alphabetical order.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/chemical/pms7003.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Jonathan Cameron April 17, 2025, 5:35 p.m. UTC | #1
On Thu, 17 Apr 2025 11:52:36 -0500
David Lechner <dlechner@baylibre.com> wrote:

> Follow the pattern of other drivers and use aligned_s64 for the
> timestamp. This will ensure that the timestamp is correctly aligned on
> all architectures.
> 
> Also move the unaligned.h header while touching this since it was the
> only one not in alphabetical order.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>  drivers/iio/chemical/pms7003.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/chemical/pms7003.c b/drivers/iio/chemical/pms7003.c
> index d0bd94912e0a3492641acd955adbc2184f4a11b3..e05ce1f12065c65d14b66ab86e291fab47805dec 100644
> --- a/drivers/iio/chemical/pms7003.c
> +++ b/drivers/iio/chemical/pms7003.c
> @@ -5,7 +5,6 @@
>   * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
>   */
>  
> -#include <linux/unaligned.h>
>  #include <linux/completion.h>
>  #include <linux/device.h>
>  #include <linux/errno.h>
> @@ -19,6 +18,8 @@
>  #include <linux/module.h>
>  #include <linux/mutex.h>
>  #include <linux/serdev.h>
> +#include <linux/types.h>
> +#include <linux/unaligned.h>
>  
>  #define PMS7003_DRIVER_NAME "pms7003"
>  
> @@ -76,7 +77,7 @@ struct pms7003_state {
>  	/* Used to construct scan to push to the IIO buffer */
>  	struct {
>  		u16 data[3]; /* PM1, PM2P5, PM10 */
> -		s64 ts;
> +		aligned_s64 ts;

Bug I think..  So another one that really needs a fixes tag.
For all these we might be lucky with padding on the allocations
but we shouldn't really rely on that.

>  	} scan;
>  };
>  
>
Nuno Sá April 18, 2025, 8:51 a.m. UTC | #2
On Thu, 2025-04-17 at 18:35 +0100, Jonathan Cameron wrote:
> On Thu, 17 Apr 2025 11:52:36 -0500
> David Lechner <dlechner@baylibre.com> wrote:
> 
> > Follow the pattern of other drivers and use aligned_s64 for the
> > timestamp. This will ensure that the timestamp is correctly aligned on
> > all architectures.
> > 
> > Also move the unaligned.h header while touching this since it was the
> > only one not in alphabetical order.
> > 
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---
> >  drivers/iio/chemical/pms7003.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/chemical/pms7003.c b/drivers/iio/chemical/pms7003.c
> > index
> > d0bd94912e0a3492641acd955adbc2184f4a11b3..e05ce1f12065c65d14b66ab86e291fab47805de
> > c 100644
> > --- a/drivers/iio/chemical/pms7003.c
> > +++ b/drivers/iio/chemical/pms7003.c
> > @@ -5,7 +5,6 @@
> >   * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
> >   */
> >  
> > -#include <linux/unaligned.h>
> >  #include <linux/completion.h>
> >  #include <linux/device.h>
> >  #include <linux/errno.h>
> > @@ -19,6 +18,8 @@
> >  #include <linux/module.h>
> >  #include <linux/mutex.h>
> >  #include <linux/serdev.h>
> > +#include <linux/types.h>
> > +#include <linux/unaligned.h>
> >  
> >  #define PMS7003_DRIVER_NAME "pms7003"
> >  
> > @@ -76,7 +77,7 @@ struct pms7003_state {
> >  	/* Used to construct scan to push to the IIO buffer */
> >  	struct {
> >  		u16 data[3]; /* PM1, PM2P5, PM10 */
> > -		s64 ts;
> > +		aligned_s64 ts;
> 
> Bug I think..  So another one that really needs a fixes tag.
> For all these we might be lucky with padding on the allocations
> but we shouldn't really rely on that.

Agreed... We're likely not that lucky for x86-32

- Nuno Sá
> 
> >  	} scan;
> >  };
> >  
> > 
>
Nuno Sá April 18, 2025, 8:58 a.m. UTC | #3
On Thu, 2025-04-17 at 11:52 -0500, David Lechner wrote:
> Follow the pattern of other drivers and use aligned_s64 for the
> timestamp. This will ensure that the timestamp is correctly aligned on
> all architectures.
> 
> Also move the unaligned.h header while touching this since it was the
> only one not in alphabetical order.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---

With the tag:

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  drivers/iio/chemical/pms7003.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/chemical/pms7003.c b/drivers/iio/chemical/pms7003.c
> index
> d0bd94912e0a3492641acd955adbc2184f4a11b3..e05ce1f12065c65d14b66ab86e291fab47805dec
> 100644
> --- a/drivers/iio/chemical/pms7003.c
> +++ b/drivers/iio/chemical/pms7003.c
> @@ -5,7 +5,6 @@
>   * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
>   */
>  
> -#include <linux/unaligned.h>
>  #include <linux/completion.h>
>  #include <linux/device.h>
>  #include <linux/errno.h>
> @@ -19,6 +18,8 @@
>  #include <linux/module.h>
>  #include <linux/mutex.h>
>  #include <linux/serdev.h>
> +#include <linux/types.h>
> +#include <linux/unaligned.h>
>  
>  #define PMS7003_DRIVER_NAME "pms7003"
>  
> @@ -76,7 +77,7 @@ struct pms7003_state {
>  	/* Used to construct scan to push to the IIO buffer */
>  	struct {
>  		u16 data[3]; /* PM1, PM2P5, PM10 */
> -		s64 ts;
> +		aligned_s64 ts;
>  	} scan;
>  };
>  
>
Jonathan Cameron April 18, 2025, 2:51 p.m. UTC | #4
On Fri, 18 Apr 2025 09:51:37 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Thu, 2025-04-17 at 18:35 +0100, Jonathan Cameron wrote:
> > On Thu, 17 Apr 2025 11:52:36 -0500
> > David Lechner <dlechner@baylibre.com> wrote:
> >   
> > > Follow the pattern of other drivers and use aligned_s64 for the
> > > timestamp. This will ensure that the timestamp is correctly aligned on
> > > all architectures.
> > > 
> > > Also move the unaligned.h header while touching this since it was the
> > > only one not in alphabetical order.
> > > 
> > > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > > ---
> > >  drivers/iio/chemical/pms7003.c | 5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/iio/chemical/pms7003.c b/drivers/iio/chemical/pms7003.c
> > > index
> > > d0bd94912e0a3492641acd955adbc2184f4a11b3..e05ce1f12065c65d14b66ab86e291fab47805de
> > > c 100644
> > > --- a/drivers/iio/chemical/pms7003.c
> > > +++ b/drivers/iio/chemical/pms7003.c
> > > @@ -5,7 +5,6 @@
> > >   * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
> > >   */
> > >  
> > > -#include <linux/unaligned.h>
> > >  #include <linux/completion.h>
> > >  #include <linux/device.h>
> > >  #include <linux/errno.h>
> > > @@ -19,6 +18,8 @@
> > >  #include <linux/module.h>
> > >  #include <linux/mutex.h>
> > >  #include <linux/serdev.h>
> > > +#include <linux/types.h>
> > > +#include <linux/unaligned.h>
> > >  
> > >  #define PMS7003_DRIVER_NAME "pms7003"
> > >  
> > > @@ -76,7 +77,7 @@ struct pms7003_state {
> > >  	/* Used to construct scan to push to the IIO buffer */
> > >  	struct {
> > >  		u16 data[3]; /* PM1, PM2P5, PM10 */
> > > -		s64 ts;
> > > +		aligned_s64 ts;  
> > 
> > Bug I think..  So another one that really needs a fixes tag.
> > For all these we might be lucky with padding on the allocations
> > but we shouldn't really rely on that.  
> 
> Agreed... We're likely not that lucky for x86-32
Applied with
Fixes: 13e945631c2f ("iio:chemical:pms7003: Fix timestamp alignment and prevent data leak.")
and +CC stable.
> 
> - Nuno Sá
> >   
> > >  	} scan;
> > >  };
> > >  
> > >   
> >   
> 
>
diff mbox series

Patch

diff --git a/drivers/iio/chemical/pms7003.c b/drivers/iio/chemical/pms7003.c
index d0bd94912e0a3492641acd955adbc2184f4a11b3..e05ce1f12065c65d14b66ab86e291fab47805dec 100644
--- a/drivers/iio/chemical/pms7003.c
+++ b/drivers/iio/chemical/pms7003.c
@@ -5,7 +5,6 @@ 
  * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
  */
 
-#include <linux/unaligned.h>
 #include <linux/completion.h>
 #include <linux/device.h>
 #include <linux/errno.h>
@@ -19,6 +18,8 @@ 
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/serdev.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
 
 #define PMS7003_DRIVER_NAME "pms7003"
 
@@ -76,7 +77,7 @@  struct pms7003_state {
 	/* Used to construct scan to push to the IIO buffer */
 	struct {
 		u16 data[3]; /* PM1, PM2P5, PM10 */
-		s64 ts;
+		aligned_s64 ts;
 	} scan;
 };