public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: unlisted-recipients:; (no To-header on input)@bombadil.infradead.org
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: [PATCH 4/4] ir-core: allow specifying multiple protocols at one open/write
Date: Mon, 28 Jun 2010 13:59:57 -0300	[thread overview]
Message-ID: <20100628135957.4bb18df2@pedra> (raw)
In-Reply-To: <cover.1277744236.git.mchehab@redhat.com>

With this change, it is now possible to do something like:
        su -c 'echo "none +rc-5 +nec" > /sys/class/rc/rc1/protocols'

This prevents the need of multiple opens, one for each protocol change,
and makes userspace application easier.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index db8c7f4..e538f16 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -117,61 +117,62 @@ static ssize_t store_protocols(struct device *d,
 	const char *tmp;
 	u64 type;
 	u64 mask;
-	int rc, i;
+	int rc, i, count = 0;
 	unsigned long flags;
 
-	tmp = skip_spaces(data);
-	if (*tmp == '\0') {
-		IR_dprintk(1, "Protocol not specified\n");
-		return -EINVAL;
-	} else if (*tmp == '+') {
-		enable = true;
-		disable = false;
-		tmp++;
-	} else if (*tmp == '-') {
-		enable = false;
-		disable = true;
-		tmp++;
-	} else {
-		enable = false;
-		disable = false;
-	}
-
-
-	if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) {
-		mask = 0;
-		tmp += sizeof(PROTO_NONE);
-	} else {
-		for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
-			if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
-				tmp += strlen(proto_names[i].name);
-				mask = proto_names[i].type;
-				break;
-			}
-		}
-		if (i == ARRAY_SIZE(proto_names)) {
-			IR_dprintk(1, "Unknown protocol\n");
-			return -EINVAL;
-		}
-	}
-
-	tmp = skip_spaces(tmp);
-	if (*tmp != '\0') {
-		IR_dprintk(1, "Invalid trailing characters\n");
-		return -EINVAL;
-	}
-
 	if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
 		type = ir_dev->rc_tab.ir_type;
 	else
 		type = ir_dev->raw->enabled_protocols;
 
-	if (enable)
-		type |= mask;
-	else if (disable)
-		type &= ~mask;
-	else
-		type = mask;
+	while ((tmp = strsep((char **) &data, " \n")) != NULL) {
+		if (!*tmp)
+			break;
+
+		if (*tmp == '+') {
+			enable = true;
+			disable = false;
+			tmp++;
+		} else if (*tmp == '-') {
+			enable = false;
+			disable = true;
+			tmp++;
+		} else {
+			enable = false;
+			disable = false;
+		}
+
+		if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) {
+			tmp += sizeof(PROTO_NONE);
+			mask = 0;
+			count++;
+		} else {
+			for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
+				if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
+					tmp += strlen(proto_names[i].name);
+					mask = proto_names[i].type;
+					break;
+				}
+			}
+			if (i == ARRAY_SIZE(proto_names)) {
+				IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
+				return -EINVAL;
+			}
+			count++;
+		}
+
+		if (enable)
+			type |= mask;
+		else if (disable)
+			type &= ~mask;
+		else
+			type = mask;
+	}
+
+	if (!count) {
+		IR_dprintk(1, "Protocol not specified\n");
+		return -EINVAL;
+	}
 
 	if (ir_dev->props && ir_dev->props->change_protocol) {
 		rc = ir_dev->props->change_protocol(ir_dev->props->priv,
@@ -191,7 +192,6 @@ static ssize_t store_protocols(struct device *d,
 		ir_dev->raw->enabled_protocols = type;
 	}
 
-
 	IR_dprintk(1, "Current protocol(s): 0x%llx\n",
 		   (long long)type);
 
-- 
1.7.1


       reply	other threads:[~2010-06-28 17:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1277744236.git.mchehab@redhat.com>
2010-06-28 16:59 ` Mauro Carvalho Chehab [this message]
2010-06-28 16:59 ` [PATCH 3/4] ir-core: Add support for disabling all protocols Mauro Carvalho Chehab
2010-06-28 16:59 ` [PATCH 2/4] ir-core: Rename sysfs protocols nomenclature to rc-5 and rc-6 Mauro Carvalho Chehab
2010-06-28 17:00 ` [PATCH 1/4] ir-core: Remove magic numbers at the sysfs logic Mauro Carvalho Chehab

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=20100628135957.4bb18df2@pedra \
    --to=mchehab@redhat.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