diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-06-28 11:37:13 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-08-02 13:54:35 -0400 |
commit | 4403b7b4eabd3f307c21bfadebe7a1d951d1478b (patch) | |
tree | aa5dfb6591a043ee1098fb23c564a0f5a4392827 /drivers/media/IR | |
parent | 667c9ebe97f7e5f1e48e7eb321644c6fb1668de5 (diff) |
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: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR')
-rw-r--r-- | drivers/media/IR/ir-sysfs.c | 83 |
1 files changed, 32 insertions, 51 deletions
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c index 005621d067f0..f897c483e7bc 100644 --- a/drivers/media/IR/ir-sysfs.c +++ b/drivers/media/IR/ir-sysfs.c | |||
@@ -33,6 +33,18 @@ static struct class ir_input_class = { | |||
33 | .devnode = ir_devnode, | 33 | .devnode = ir_devnode, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | static struct { | ||
37 | u64 type; | ||
38 | char *name; | ||
39 | } proto_names[] = { | ||
40 | { IR_TYPE_UNKNOWN, "unknown" }, | ||
41 | { IR_TYPE_RC5, "rc5" }, | ||
42 | { IR_TYPE_NEC, "nec" }, | ||
43 | { IR_TYPE_RC6, "rc6" }, | ||
44 | { IR_TYPE_JVC, "jvc" }, | ||
45 | { IR_TYPE_SONY, "sony" }, | ||
46 | }; | ||
47 | |||
36 | /** | 48 | /** |
37 | * show_protocols() - shows the current IR protocol(s) | 49 | * show_protocols() - shows the current IR protocol(s) |
38 | * @d: the device descriptor | 50 | * @d: the device descriptor |
@@ -50,6 +62,7 @@ static ssize_t show_protocols(struct device *d, | |||
50 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | 62 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); |
51 | u64 allowed, enabled; | 63 | u64 allowed, enabled; |
52 | char *tmp = buf; | 64 | char *tmp = buf; |
65 | int i; | ||
53 | 66 | ||
54 | if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { | 67 | if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { |
55 | enabled = ir_dev->rc_tab.ir_type; | 68 | enabled = ir_dev->rc_tab.ir_type; |
@@ -63,35 +76,12 @@ static ssize_t show_protocols(struct device *d, | |||
63 | (long long)allowed, | 76 | (long long)allowed, |
64 | (long long)enabled); | 77 | (long long)enabled); |
65 | 78 | ||
66 | if (allowed & enabled & IR_TYPE_UNKNOWN) | 79 | for (i = 0; i < ARRAY_SIZE(proto_names); i++) { |
67 | tmp += sprintf(tmp, "[unknown] "); | 80 | if (allowed & enabled & proto_names[i].type) |
68 | else if (allowed & IR_TYPE_UNKNOWN) | 81 | tmp += sprintf(tmp, "[%s] ", proto_names[i].name); |
69 | tmp += sprintf(tmp, "unknown "); | 82 | else if (allowed & proto_names[i].type) |
70 | 83 | tmp += sprintf(tmp, "%s ", proto_names[i].name); | |
71 | if (allowed & enabled & IR_TYPE_RC5) | 84 | } |
72 | tmp += sprintf(tmp, "[rc5] "); | ||
73 | else if (allowed & IR_TYPE_RC5) | ||
74 | tmp += sprintf(tmp, "rc5 "); | ||
75 | |||
76 | if (allowed & enabled & IR_TYPE_NEC) | ||
77 | tmp += sprintf(tmp, "[nec] "); | ||
78 | else if (allowed & IR_TYPE_NEC) | ||
79 | tmp += sprintf(tmp, "nec "); | ||
80 | |||
81 | if (allowed & enabled & IR_TYPE_RC6) | ||
82 | tmp += sprintf(tmp, "[rc6] "); | ||
83 | else if (allowed & IR_TYPE_RC6) | ||
84 | tmp += sprintf(tmp, "rc6 "); | ||
85 | |||
86 | if (allowed & enabled & IR_TYPE_JVC) | ||
87 | tmp += sprintf(tmp, "[jvc] "); | ||
88 | else if (allowed & IR_TYPE_JVC) | ||
89 | tmp += sprintf(tmp, "jvc "); | ||
90 | |||
91 | if (allowed & enabled & IR_TYPE_SONY) | ||
92 | tmp += sprintf(tmp, "[sony] "); | ||
93 | else if (allowed & IR_TYPE_SONY) | ||
94 | tmp += sprintf(tmp, "sony "); | ||
95 | 85 | ||
96 | if (tmp != buf) | 86 | if (tmp != buf) |
97 | tmp--; | 87 | tmp--; |
@@ -124,12 +114,14 @@ static ssize_t store_protocols(struct device *d, | |||
124 | const char *tmp; | 114 | const char *tmp; |
125 | u64 type; | 115 | u64 type; |
126 | u64 mask; | 116 | u64 mask; |
127 | int rc; | 117 | int rc, i; |
128 | unsigned long flags; | 118 | unsigned long flags; |
129 | 119 | ||
130 | tmp = skip_spaces(data); | 120 | tmp = skip_spaces(data); |
131 | 121 | if (*tmp == '\0') { | |
132 | if (*tmp == '+') { | 122 | IR_dprintk(1, "Protocol not specified\n"); |
123 | return -EINVAL; | ||
124 | } else if (*tmp == '+') { | ||
133 | enable = true; | 125 | enable = true; |
134 | disable = false; | 126 | disable = false; |
135 | tmp++; | 127 | tmp++; |
@@ -142,25 +134,14 @@ static ssize_t store_protocols(struct device *d, | |||
142 | disable = false; | 134 | disable = false; |
143 | } | 135 | } |
144 | 136 | ||
145 | if (!strncasecmp(tmp, "unknown", 7)) { | 137 | for (i = 0; i < ARRAY_SIZE(proto_names); i++) { |
146 | tmp += 7; | 138 | if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) { |
147 | mask = IR_TYPE_UNKNOWN; | 139 | tmp += strlen(proto_names[i].name); |
148 | } else if (!strncasecmp(tmp, "rc5", 3)) { | 140 | mask = proto_names[i].type; |
149 | tmp += 3; | 141 | break; |
150 | mask = IR_TYPE_RC5; | 142 | } |
151 | } else if (!strncasecmp(tmp, "nec", 3)) { | 143 | } |
152 | tmp += 3; | 144 | if (i == ARRAY_SIZE(proto_names)) { |
153 | mask = IR_TYPE_NEC; | ||
154 | } else if (!strncasecmp(tmp, "rc6", 3)) { | ||
155 | tmp += 3; | ||
156 | mask = IR_TYPE_RC6; | ||
157 | } else if (!strncasecmp(tmp, "jvc", 3)) { | ||
158 | tmp += 3; | ||
159 | mask = IR_TYPE_JVC; | ||
160 | } else if (!strncasecmp(tmp, "sony", 4)) { | ||
161 | tmp += 4; | ||
162 | mask = IR_TYPE_SONY; | ||
163 | } else { | ||
164 | IR_dprintk(1, "Unknown protocol\n"); | 145 | IR_dprintk(1, "Unknown protocol\n"); |
165 | return -EINVAL; | 146 | return -EINVAL; |
166 | } | 147 | } |