linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hansverk@cisco.com>
To: linux-media <linux-media@vger.kernel.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH] cec-funcs.h: add length checks
Date: Wed, 6 Jul 2016 10:49:26 +0200	[thread overview]
Message-ID: <577CC616.7060002@cisco.com> (raw)

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>

diff --git a/include/linux/cec-funcs.h b/include/linux/cec-funcs.h
index 19486009..8d217ce 100644
--- a/include/linux/cec-funcs.h
+++ b/include/linux/cec-funcs.h
@@ -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;

                 reply	other threads:[~2016-07-06  8:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=577CC616.7060002@cisco.com \
    --to=hansverk@cisco.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).