Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Julia Lawall


On Tue, 6 Feb 2018, Dan Carpenter wrote:

> That found 4 that I think Wolfram's grep missed.
>
>  arch/um/drivers/vector_user.h |2 --
>  drivers/gpu/drm/mxsfb/mxsfb_regs.h|2 --
>  drivers/video/fbdev/mxsfb.c   |2 --
>  include/drm/drm_scdc_helper.h |3 ---
>
> But it didn't find the two bugs that Geert found where the right side
> wasn't a number literal.
>
> drivers/net/can/m_can/m_can.c:#define RXFC_FWM_MASK (0x7f < 
> RXFC_FWM_SHIFT)

OK, I can easily add this in - I've got rules to protect against reporting
it at the moment.  It may end up with false positives.

> drivers/usb/gadget/udc/goku_udc.h:#define INT_EPnNAK(n) (0x00100 < (n))   
>   /* 0 < n < 4 */

This is indeed harder, because one has to look at the usage site.

julia


Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Dan Carpenter
That found 4 that I think Wolfram's grep missed.

 arch/um/drivers/vector_user.h |2 --
 drivers/gpu/drm/mxsfb/mxsfb_regs.h|2 --
 drivers/video/fbdev/mxsfb.c   |2 --
 include/drm/drm_scdc_helper.h |3 ---

But it didn't find the two bugs that Geert found where the right side
wasn't a number literal.

drivers/net/can/m_can/m_can.c:#define RXFC_FWM_MASK (0x7f < RXFC_FWM_SHIFT)
drivers/usb/gadget/udc/goku_udc.h:#define INT_EPnNAK(n) (0x00100 < (n)) 
/* 0 < n < 4 */

regards,
dan carpenter



Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Wolfram Sang

> I did that too but got no results.  Perhaps right shifting constants is
> pretty uncommon.  I can put that in the complete rule though.

Please do. Even if rare, we would want this bug pointed out, right? :)



signature.asc
Description: PGP signature


Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Julia Lawall


On Tue, 6 Feb 2018, Wolfram Sang wrote:

> Hi Julia,
>
> > and got the results below.  I can make a version for the kernel shortly.
>
> It should probably take care of right-shifting, too?

I did that too but got no results.  Perhaps right shifting constants is
pretty uncommon.  I can put that in the complete rule though.

julia


Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Wolfram Sang
Hi Julia,

> and got the results below.  I can make a version for the kernel shortly.

It should probably take care of right-shifting, too?

Thanks,

   Wolfram



signature.asc
Description: PGP signature


Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Julia Lawall


On Tue, 6 Feb 2018, Dan Carpenter wrote:

> On Tue, Feb 06, 2018 at 02:15:51PM +0100, Julia Lawall wrote:
> >
> >
> > On Tue, 6 Feb 2018, Dan Carpenter wrote:
> >
> > > On Mon, Feb 05, 2018 at 09:09:57PM +0100, Wolfram Sang wrote:
> > > > In one Renesas driver, I found a typo which turned an intended bit 
> > > > shift ('<<')
> > > > into a comparison ('<'). Because this is a subtle issue, I looked tree 
> > > > wide for
> > > > similar patterns. This small patch series is the outcome.
> > > >
> > > > Buildbot and checkpatch are happy. Only compile-tested. To be applied
> > > > individually per sub-system, I think. I'd think only the net: amd: 
> > > > patch needs
> > > > to be conisdered for stable, but I leave this to people who actually 
> > > > know this
> > > > driver.
> > > >
> > > > CCing Dan. Maybe he has an idea how to add a test to smatch? In my 
> > > > setup, only
> > > > cppcheck reported a 'coding style' issue with a low prio.
> > > >
> > >
> > > Most of these are inside macros so it makes it complicated for Smatch
> > > to warn about them.  It might be easier in Coccinelle.  Julia the bugs
> > > look like this:
> > >
> > > - reissue_mask |= 0x < 4;
> > > + reissue_mask |= 0x << 4;
> >
> > Thanks.  I'll take a look.  Do you have an example of the macro issue
> > handy?
> >
>
> It's the same:
>
> #define EXYNOS_CIIMGEFF_PAT_CBCR_MASK  ((0xff < 13) | (0xff < 0))
>
> Smatch only sees the outside of the macro (where it is used in the code)
> and the pre-processed code.

