Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: cec: cec-adap.c: improve CEC_MSG_FL_REPLY_VENDOR_ID check

The new CEC_MSG_FL_REPLY_VENDOR_ID flag only makes sense in combination
with CEC_MSG_VENDOR_COMMAND_WITH_ID. So rather than reporting an error
if that flag is set with another command, just clear the flag instead.

Only keep the message length check, since otherwise the flag would not
make sense.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
31aaa7d9 599f6899

+6 -5
+6 -5
drivers/media/cec/core/cec-adap.c
··· 781 781 { 782 782 struct cec_data *data; 783 783 bool is_raw = msg_is_raw(msg); 784 - bool reply_vendor_id = msg->flags & CEC_MSG_FL_REPLY_VENDOR_ID; 784 + bool reply_vendor_id = (msg->flags & CEC_MSG_FL_REPLY_VENDOR_ID) && 785 + msg->len > 1 && msg->msg[1] == CEC_MSG_VENDOR_COMMAND_WITH_ID; 785 786 int err; 786 787 787 788 if (adap->devnode.unregistered) ··· 798 797 msg->tx_error_cnt = 0; 799 798 msg->sequence = 0; 800 799 msg->flags &= CEC_MSG_FL_REPLY_TO_FOLLOWERS | CEC_MSG_FL_RAW | 801 - CEC_MSG_FL_REPLY_VENDOR_ID; 800 + (reply_vendor_id ? CEC_MSG_FL_REPLY_VENDOR_ID : 0); 802 801 803 802 if ((reply_vendor_id || msg->reply) && msg->timeout == 0) { 804 803 /* Make sure the timeout isn't 0. */ ··· 813 812 dprintk(1, "%s: invalid length %d\n", __func__, msg->len); 814 813 return -EINVAL; 815 814 } 816 - if (reply_vendor_id && 817 - (msg->len < 6 || msg->msg[1] != CEC_MSG_VENDOR_COMMAND_WITH_ID)) { 818 - dprintk(1, "%s: message too short or not <Vendor Command With ID>\n", __func__); 815 + if (reply_vendor_id && msg->len < 6) { 816 + dprintk(1, "%s: <Vendor Command With ID> message too short\n", 817 + __func__); 819 818 return -EINVAL; 820 819 } 821 820