diff mbox

[2/3] rc-main: Limit to a single wakeup protocol group

Message ID 1395868113-17950-3-git-send-email-james.hogan@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

James Hogan March 26, 2014, 9:08 p.m. UTC
Limit the enabled wakeup protocols to be within a protocol group, as
defined by the proto_names array. For example this prevents the
selection of both rc-5 and nec, while allowing rc-5 alone (which
encompasses both normal rc-5 and rc-5x).

It doesn't usually make sense to enable more than one wakeup protocol
since only a single protocol can usually be used for wakeup at a time,
and doing so with encode based wakeup will result in an arbitrary
protocol being used if multiple are possible.

Reported-by: Antti Seppälä <a.seppala@gmail.com>
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>
Cc: Antti Seppälä <a.seppala@gmail.com>
---
Sorry it took a little while to get around to submitting this.
---
 drivers/media/rc/rc-main.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox

Patch

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index e067fee..79d1060 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -979,6 +979,19 @@  static ssize_t store_protocols(struct device *device,
 		goto out;
 	}
 
+	if (fattr->type == RC_FILTER_WAKEUP) {
+		/* A proto_names entry must cover enabled wakeup protocols */
+		for (i = 0; i < ARRAY_SIZE(proto_names); i++)
+			if (type & proto_names[i].type &&
+			    !(type & ~proto_names[i].type))
+				break;
+		if (i == ARRAY_SIZE(proto_names)) {
+			IR_dprintk(1, "Multiple distinct wakeup protocols\n");
+			ret = -EINVAL;
+			goto out;
+		}
+	}
+
 	change_protocol = (fattr->type == RC_FILTER_NORMAL)
 		? dev->change_protocol : dev->change_wakeup_protocol;
 	if (change_protocol) {