I wrote the following rule:

@@
constant int x,y;
identifier i;
type T;
@@

(
i < x
|
x < i
|
 (T)i < x
|
x < (T)i
|
* x < y
)

and got the results below.  I can make a version for the kernel shortly.

julia

diff -u -p /run/shm/linux-next/drivers/gpu/drm/exynos/regs-fimc.h 
/tmp/nothing/drivers/gpu/drm/exynos/regs-fimc.h
--- /run/shm/linux-next/drivers/gpu/drm/exynos/regs-fimc.h
+++ /tmp/nothing/drivers/gpu/drm/exynos/regs-fimc.h
@@ -569,7 +569,6 @@
 #define EXYNOS_CIIMGEFF_FIN_EMBOSSING  (4 << 26)
 #define EXYNOS_CIIMGEFF_FIN_SILHOUETTE (5 << 26)
 #define EXYNOS_CIIMGEFF_FIN_MASK   (7 << 26)
-#define EXYNOS_CIIMGEFF_PAT_CBCR_MASK  ((0xff < 13) | (0xff < 0))

 /* Real input DMA size register */
 #define EXYNOS_CIREAL_ISIZE_AUTOLOAD_ENABLE(1 << 31)
diff -u -p /run/shm/linux-next/drivers/net/ethernet/amd/xgbe/xgbe-drv.c 
/tmp/nothing/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
--- /run/shm/linux-next/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ /tmp/nothing/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -595,7 +595,6 @@ isr_done:

reissue_mask = 1 << 0;
if (!pdata->per_channel_irq)
-   reissue_mask |= 0x < 4;

XP_IOWRITE(pdata, XP_INT_REISSUE_EN, reissue_mask);
}
diff -u -p /run/shm/linux-next/drivers/video/fbdev/mxsfb.c 
/tmp/nothing/drivers/video/fbdev/mxsfb.c
--- /run/shm/linux-next/drivers/video/fbdev/mxsfb.c
+++ /tmp/nothing/drivers/video/fbdev/mxsfb.c
@@ -133,8 +133,6 @@
 #define VDCTRL4_SYNC_SIGNALS_ON(1 << 18)
 #define SET_DOTCLK_H_VALID_DATA_CNT(x) ((x) & 0x3)

-#define DEBUG0_HSYNC   (1 < 26)
-#define DEBUG0_VSYNC   (1 < 25)

 #define MIN_XRES   120
 #define MIN_YRES   120
diff -u -p /run/shm/linux-next/include/drm/drm_scdc_helper.h 
/tmp/nothing/include/drm/drm_scdc_helper.h
--- /run/shm/linux-next/include/drm/drm_scdc_helper.h
+++ /tmp/nothing/include/drm/drm_scdc_helper.h
@@ -50,9 +50,6 @@
 #define  SCDC_READ_REQUEST_ENABLE (1 << 0)

 #define SCDC_STATUS_FLAGS_0 0x40
-#define  SCDC_CH2_LOCK (1 < 3)
-#define  SCDC_CH1_LOCK (1 < 2)
-#define  SCDC_CH0_LOCK (1 < 1)
 #define  SCDC_CH_LOCK_MASK (SCDC_CH2_LOCK | SCDC_CH1_LOCK | SCDC_CH0_LOCK)
 #define  SCDC_CLOCK_DETECT (1 << 0)

diff -u -p /run/shm/linux-next/arch/um/drivers/vector_user.h 
/tmp/nothing/arch/um/drivers/vector_user.h
--- /run/shm/linux-next/arch/um/drivers/vector_user.h
+++ /tmp/nothing/arch/um/drivers/vector_user.h
@@ -61,8 +61,6 @@ struct vector_fds {
 };

 #define VECTOR_READ1
-#define VECTOR_WRITE   (1 < 1)
-#define VECTOR_HEADERS (1 < 2)

 extern struct arglist *uml_parse_vector_ifspec(char *arg);

