media: ddbridge: check pointers before dereferencing
authorDaniel Scheller <d.scheller@gmx.net>
Sat, 12 Aug 2017 11:55:55 +0000 (07:55 -0400)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Sun, 20 Aug 2017 11:06:21 +0000 (07:06 -0400)
Fixes two warnings reported by smatch:

  drivers/media/pci/ddbridge/ddbridge-core.c:240 ddb_redirect() warn: variable dereferenced before check 'idev' (see line 238)
  drivers/media/pci/ddbridge/ddbridge-core.c:240 ddb_redirect() warn: variable dereferenced before check 'pdev' (see line 238)

Fixed by moving the existing checks up before accessing members.

Cc: Ralph Metzler <rjkm@metzlerbros.de>
Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
Tested-by: Richard Scobie <r.scobie@clear.net.nz>
Tested-by: Jasmin Jessich <jasmin@anw.at>
Tested-by: Dietmar Spingler <d_spingler@freenet.de>
Tested-by: Manfred Knick <Manfred.Knick@t-online.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/pci/ddbridge/ddbridge-core.c

index bbd8d556175b949009765e0bd9cf0ee73f205464..d7bf01f38d98747c90fbf44c92de4dfa043e7b79 100644 (file)
@@ -170,10 +170,10 @@ static int ddb_redirect(u32 i, u32 p)
        struct ddb *pdev = ddbs[(p >> 4) & 0x3f];
        struct ddb_port *port;
 
-       if (!idev->has_dma || !pdev->has_dma)
-               return -EINVAL;
        if (!idev || !pdev)
                return -EINVAL;
+       if (!idev->has_dma || !pdev->has_dma)
+               return -EINVAL;
 
        port = &pdev->port[p & 0x0f];
        if (!port->output)