mirror of https://gitee.com/openkylin/linux.git
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>
This commit is contained in:
parent
6dbd682b7c
commit
87e71b473e
|
@ -171,7 +171,7 @@ struct cxacru_data {
|
||||||
struct delayed_work poll_work;
|
struct delayed_work poll_work;
|
||||||
u32 card_info[CXINF_MAX];
|
u32 card_info[CXINF_MAX];
|
||||||
struct mutex poll_state_serialize;
|
struct mutex poll_state_serialize;
|
||||||
int poll_state;
|
enum cxacru_poll_state poll_state;
|
||||||
|
|
||||||
/* contol handles */
|
/* contol handles */
|
||||||
struct mutex cm_serialize;
|
struct mutex cm_serialize;
|
||||||
|
@ -226,58 +226,48 @@ static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf)
|
||||||
|
|
||||||
static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
|
static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
|
||||||
{
|
{
|
||||||
if (unlikely(value < 0)) {
|
return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
|
||||||
return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
|
value / 100, abs(value) % 100);
|
||||||
value / 100, -value % 100);
|
|
||||||
} else {
|
|
||||||
return snprintf(buf, PAGE_SIZE, "%d.%02u\n",
|
|
||||||
value / 100, value % 100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
|
static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
|
||||||
{
|
{
|
||||||
switch (value) {
|
static char *str[] = { "no", "yes" };
|
||||||
case 0: return snprintf(buf, PAGE_SIZE, "no\n");
|
if (unlikely(value >= ARRAY_SIZE(str)))
|
||||||
case 1: return snprintf(buf, PAGE_SIZE, "yes\n");
|
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||||
default: return 0;
|
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
|
static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
|
||||||
{
|
{
|
||||||
switch (value) {
|
static char *str[] = { NULL, "not connected", "connected", "lost" };
|
||||||
case 1: return snprintf(buf, PAGE_SIZE, "not connected\n");
|
if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
|
||||||
case 2: return snprintf(buf, PAGE_SIZE, "connected\n");
|
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||||
case 3: return snprintf(buf, PAGE_SIZE, "lost\n");
|
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||||
default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
|
static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
|
||||||
{
|
{
|
||||||
switch (value) {
|
static char *str[] = { "down", "attempting to activate",
|
||||||
case 0: return snprintf(buf, PAGE_SIZE, "down\n");
|
"training", "channel analysis", "exchange", "up",
|
||||||
case 1: return snprintf(buf, PAGE_SIZE, "attempting to activate\n");
|
"waiting", "initialising"
|
||||||
case 2: return snprintf(buf, PAGE_SIZE, "training\n");
|
};
|
||||||
case 3: return snprintf(buf, PAGE_SIZE, "channel analysis\n");
|
if (unlikely(value >= ARRAY_SIZE(str)))
|
||||||
case 4: return snprintf(buf, PAGE_SIZE, "exchange\n");
|
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||||
case 5: return snprintf(buf, PAGE_SIZE, "up\n");
|
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||||
case 6: return snprintf(buf, PAGE_SIZE, "waiting\n");
|
|
||||||
case 7: return snprintf(buf, PAGE_SIZE, "initialising\n");
|
|
||||||
default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
|
static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
|
||||||
{
|
{
|
||||||
switch (value) {
|
static char *str[] = {
|
||||||
case 0: return 0;
|
NULL,
|
||||||
case 1: return snprintf(buf, PAGE_SIZE, "ANSI T1.413\n");
|
"ANSI T1.413",
|
||||||
case 2: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.1 (G.DMT)\n");
|
"ITU-T G.992.1 (G.DMT)",
|
||||||
case 3: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.2 (G.LITE)\n");
|
"ITU-T G.992.2 (G.LITE)"
|
||||||
default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
|
};
|
||||||
}
|
if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
|
||||||
|
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||||
|
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -308,11 +298,10 @@ static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev,
|
||||||
struct cxacru_data *instance = usbatm_instance->driver_data;
|
struct cxacru_data *instance = usbatm_instance->driver_data;
|
||||||
u32 value = instance->card_info[CXINF_LINE_STARTABLE];
|
u32 value = instance->card_info[CXINF_LINE_STARTABLE];
|
||||||
|
|
||||||
switch (value) {
|
static char *str[] = { "running", "stopped" };
|
||||||
case 0: return snprintf(buf, PAGE_SIZE, "running\n");
|
if (unlikely(value >= ARRAY_SIZE(str)))
|
||||||
case 1: return snprintf(buf, PAGE_SIZE, "stopped\n");
|
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||||
default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value);
|
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
|
static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
|
||||||
|
|
Loading…
Reference in New Issue