diff -u -p /run/shm/linux-next/drivers/gpu/drm/mxsfb/mxsfb_regs.h 
/tmp/nothing/drivers/gpu/drm/mxsfb/mxsfb_regs.h
--- /run/shm/linux-next/drivers/gpu/drm/mxsfb/mxsfb_regs.h
+++ /tmp/nothing/drivers/gpu/drm/mxsfb/mxsfb_regs.h
@@ -91,8 +91,6 @@
 #define VDCTRL4_SYNC_SIGNALS_ON(1 << 18)
 #define SET_DOTCLK_H_VALID_DATA_CNT(x) ((x) & 0x3)

-#define DEBUG0_HSYNC   (1 < 26)
-#define DEBUG0_VSYNC   (1 < 25)

 #define MXSFB_MIN_XRES 120
 #define MXSFB_MIN_YRES 120
diff -u -p /run/shm/linux-next/drivers/media/platform/vsp1/vsp1_regs.h 
/tmp/nothing/drivers/media/platform/vsp1/vsp1_regs.h
--- 

Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Dan Carpenter
On Tue, Feb 06, 2018 at 02:15:51PM +0100, Julia Lawall wrote:
> 
> 
> On Tue, 6 Feb 2018, Dan Carpenter wrote:
> 
> > On Mon, Feb 05, 2018 at 09:09:57PM +0100, Wolfram Sang wrote:
> > > In one Renesas driver, I found a typo which turned an intended bit shift 
> > > ('<<')
> > > into a comparison ('<'). Because this is a subtle issue, I looked tree 
> > > wide for
> > > similar patterns. This small patch series is the outcome.
> > >
> > > Buildbot and checkpatch are happy. Only compile-tested. To be applied
> > > individually per sub-system, I think. I'd think only the net: amd: patch 
> > > needs
> > > to be conisdered for stable, but I leave this to people who actually know 
> > > this
> > > driver.
> > >
> > > CCing Dan. Maybe he has an idea how to add a test to smatch? In my setup, 
> > > only
> > > cppcheck reported a 'coding style' issue with a low prio.
> > >
> >
> > Most of these are inside macros so it makes it complicated for Smatch
> > to warn about them.  It might be easier in Coccinelle.  Julia the bugs
> > look like this:
> >
> > -   reissue_mask |= 0x < 4;
> > +   reissue_mask |= 0x << 4;
> 
> Thanks.  I'll take a look.  Do you have an example of the macro issue
> handy?
> 

It's the same:

#define EXYNOS_CIIMGEFF_PAT_CBCR_MASK  ((0xff < 13) | (0xff < 0)) 

Smatch only sees the outside of the macro (where it is used in the code)
and the pre-processed code.

regards,
dan carpenter



Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Julia Lawall


On Tue, 6 Feb 2018, Dan Carpenter wrote:

> On Mon, Feb 05, 2018 at 09:09:57PM +0100, Wolfram Sang wrote:
> > In one Renesas driver, I found a typo which turned an intended bit shift 
> > ('<<')
> > into a comparison ('<'). Because this is a subtle issue, I looked tree wide 
> > for
> > similar patterns. This small patch series is the outcome.
> >
> > Buildbot and checkpatch are happy. Only compile-tested. To be applied
> > individually per sub-system, I think. I'd think only the net: amd: patch 
> > needs
> > to be conisdered for stable, but I leave this to people who actually know 
> > this
> > driver.
> >
> > CCing Dan. Maybe he has an idea how to add a test to smatch? In my setup, 
> > only
> > cppcheck reported a 'coding style' issue with a low prio.
> >
>
> Most of these are inside macros so it makes it complicated for Smatch
> to warn about them.  It might be easier in Coccinelle.  Julia the bugs
> look like this:
>
> - reissue_mask |= 0x < 4;
> + reissue_mask |= 0x << 4;

Thanks.  I'll take a look.  Do you have an example of the macro issue
handy?

julia

