[media] staging/media/davinci_vpfe/dm365_ipipeif.c: fix negativity check
authorAndrey Utkin <andrey.krieger.utkin@gmail.com>
Thu, 17 Jul 2014 16:27:16 +0000 (13:27 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Mon, 21 Jul 2014 22:31:58 +0000 (19:31 -0300)
[linux-3.16-rc5/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c:210]:
(style) Checking if unsigned variable 'val' is less than zero.

    val = get_oneshot_mode(ipipeif->input);
    if (val < 0) {
        pr_err("ipipeif: links setup required");
        return -EINVAL;
    }

but

static int get_oneshot_mode(enum ipipeif_input_entity input)

Introduced temporary variable for negativity check.
"val" is afterwards used in a lot of bitwise operations, so changing its type
to signed is not safe, according to CERT C Secure Coding Standards chapter
INT13-C: "Use bitwise operators only on unsigned operands"
https://www.securecoding.cert.org/confluence/display/seccode/INT13-C.+Use+bitwise+operators+only+on+unsigned+operands

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=80521

Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Andrey Utkin <andrey.krieger.utkin@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c

index 59540cd4bb98c0d14705841b6edbd35c50ad640f..6d4893b44c1ff9d6a968e01ef8bab95b7f4cc53c 100644 (file)
@@ -196,6 +196,7 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)
        int data_shift;
        int pack_mode;
        int source1;
+       int tmp;
 
        ipipeif_base_addr = ipipeif->ipipeif_base_addr;
 
@@ -206,8 +207,8 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)
        outformat = &ipipeif->formats[IPIPEIF_PAD_SOURCE];
 
        /* Combine all the fields to make CFG1 register of IPIPEIF */
-       val = get_oneshot_mode(ipipeif->input);
-       if (val < 0) {
+       tmp = val = get_oneshot_mode(ipipeif->input);
+       if (tmp < 0) {
                pr_err("ipipeif: links setup required");
                return -EINVAL;
        }