V4L/DVB: drivers/media/video/em28xx: Remove potential NULL dereference
authorJulia Lawall <julia@diku.dk>
Fri, 27 Aug 2010 05:57:18 +0000 (02:57 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Thu, 21 Oct 2010 03:04:53 +0000 (01:04 -0200)
If the NULL test is necessary, the initialization involving a dereference of
the tested value should be moved after the NULL test.

The sematic patch that fixes this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
type T;
expression E;
identifier i,fld;
statement S;
@@

- T i = E->fld;
+ T i;
  ... when != E
      when != i
  if (E == NULL) S
+ i = E->fld;
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/em28xx/em28xx-video.c

index 7b9ec6e493e4ee43b5534326f6b0c43ed126df7f..95a4b60a1eda496ccef9f74a38399e131b28cfa8 100644 (file)
@@ -277,12 +277,13 @@ static void em28xx_copy_vbi(struct em28xx *dev,
 {
        void *startwrite, *startread;
        int  offset;
-       int bytesperline = dev->vbi_width;
+       int bytesperline;
 
        if (dev == NULL) {
                em28xx_isocdbg("dev is null\n");
                return;
        }
+       bytesperline = dev->vbi_width;
 
        if (dma_q == NULL) {
                em28xx_isocdbg("dma_q is null\n");