>
> regards,
> dan carpenter
>
> > Wolfram Sang (4):
> >   v4l: vsp1: fix mask creation for MULT_ALPHA_RATIO
> >   drm/exynos: fix comparison to bitshift when dealing with a mask
> >   v4l: dvb-frontends: stb0899: fix comparison to bitshift when dealing
> > with a mask
> >   net: amd-xgbe: fix comparison to bitshift when dealing with a mask
> >
> >  drivers/gpu/drm/exynos/regs-fimc.h| 2 +-
> >  drivers/media/dvb-frontends/stb0899_reg.h | 8 
> >  drivers/media/platform/vsp1/vsp1_regs.h   | 2 +-
> >  drivers/net/ethernet/amd/xgbe/xgbe-drv.c  | 2 +-
> >  4 files changed, 7 insertions(+), 7 deletions(-)
> >
> > --
> > 2.11.0
>


Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Dan Carpenter
On Mon, Feb 05, 2018 at 09:09:57PM +0100, Wolfram Sang wrote:
> In one Renesas driver, I found a typo which turned an intended bit shift 
> ('<<')
> into a comparison ('<'). Because this is a subtle issue, I looked tree wide 
> for
> similar patterns. This small patch series is the outcome.
> 
> Buildbot and checkpatch are happy. Only compile-tested. To be applied
> individually per sub-system, I think. I'd think only the net: amd: patch needs
> to be conisdered for stable, but I leave this to people who actually know this
> driver.
> 
> CCing Dan. Maybe he has an idea how to add a test to smatch? In my setup, only
> cppcheck reported a 'coding style' issue with a low prio.
> 

Most of these are inside macros so it makes it complicated for Smatch
to warn about them.  It might be easier in Coccinelle.  Julia the bugs
look like this:

-   reissue_mask |= 0x < 4;
+   reissue_mask |= 0x << 4;

regards,
dan carpenter

> Wolfram Sang (4):
>   v4l: vsp1: fix mask creation for MULT_ALPHA_RATIO
>   drm/exynos: fix comparison to bitshift when dealing with a mask
>   v4l: dvb-frontends: stb0899: fix comparison to bitshift when dealing
> with a mask
>   net: amd-xgbe: fix comparison to bitshift when dealing with a mask
> 
>  drivers/gpu/drm/exynos/regs-fimc.h| 2 +-
>  drivers/media/dvb-frontends/stb0899_reg.h | 8 
>  drivers/media/platform/vsp1/vsp1_regs.h   | 2 +-
>  drivers/net/ethernet/amd/xgbe/xgbe-drv.c  | 2 +-
>  4 files changed, 7 insertions(+), 7 deletions(-)
> 
> -- 
> 2.11.0


Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Wolfram Sang

> I found two more using "git grep 'define.*0x[0-9a-f]* < '":

I added '[0-9]\+' at the end of the regex to reduce the number of false
positives...

> drivers/net/can/m_can/m_can.c:#define RXFC_FWM_MASK (0x7f < 
> RXFC_FWM_SHIFT)
> drivers/usb/gadget/udc/goku_udc.h:#define INT_EPnNAK(n)
> (0x00100 < (n)) /* 0 < n < 4 */

... but you found those two true positives in there. Nice, thanks!



signature.asc
Description: PGP signature


Re: [PATCH 0/4] tree-wide: fix comparison to bitshift when dealing with a mask

2018-02-06 Thread Geert Uytterhoeven
Hi Wolfram,

On Mon, Feb 5, 2018 at 9:09 PM, Wolfram Sang
 wrote:
> In one Renesas driver, I found a typo which turned an intended bit shift 
> ('<<')
> into a comparison ('<'). Because this is a subtle issue, I looked tree wide 
> for
> similar patterns. This small patch series is the outcome.
>
> Buildbot and checkpatch are happy. Only compile-tested. To be applied
> individually per sub-system, I think. I'd think only the net: amd: patch needs
> to be conisdered for stable, but I leave this to people who actually know this
> driver.
>
> CCing Dan. Maybe he has an idea how to add a test to smatch? In my setup, only
> cppcheck reported a 'coding style' issue with a low prio.

I found two more using "git grep 'define.*0x[0-9a-f]* < '":

drivers/net/can/m_can/m_can.c:#define RXFC_FWM_MASK (0x7f < RXFC_FWM_SHIFT)
drivers/usb/gadget/udc/goku_udc.h:#define INT_EPnNAK(n)
(0x00100 < (n)) /* 0 < n < 4 */

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds