On 3/4/20 2:57 PM, Gabriel Krisman Bertazi wrote:
+static const struct { + int state; + char *name; +} connection_state_name[] = { + {ISCSI_CONN_UP, "up"}, + {ISCSI_CONN_DOWN, "down"}, + {ISCSI_CONN_FAILED, "failed"} +}; + +static ssize_t +show_conn_state(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); + + return sprintf(buf, "%s\n", + connection_state_name[conn->state].name); +} +static ISCSI_CLASS_ATTR(conn, state, S_IRUGO, show_conn_state, + NULL);
The above code can only work if ISCSI_CONN_UP == 0, ISCSI_CONN_DOWN == 1 and ISCSI_CONN_FAILED == 2. Please don't hardcode such a dependency and use designated initializers instead.
Thanks, Bart.