]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
[media] cec-funcs.h: add length checks
authorHans Verkuil <hansverk@cisco.com>
Wed, 6 Jul 2016 08:49:26 +0000 (05:49 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Fri, 8 Jul 2016 21:34:42 +0000 (18:34 -0300)
Add msg->len sanity checks to fix static checker warning:

include/linux/cec-funcs.h:1154 cec_ops_set_osd_string()
warn: setting length 'msg->len - 3' to negative one

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
include/linux/cec-funcs.h

index 19486009693a4b15e4909b0a0b328298457489d4..8d217ce5303401e470f981c85df6137036cd11d0 100644 (file)
@@ -788,7 +788,7 @@ static inline void cec_msg_set_timer_program_title(struct cec_msg *msg,
 static inline void cec_ops_set_timer_program_title(const struct cec_msg *msg,
                                                   char *prog_title)
 {
-       unsigned int len = msg->len - 2;
+       unsigned int len = msg->len > 2 ? msg->len - 2 : 0;
 
        if (len > 14)
                len = 14;
@@ -1167,7 +1167,7 @@ static inline void cec_ops_set_osd_string(const struct cec_msg *msg,
                                          __u8 *disp_ctl,
                                          char *osd)
 {
-       unsigned int len = msg->len - 3;
+       unsigned int len = msg->len > 3 ? msg->len - 3 : 0;
 
        *disp_ctl = msg->msg[2];
        if (len > 13)
@@ -1192,7 +1192,7 @@ static inline void cec_msg_set_osd_name(struct cec_msg *msg, const char *name)
 static inline void cec_ops_set_osd_name(const struct cec_msg *msg,
                                        char *name)
 {
-       unsigned int len = msg->len - 2;
+       unsigned int len = msg->len > 2 ? msg->len - 2 : 0;
 
        if (len > 14)
                len = 14;