Commit 4403b7b4 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

V4L/DVB: ir-core: Remove magic numbers at the sysfs logic

Instead of using "magic" sizes for protocol names, replace them by an
array, and use strlen().

No functional changes.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 667c9ebe
...@@ -33,6 +33,18 @@ static struct class ir_input_class = { ...@@ -33,6 +33,18 @@ static struct class ir_input_class = {
.devnode = ir_devnode, .devnode = ir_devnode,
}; };
static struct {
u64 type;
char *name;
} proto_names[] = {
{ IR_TYPE_UNKNOWN, "unknown" },
{ IR_TYPE_RC5, "rc5" },
{ IR_TYPE_NEC, "nec" },
{ IR_TYPE_RC6, "rc6" },
{ IR_TYPE_JVC, "jvc" },
{ IR_TYPE_SONY, "sony" },
};
/** /**
* show_protocols() - shows the current IR protocol(s) * show_protocols() - shows the current IR protocol(s)
* @d: the device descriptor * @d: the device descriptor
...@@ -50,6 +62,7 @@ static ssize_t show_protocols(struct device *d, ...@@ -50,6 +62,7 @@ static ssize_t show_protocols(struct device *d,
struct ir_input_dev *ir_dev = dev_get_drvdata(d); struct ir_input_dev *ir_dev = dev_get_drvdata(d);
u64 allowed, enabled; u64 allowed, enabled;
char *tmp = buf; char *tmp = buf;
int i;
if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) {
enabled = ir_dev->rc_tab.ir_type; enabled = ir_dev->rc_tab.ir_type;
...@@ -63,35 +76,12 @@ static ssize_t show_protocols(struct device *d, ...@@ -63,35 +76,12 @@ static ssize_t show_protocols(struct device *d,
(long long)allowed, (long long)allowed,
(long long)enabled); (long long)enabled);
if (allowed & enabled & IR_TYPE_UNKNOWN) for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
tmp += sprintf(tmp, "[unknown] "); if (allowed & enabled & proto_names[i].type)
else if (allowed & IR_TYPE_UNKNOWN) tmp += sprintf(tmp, "[%s] ", proto_names[i].name);
tmp += sprintf(tmp, "unknown "); else if (allowed & proto_names[i].type)
tmp += sprintf(tmp, "%s ", proto_names[i].name);
if (allowed & enabled & IR_TYPE_RC5) }
tmp += sprintf(tmp, "[rc5] ");
else if (allowed & IR_TYPE_RC5)
tmp += sprintf(tmp, "rc5 ");
if (allowed & enabled & IR_TYPE_NEC)
tmp += sprintf(tmp, "[nec] ");
else if (allowed & IR_TYPE_NEC)
tmp += sprintf(tmp, "nec ");
if (allowed & enabled & IR_TYPE_RC6)
tmp += sprintf(tmp, "[rc6] ");
else if (allowed & IR_TYPE_RC6)
tmp += sprintf(tmp, "rc6 ");
if (allowed & enabled & IR_TYPE_JVC)
tmp += sprintf(tmp, "[jvc] ");
else if (allowed & IR_TYPE_JVC)
tmp += sprintf(tmp, "jvc ");
if (allowed & enabled & IR_TYPE_SONY)
tmp += sprintf(tmp, "[sony] ");
else if (allowed & IR_TYPE_SONY)
tmp += sprintf(tmp, "sony ");
if (tmp != buf) if (tmp != buf)
tmp--; tmp--;
...@@ -124,12 +114,14 @@ static ssize_t store_protocols(struct device *d, ...@@ -124,12 +114,14 @@ static ssize_t store_protocols(struct device *d,
const char *tmp; const char *tmp;
u64 type; u64 type;
u64 mask; u64 mask;
int rc; int rc, i;
unsigned long flags; unsigned long flags;
tmp = skip_spaces(data); tmp = skip_spaces(data);
if (*tmp == '\0') {
if (*tmp == '+') { IR_dprintk(1, "Protocol not specified\n");
return -EINVAL;
} else if (*tmp == '+') {
enable = true; enable = true;
disable = false; disable = false;
tmp++; tmp++;
...@@ -142,25 +134,14 @@ static ssize_t store_protocols(struct device *d, ...@@ -142,25 +134,14 @@ static ssize_t store_protocols(struct device *d,
disable = false; disable = false;
} }
if (!strncasecmp(tmp, "unknown", 7)) { for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
tmp += 7; if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
mask = IR_TYPE_UNKNOWN; tmp += strlen(proto_names[i].name);
} else if (!strncasecmp(tmp, "rc5", 3)) { mask = proto_names[i].type;
tmp += 3; break;
mask = IR_TYPE_RC5; }
} else if (!strncasecmp(tmp, "nec", 3)) { }
tmp += 3; if (i == ARRAY_SIZE(proto_names)) {
mask = IR_TYPE_NEC;
} else if (!strncasecmp(tmp, "rc6", 3)) {
tmp += 3;
mask = IR_TYPE_RC6;
} else if (!strncasecmp(tmp, "jvc", 3)) {
tmp += 3;
mask = IR_TYPE_JVC;
} else if (!strncasecmp(tmp, "sony", 4)) {
tmp += 4;
mask = IR_TYPE_SONY;
} else {
IR_dprintk(1, "Unknown protocol\n"); IR_dprintk(1, "Unknown protocol\n");
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment