[media] ir: Fix IR_MAX_DURATION enforcement
authorMauro Carvalho Chehab <mchehab@osg.samsung.com>
Fri, 5 Jun 2015 13:25:24 +0000 (10:25 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Fri, 5 Jun 2015 14:26:42 +0000 (11:26 -0300)
Don't assume that IR_MAX_DURATION is a bitmask. It isn't.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/rc/redrat3.c
drivers/media/rc/streamzap.c

index c83292ad1b34426e9bfc322349c3a63c0a0f2454..ec74244a38530a937d07280a304debdf7a5988b7 100644 (file)
@@ -322,7 +322,7 @@ static u32 redrat3_us_to_len(u32 microsec)
        u32 result;
        u32 divisor;
 
-       microsec &= IR_MAX_DURATION;
+       microsec = (microsec > IR_MAX_DURATION) ? IR_MAX_DURATION : microsec;
        divisor = (RR3_CLK_CONV_FACTOR / 1000);
        result = (u32)(microsec * divisor) / 1000;
 
@@ -380,7 +380,8 @@ static void redrat3_process_ir_data(struct redrat3_dev *rr3)
                if (i == 0)
                        trailer = rawir.duration;
                /* cap the value to IR_MAX_DURATION */
-               rawir.duration &= IR_MAX_DURATION;
+               rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
+                                IR_MAX_DURATION : rawir.duration;
 
                dev_dbg(dev, "storing %s with duration %d (i: %d)\n",
                        rawir.pulse ? "pulse" : "space", rawir.duration, i);
index bf4a44272f0e3e00a01c0bc3fb44720e1732ec27..5a17cb88ff27e45e12482b50170fc15e7f386fa9 100644 (file)
@@ -152,7 +152,8 @@ static void sz_push_full_pulse(struct streamzap_ir *sz,
                                sz->signal_last.tv_usec);
                        rawir.duration -= sz->sum;
                        rawir.duration = US_TO_NS(rawir.duration);
-                       rawir.duration &= IR_MAX_DURATION;
+                       rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
+                                        IR_MAX_DURATION : rawir.duration;
                }
                sz_push(sz, rawir);
 
@@ -165,7 +166,8 @@ static void sz_push_full_pulse(struct streamzap_ir *sz,
        rawir.duration += SZ_RESOLUTION / 2;
        sz->sum += rawir.duration;
        rawir.duration = US_TO_NS(rawir.duration);
-       rawir.duration &= IR_MAX_DURATION;
+       rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
+                        IR_MAX_DURATION : rawir.duration;
        sz_push(sz, rawir);
 }