Commit 87e71b473ee199cf4b7b7a0ce890cd01f45e3a0e

Authored by Simon Arlott
Committed by Greg Kroah-Hartman
1 parent 6dbd682b7c

USB: cxacru: Cleanup sysfs attribute code

This changes the format of unknown status values to be less verbose and
uses an array instead of several different snprintf calls. Since only
enum values are assigned to it, poll_state is changed from int to enum.
Use abs() for dB values instead of two almost identical return lines.

Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
Acked-by: Duncan Sands <duncan.sands@math.u-psud.fr>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 31 additions and 42 deletions Side-by-side Diff

drivers/usb/atm/cxacru.c
... ... @@ -171,7 +171,7 @@
171 171 struct delayed_work poll_work;
172 172 u32 card_info[CXINF_MAX];
173 173 struct mutex poll_state_serialize;
174   - int poll_state;
  174 + enum cxacru_poll_state poll_state;
175 175  
176 176 /* contol handles */
177 177 struct mutex cm_serialize;
178 178  
179 179  
180 180  
181 181  
... ... @@ -226,58 +226,48 @@
226 226  
227 227 static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
228 228 {
229   - if (unlikely(value < 0)) {
230   - return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
231   - value / 100, -value % 100);
232   - } else {
233   - return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
234   - value / 100, value % 100);
235   - }
  229 + return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
  230 + value / 100, abs(value) % 100);
236 231 }
237 232  
238 233 static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
239 234 {
240   - switch (value) {
241   - case 0: return snprintf(buf, PAGE_SIZE, "no\n");
242   - case 1: return snprintf(buf, PAGE_SIZE, "yes\n");
243   - default: return 0;
244   - }
  235 + static char *str[] = { "no", "yes" };
  236 + if (unlikely(value >= ARRAY_SIZE(str)))
  237 + return snprintf(buf, PAGE_SIZE, "%u\n", value);
  238 + return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
245 239 }
246 240  
247 241 static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
248 242 {
249   - switch (value) {
250   - case 1: return snprintf(buf, PAGE_SIZE, "not connected\n");
251   - case 2: return snprintf(buf, PAGE_SIZE, "connected\n");
252   - case 3: return snprintf(buf, PAGE_SIZE, "lost\n");
253   - default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
254   - }
  243 + static char *str[] = { NULL, "not connected", "connected", "lost" };
  244 + if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  245 + return snprintf(buf, PAGE_SIZE, "%u\n", value);
  246 + return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
255 247 }
256 248  
257 249 static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
258 250 {
259   - switch (value) {
260   - case 0: return snprintf(buf, PAGE_SIZE, "down\n");
261   - case 1: return snprintf(buf, PAGE_SIZE, "attempting to activate\n");
262   - case 2: return snprintf(buf, PAGE_SIZE, "training\n");
263   - case 3: return snprintf(buf, PAGE_SIZE, "channel analysis\n");
264   - case 4: return snprintf(buf, PAGE_SIZE, "exchange\n");
265   - case 5: return snprintf(buf, PAGE_SIZE, "up\n");
266   - case 6: return snprintf(buf, PAGE_SIZE, "waiting\n");
267   - case 7: return snprintf(buf, PAGE_SIZE, "initialising\n");
268   - default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
269   - }
  251 + static char *str[] = { "down", "attempting to activate",
  252 + "training", "channel analysis", "exchange", "up",
  253 + "waiting", "initialising"
  254 + };
  255 + if (unlikely(value >= ARRAY_SIZE(str)))
  256 + return snprintf(buf, PAGE_SIZE, "%u\n", value);
  257 + return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
270 258 }
271 259  
272 260 static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
273 261 {
274   - switch (value) {
275   - case 0: return 0;
276   - case 1: return snprintf(buf, PAGE_SIZE, "ANSI T1.413\n");
277   - case 2: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.1 (G.DMT)\n");
278   - case 3: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.2 (G.LITE)\n");
279   - default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
280   - }
  262 + static char *str[] = {
  263 + NULL,
  264 + "ANSI T1.413",
  265 + "ITU-T G.992.1 (G.DMT)",
  266 + "ITU-T G.992.2 (G.LITE)"
  267 + };
  268 + if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
  269 + return snprintf(buf, PAGE_SIZE, "%u\n", value);
  270 + return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
281 271 }
282 272  
283 273 /*
... ... @@ -308,11 +298,10 @@
308 298 struct cxacru_data *instance = usbatm_instance->driver_data;
309 299 u32 value = instance->card_info[CXINF_LINE_STARTABLE];
310 300  
311   - switch (value) {
312   - case 0: return snprintf(buf, PAGE_SIZE, "running\n");
313   - case 1: return snprintf(buf, PAGE_SIZE, "stopped\n");
314   - default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
315   - }
  301 + static char *str[] = { "running", "stopped" };
  302 + if (unlikely(value >= ARRAY_SIZE(str)))
  303 + return snprintf(buf, PAGE_SIZE, "%u\n", value);
  304 + return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
316 305 }
317 306  
318 307 static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,