Skip to contentSkip to conversation

video: atmel_lcdc: Fix Shifting signed 32 bit value by 31 bits problem

PATCH New Shobhit Kukreti 3 participants 6 messages Jul 6, 2019 – Jan 8, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 video: atmel_lcdc: Fix Shifting signed 32 bit value by 31 bits problem

Fix ATMEL_LCDC_MEMOR and ATMEL_LCDC_MEMOR_LITTLE defines to use "U" cast to avoid shifting signed 32 bit values by 31 bit problem. This problem. This is not a problem for gcc built kernel.

However, this may be a problem since the header is part of pbulic API which could be included for builds using compilers which do not handle this condition safely resulting in undefined behavior

Signed-off-by Shobhit Kukreti <shobhitkukreti at gmail.com>
---
 include/video/atmel_lcdc.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/video/atmel_lcdc.h +2 -2
index 43e497c..ac96b4f 100644
@@ -103,9 +103,9 @@ struct atmel_lcdfb_pdata {
 #define	ATMEL_LCDC_CLKMOD	(1 << 15)
 #define		ATMEL_LCDC_CLKMOD_ACTIVEDISPLAY	(0 << 15)
 #define		ATMEL_LCDC_CLKMOD_ALWAYSACTIVE	(1 << 15)
-#define	ATMEL_LCDC_MEMOR	(1 << 31)
+#define	ATMEL_LCDC_MEMOR	(1U << 31)
 #define		ATMEL_LCDC_MEMOR_BIG		(0 << 31)
-#define		ATMEL_LCDC_MEMOR_LITTLE		(1 << 31)
+#define		ATMEL_LCDC_MEMOR_LITTLE		(1U << 31)
 
 #define ATMEL_LCDC_TIM1		0x0808
 #define	ATMEL_LCDC_VFP		(0xffU <<  0)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/1 video: atmel_lcdc: Fix Shifting signed 32 bit value by 31 bits problem

From: Shobhit Kukreti <[email protected]>

Fix ATMEL_LCDC_MEMOR and ATMEL_LCDC_MEMOR_LITTLE defines to use "U" cast to avoid shifting signed 32 bit values by 31 bit problem. This is not a problem for gcc built kernel.

However, this may be a problem since the header is part of public API which could be included for builds using compilers which do not handle this condition safely resulting in undefined behavior

Signed-off-by Shobhit Kukreti <shobhitkukreti at gmail.com>

---
Changes in v2:
Fixed spelling typo

 include/video/atmel_lcdc.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/video/atmel_lcdc.h +2 -2
index 43e497c..ac96b4f 100644
@@ -103,9 +103,9 @@ struct atmel_lcdfb_pdata {
 #define	ATMEL_LCDC_CLKMOD	(1 << 15)
 #define		ATMEL_LCDC_CLKMOD_ACTIVEDISPLAY	(0 << 15)
 #define		ATMEL_LCDC_CLKMOD_ALWAYSACTIVE	(1 << 15)
-#define	ATMEL_LCDC_MEMOR	(1 << 31)
+#define	ATMEL_LCDC_MEMOR	(1U << 31)
 #define		ATMEL_LCDC_MEMOR_BIG		(0 << 31)
-#define		ATMEL_LCDC_MEMOR_LITTLE		(1 << 31)
+#define		ATMEL_LCDC_MEMOR_LITTLE		(1U << 31)
 
 #define ATMEL_LCDC_TIM1		0x0808
 #define	ATMEL_LCDC_VFP		(0xffU <<  0)
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 1/1 video: atmel_lcdc: Fix Shifting signed 32 bit value by 31 bits problem

Hi,

Quoted 11 lines · shobhitkukreti at gmail.com

From: Shobhit Kukreti <shobhitkukreti at gmail.com>

Fix ATMEL_LCDC_MEMOR and ATMEL_LCDC_MEMOR_LITTLE defines to use "U" cast to avoid shifting signed 32 bit values by 31 bit problem. This is not a problem for gcc built kernel.

However, this may be a problem since the header is part of public API which could be included for builds using compilers which do not handle this condition safely resulting in undefined behavior

Signed-off-by Shobhit Kukreti <shobhitkukreti at gmail.com>

While you are at it please convert atmel_lcdc.h to use BIT() macro.

Quoted 13 lines

---
Changes in v2:
Fixed spelling typo

 include/video/atmel_lcdc.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/video/atmel_lcdc.h +0 -0
index 43e497c..ac96b4f 100644
@@ -103,9 +103,9 @@ struct atmel_lcdfb_pdata {
 #define	ATMEL_LCDC_CLKMOD	(1 << 15)

include/video/atmel_lcdc.h struct atmel_lcdfb_pdata { · line 111

Quoted 10 lines
include/video/atmel_lcdc.h +2 -2
 #define		ATMEL_LCDC_CLKMOD_ACTIVEDISPLAY	(0 << 15)
 #define		ATMEL_LCDC_CLKMOD_ALWAYSACTIVE	(1 << 15)
-#define	ATMEL_LCDC_MEMOR	(1 << 31)
+#define	ATMEL_LCDC_MEMOR	(1U << 31)
 #define		ATMEL_LCDC_MEMOR_BIG		(0 << 31)
-#define		ATMEL_LCDC_MEMOR_LITTLE		(1 << 31)
+#define		ATMEL_LCDC_MEMOR_LITTLE		(1U << 31)
 
 #define ATMEL_LCDC_TIM1		0x0808
 #define	ATMEL_LCDC_VFP		(0xffU <<  0)

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

#3 lore raw

PATCH v3 1/1 video: atmel_lcdc: Fix Shifting signed 32 bit value by 31 bits problem

Fix ATMEL_LCDC_MEMOR and ATMEL_LCDC_MEMOR_LITTLE defines to use "U" cast to avoid shifting signed 32 bit values by 31 bit problem. This problem. This is not a problem for gcc built kernel.

However, this may be a problem since the header is part of pbulic API which could be included for builds using compilers which do not handle this condition safely resulting in undefined behavior

Signed-off-by Shobhit Kukreti <shobhitkukreti at gmail.com>

---
Changes in v3:
Replace Bit Shift Operations with BIT() macros

Changes in v2:
Fixed spelling typo

 include/video/atmel_lcdc.h | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
include/video/atmel_lcdc.h +14 -14
index 43e497c..985e2d6 100644
@@ -85,27 +85,27 @@ struct atmel_lcdfb_pdata {
 #define		ATMEL_LCDC_PIXELSIZE_16		(4 << 5)
 #define		ATMEL_LCDC_PIXELSIZE_24		(5 << 5)
 #define		ATMEL_LCDC_PIXELSIZE_32		(6 << 5)
-#define	ATMEL_LCDC_INVVD	(1 << 8)
+#define	ATMEL_LCDC_INVVD	BIT(8)
 #define		ATMEL_LCDC_INVVD_NORMAL		(0 << 8)
-#define		ATMEL_LCDC_INVVD_INVERTED	(1 << 8)
-#define	ATMEL_LCDC_INVFRAME	(1 << 9 )
+#define		ATMEL_LCDC_INVVD_INVERTED	BIT(8)
+#define	ATMEL_LCDC_INVFRAME	BIT(9)
 #define		ATMEL_LCDC_INVFRAME_NORMAL	(0 << 9)
-#define		ATMEL_LCDC_INVFRAME_INVERTED	(1 << 9)
-#define	ATMEL_LCDC_INVLINE	(1 << 10)
+#define		ATMEL_LCDC_INVFRAME_INVERTED	BIT(9)
+#define	ATMEL_LCDC_INVLINE	BIT(10)
 #define		ATMEL_LCDC_INVLINE_NORMAL	(0 << 10)
-#define		ATMEL_LCDC_INVLINE_INVERTED	(1 << 10)
-#define	ATMEL_LCDC_INVCLK	(1 << 11)
+#define		ATMEL_LCDC_INVLINE_INVERTED	BIT(10)
+#define	ATMEL_LCDC_INVCLK	BIT(11)
 #define		ATMEL_LCDC_INVCLK_NORMAL	(0 << 11)
-#define		ATMEL_LCDC_INVCLK_INVERTED	(1 << 11)
-#define	ATMEL_LCDC_INVDVAL	(1 << 12)
+#define		ATMEL_LCDC_INVCLK_INVERTED	BIT(11)
+#define	ATMEL_LCDC_INVDVAL	BIT(12)
 #define		ATMEL_LCDC_INVDVAL_NORMAL	(0 << 12)
-#define		ATMEL_LCDC_INVDVAL_INVERTED	(1 << 12)
-#define	ATMEL_LCDC_CLKMOD	(1 << 15)
+#define		ATMEL_LCDC_INVDVAL_INVERTED	BIT(12)
+#define	ATMEL_LCDC_CLKMOD	BIT(15)
 #define		ATMEL_LCDC_CLKMOD_ACTIVEDISPLAY	(0 << 15)
-#define		ATMEL_LCDC_CLKMOD_ALWAYSACTIVE	(1 << 15)
-#define	ATMEL_LCDC_MEMOR	(1 << 31)
+#define		ATMEL_LCDC_CLKMOD_ALWAYSACTIVE	BIT(15)
+#define	ATMEL_LCDC_MEMOR	BIT(31)
 #define		ATMEL_LCDC_MEMOR_BIG		(0 << 31)
-#define		ATMEL_LCDC_MEMOR_LITTLE		(1 << 31)
+#define		ATMEL_LCDC_MEMOR_LITTLE		BIT(31)
 
 #define ATMEL_LCDC_TIM1		0x0808
 #define	ATMEL_LCDC_VFP		(0xffU <<  0)
Signature · 1 line
2.7.4
#4 lore raw

PATCH v3 1/1 video: atmel_lcdc: Fix Shifting signed 32 bit value by 31 bits problem

Hi,

Quoted 4 lines · Shobhit Kukreti

Fix ATMEL_LCDC_MEMOR and ATMEL_LCDC_MEMOR_LITTLE defines to use "U" cast to avoid shifting signed 32 bit values by 31 bit problem. This problem. This is not a problem for gcc built kernel.

Quoted 8 lines

However, this may be a problem since the header is part of pbulic API which could be included for builds using compilers which do not handle this condition safely resulting in undefined behavior

Signed-off-by Shobhit Kukreti <shobhitkukreti at gmail.com>

---
Changes in v3:
Replace Bit Shift Operations with BIT() macros

1. Please update the patch summary & description to reflect that, please see commit 13990cf8a180 for the reference:

commit 13990cf8a180cc070f0b1266140e799db8754289

Author: Amol Surati <suratiamol at gmail.com>
Date:   Sun Jul 7 14:27:29 2019 +0530

ide: use BIT() macro for defining bit-flags

The BIT() macro is available for defining the required bit-flags.

Since it operates on an unsigned value and expands to an unsigned result, using it, instead of an expression like (1 << x), also fixes the problem of shifting a signed 32-bit value by 31 bits (e.g. 1 << 31).

Signed-off-by Amol Surati <suratiamol at gmail.com>
Signed-off-by David S. Miller <davem at davemloft.net>

2. Please update Cc: list of your mail by all mailing lists returned by ./scripts/get_maintainer.pl:

$ ./scripts/get_maintainer.pl -f include/video/atmel_lcdc.h
Nicolas Ferre <nicolas.ferre at microchip.com> (maintainer:MICROCHIP LCDFB DRIVER)
Bartlomiej Zolnierkiewicz <b.zolnierkie at samsung.com> (maintainer:FRAMEBUFFER LAYER)
Alexandre Belloni <alexandre.belloni at bootlin.com> (supporter:ARM/Microchip (AT91) SoC support)
Ludovic Desroches <ludovic.desroches at microchip.com> (supporter:ARM/Microchip (AT91) SoC support)
linux-fbdev at vger.kernel.org (open list:MICROCHIP LCDFB DRIVER)
dri-devel at lists.freedesktop.org (open list:FRAMEBUFFER LAYER)
linux-arm-kernel at lists.infradead.org (moderated list:ARM/Microchip (AT91) SoC support)
linux-kernel at vger.kernel.org (open list)
Quoted 5 lines

Changes in v2:
Fixed spelling typo

 include/video/atmel_lcdc.h | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

maintainer Acked-by on v3 1/1
#5 lore raw
In reply to shobhitkukreti at gmail.com (Shobhit Kukreti)
Quoted 3 lines · Shobhit Kukreti

Fix ATMEL_LCDC_MEMOR and ATMEL_LCDC_MEMOR_LITTLE defines to use "U" cast to avoid shifting signed 32 bit values by 31 bit problem. This problem. This is not a problem for gcc built kernel.

Chuck of a sentence remaining.

Quoted 1 line

However, this may be a problem since the header is part of pbulic API

Typo
+
no, this header is not part of public API.

Quoted 4 lines

which could be included for builds using compilers which do not handle this condition safely resulting in undefined behavior

No strong opinion, but once typo and commit message is fixed, you can add my:

Regards,
Nicolas

Quoted 57 lines

---
Changes in v3:
Replace Bit Shift Operations with BIT() macros

Changes in v2:
Fixed spelling typo

  include/video/atmel_lcdc.h | 28 ++++++++++++++--------------
  1 file changed, 14 insertions(+), 14 deletions(-)
include/video/atmel_lcdc.h +14 -14
index 43e497c..985e2d6 100644
@@ -85,27 +85,27 @@ struct atmel_lcdfb_pdata {
  #define		ATMEL_LCDC_PIXELSIZE_16		(4 << 5)
  #define		ATMEL_LCDC_PIXELSIZE_24		(5 << 5)
  #define		ATMEL_LCDC_PIXELSIZE_32		(6 << 5)
-#define	ATMEL_LCDC_INVVD	(1 << 8)
+#define	ATMEL_LCDC_INVVD	BIT(8)
  #define		ATMEL_LCDC_INVVD_NORMAL		(0 << 8)
-#define		ATMEL_LCDC_INVVD_INVERTED	(1 << 8)
-#define	ATMEL_LCDC_INVFRAME	(1 << 9 )
+#define		ATMEL_LCDC_INVVD_INVERTED	BIT(8)
+#define	ATMEL_LCDC_INVFRAME	BIT(9)
  #define		ATMEL_LCDC_INVFRAME_NORMAL	(0 << 9)
-#define		ATMEL_LCDC_INVFRAME_INVERTED	(1 << 9)
-#define	ATMEL_LCDC_INVLINE	(1 << 10)
+#define		ATMEL_LCDC_INVFRAME_INVERTED	BIT(9)
+#define	ATMEL_LCDC_INVLINE	BIT(10)
  #define		ATMEL_LCDC_INVLINE_NORMAL	(0 << 10)
-#define		ATMEL_LCDC_INVLINE_INVERTED	(1 << 10)
-#define	ATMEL_LCDC_INVCLK	(1 << 11)
+#define		ATMEL_LCDC_INVLINE_INVERTED	BIT(10)
+#define	ATMEL_LCDC_INVCLK	BIT(11)
  #define		ATMEL_LCDC_INVCLK_NORMAL	(0 << 11)
-#define		ATMEL_LCDC_INVCLK_INVERTED	(1 << 11)
-#define	ATMEL_LCDC_INVDVAL	(1 << 12)
+#define		ATMEL_LCDC_INVCLK_INVERTED	BIT(11)
+#define	ATMEL_LCDC_INVDVAL	BIT(12)
  #define		ATMEL_LCDC_INVDVAL_NORMAL	(0 << 12)
-#define		ATMEL_LCDC_INVDVAL_INVERTED	(1 << 12)
-#define	ATMEL_LCDC_CLKMOD	(1 << 15)
+#define		ATMEL_LCDC_INVDVAL_INVERTED	BIT(12)
+#define	ATMEL_LCDC_CLKMOD	BIT(15)
  #define		ATMEL_LCDC_CLKMOD_ACTIVEDISPLAY	(0 << 15)
-#define		ATMEL_LCDC_CLKMOD_ALWAYSACTIVE	(1 << 15)
-#define	ATMEL_LCDC_MEMOR	(1 << 31)
+#define		ATMEL_LCDC_CLKMOD_ALWAYSACTIVE	BIT(15)
+#define	ATMEL_LCDC_MEMOR	BIT(31)
  #define		ATMEL_LCDC_MEMOR_BIG		(0 << 31)
-#define		ATMEL_LCDC_MEMOR_LITTLE		(1 << 31)
+#define		ATMEL_LCDC_MEMOR_LITTLE		BIT(31)
 
  #define ATMEL_LCDC_TIM1		0x0808
  #define	ATMEL_LCDC_VFP		(0xffU <<  0)
Signature · 5 lines
Nicolas Ferre
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees