diff options
author | Simon Arlott <simon@fire.lp0.eu> | 2007-05-11 02:04:11 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-12 19:29:45 -0400 |
commit | 87e71b473ee199cf4b7b7a0ce890cd01f45e3a0e (patch) | |
tree | 9701f316dc0a26fd5a6a342668090363e6e25bec /drivers/usb/atm | |
parent | 6dbd682b7c6d58916096616cdf94852641bc09d9 (diff) |
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>
Diffstat (limited to 'drivers/usb/atm')
-rw-r--r-- | drivers/usb/atm/cxacru.c | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c index 8bcf7fe1dd80..1bc884051e0f 100644 --- a/drivers/usb/atm/cxacru.c +++ b/drivers/usb/atm/cxacru.c | |||
@@ -171,7 +171,7 @@ struct cxacru_data { | |||
171 | struct delayed_work poll_work; | 171 | struct delayed_work poll_work; |
172 | u32 card_info[CXINF_MAX]; | 172 | u32 card_info[CXINF_MAX]; |
173 | struct mutex poll_state_serialize; | 173 | struct mutex poll_state_serialize; |
174 | int poll_state; | 174 | enum cxacru_poll_state poll_state; |
175 | 175 | ||
176 | /* contol handles */ | 176 | /* contol handles */ |
177 | struct mutex cm_serialize; | 177 | struct mutex cm_serialize; |
@@ -226,58 +226,48 @@ static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf) | |||
226 | 226 | ||
227 | static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf) | 227 | static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf) |
228 | { | 228 | { |
229 | if (unlikely(value < 0)) { | 229 | return snprintf(buf, PAGE_SIZE, "%d.%02u\n", |
230 | return snprintf(buf, PAGE_SIZE, "%d.%02u\n", | 230 | value / 100, abs(value) % 100); |
231 | value / 100, -value % 100); | ||
232 | } else { | ||
233 | return snprintf(buf, PAGE_SIZE, "%d.%02u\n", | ||
234 | value / 100, value % 100); | ||
235 | } | ||
236 | } | 231 | } |
237 | 232 | ||
238 | static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf) | 233 | static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf) |
239 | { | 234 | { |
240 | switch (value) { | 235 | static char *str[] = { "no", "yes" }; |
241 | case 0: return snprintf(buf, PAGE_SIZE, "no\n"); | 236 | if (unlikely(value >= ARRAY_SIZE(str))) |
242 | case 1: return snprintf(buf, PAGE_SIZE, "yes\n"); | 237 | return snprintf(buf, PAGE_SIZE, "%u\n", value); |
243 | default: return 0; | 238 | return snprintf(buf, PAGE_SIZE, "%s\n", str[value]); |
244 | } | ||
245 | } | 239 | } |
246 | 240 | ||
247 | static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf) | 241 | static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf) |
248 | { | 242 | { |
249 | switch (value) { | 243 | static char *str[] = { NULL, "not connected", "connected", "lost" }; |
250 | case 1: return snprintf(buf, PAGE_SIZE, "not connected\n"); | 244 | if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL)) |
251 | case 2: return snprintf(buf, PAGE_SIZE, "connected\n"); | 245 | return snprintf(buf, PAGE_SIZE, "%u\n", value); |
252 | case 3: return snprintf(buf, PAGE_SIZE, "lost\n"); | 246 | return snprintf(buf, PAGE_SIZE, "%s\n", str[value]); |
253 | default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value); | ||
254 | } | ||
255 | } | 247 | } |
256 | 248 | ||
257 | static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf) | 249 | static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf) |
258 | { | 250 | { |
259 | switch (value) { | 251 | static char *str[] = { "down", "attempting to activate", |
260 | case 0: return snprintf(buf, PAGE_SIZE, "down\n"); | 252 | "training", "channel analysis", "exchange", "up", |
261 | case 1: return snprintf(buf, PAGE_SIZE, "attempting to activate\n"); | 253 | "waiting", "initialising" |
262 | case 2: return snprintf(buf, PAGE_SIZE, "training\n"); | 254 | }; |
263 | case 3: return snprintf(buf, PAGE_SIZE, "channel analysis\n"); | 255 | if (unlikely(value >= ARRAY_SIZE(str))) |
264 | case 4: return snprintf(buf, PAGE_SIZE, "exchange\n"); | 256 | return snprintf(buf, PAGE_SIZE, "%u\n", value); |
265 | case 5: return snprintf(buf, PAGE_SIZE, "up\n"); | 257 | return snprintf(buf, PAGE_SIZE, "%s\n", str[value]); |
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 | } | ||
270 | } | 258 | } |
271 | 259 | ||
272 | static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf) | 260 | static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf) |
273 | { | 261 | { |
274 | switch (value) { | 262 | static char *str[] = { |
275 | case 0: return 0; | 263 | NULL, |
276 | case 1: return snprintf(buf, PAGE_SIZE, "ANSI T1.413\n"); | 264 | "ANSI T1.413", |
277 | case 2: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.1 (G.DMT)\n"); | 265 | "ITU-T G.992.1 (G.DMT)", |
278 | case 3: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.2 (G.LITE)\n"); | 266 | "ITU-T G.992.2 (G.LITE)" |
279 | default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value); | 267 | }; |
280 | } | 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 @@ static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev, | |||
308 | struct cxacru_data *instance = usbatm_instance->driver_data; | 298 | struct cxacru_data *instance = usbatm_instance->driver_data; |
309 | u32 value = instance->card_info[CXINF_LINE_STARTABLE]; | 299 | u32 value = instance->card_info[CXINF_LINE_STARTABLE]; |
310 | 300 | ||
311 | switch (value) { | 301 | static char *str[] = { "running", "stopped" }; |
312 | case 0: return snprintf(buf, PAGE_SIZE, "running\n"); | 302 | if (unlikely(value >= ARRAY_SIZE(str))) |
313 | case 1: return snprintf(buf, PAGE_SIZE, "stopped\n"); | 303 | return snprintf(buf, PAGE_SIZE, "%u\n", value); |
314 | default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value); | 304 | return snprintf(buf, PAGE_SIZE, "%s\n", str[value]); |
315 | } | ||
316 | } | 305 | } |
317 | 306 | ||
318 | static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev, | 307 | static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev, |