diff options
author | Bart Van Assche <bvanassche@acm.org> | 2011-09-10 10:31:57 -0400 |
---|---|---|
committer | Roland Dreier <roland@purestorage.com> | 2012-11-30 20:40:33 -0500 |
commit | 9134a855178f141b9be48aa19b49ed92d82665ce (patch) | |
tree | 3465c38adc44a680b31f6b0b91ef4b93bbd20398 /drivers/scsi/scsi_transport_srp.c | |
parent | ac9be30e91cffe07f762bd91ca40de065bf257d7 (diff) |
srp_transport: Simplify attribute initialization code
Eliminate the private_rport_attrs[] array and the SETUP_*() macros
used to set up that array since the information in that array
duplicates the information in the static device attributes. Also,
verify whether SRP_RPORT_ATTRS is large enough since it is easy to
forget to update that macro when adding new attributes.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Robert Jennings <rcj@linux.vnet.ibm.com>
Acked-by: David Dillow <dillowda@ornl.gov>
Signed-off-by: Roland Dreier <roland@purestorage.com>
Diffstat (limited to 'drivers/scsi/scsi_transport_srp.c')
-rw-r--r-- | drivers/scsi/scsi_transport_srp.c | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c index 07c4394624f1..0d85f797141f 100644 --- a/drivers/scsi/scsi_transport_srp.c +++ b/drivers/scsi/scsi_transport_srp.c | |||
@@ -47,7 +47,6 @@ struct srp_internal { | |||
47 | struct device_attribute *host_attrs[SRP_HOST_ATTRS + 1]; | 47 | struct device_attribute *host_attrs[SRP_HOST_ATTRS + 1]; |
48 | 48 | ||
49 | struct device_attribute *rport_attrs[SRP_RPORT_ATTRS + 1]; | 49 | struct device_attribute *rport_attrs[SRP_RPORT_ATTRS + 1]; |
50 | struct device_attribute private_rport_attrs[SRP_RPORT_ATTRS]; | ||
51 | struct transport_container rport_attr_cont; | 50 | struct transport_container rport_attr_cont; |
52 | }; | 51 | }; |
53 | 52 | ||
@@ -72,24 +71,6 @@ static DECLARE_TRANSPORT_CLASS(srp_host_class, "srp_host", srp_host_setup, | |||
72 | static DECLARE_TRANSPORT_CLASS(srp_rport_class, "srp_remote_ports", | 71 | static DECLARE_TRANSPORT_CLASS(srp_rport_class, "srp_remote_ports", |
73 | NULL, NULL, NULL); | 72 | NULL, NULL, NULL); |
74 | 73 | ||
75 | #define SETUP_TEMPLATE(attrb, field, perm, test, ro_test, ro_perm) \ | ||
76 | i->private_##attrb[count] = dev_attr_##field; \ | ||
77 | i->private_##attrb[count].attr.mode = perm; \ | ||
78 | if (ro_test) { \ | ||
79 | i->private_##attrb[count].attr.mode = ro_perm; \ | ||
80 | i->private_##attrb[count].store = NULL; \ | ||
81 | } \ | ||
82 | i->attrb[count] = &i->private_##attrb[count]; \ | ||
83 | if (test) \ | ||
84 | count++ | ||
85 | |||
86 | #define SETUP_RPORT_ATTRIBUTE_RD(field) \ | ||
87 | SETUP_TEMPLATE(rport_attrs, field, S_IRUGO, 1, 0, 0) | ||
88 | |||
89 | #define SETUP_RPORT_ATTRIBUTE_RW(field) \ | ||
90 | SETUP_TEMPLATE(rport_attrs, field, S_IRUGO | S_IWUSR, \ | ||
91 | 1, 1, S_IRUGO) | ||
92 | |||
93 | #define SRP_PID(p) \ | 74 | #define SRP_PID(p) \ |
94 | (p)->port_id[0], (p)->port_id[1], (p)->port_id[2], (p)->port_id[3], \ | 75 | (p)->port_id[0], (p)->port_id[1], (p)->port_id[2], (p)->port_id[3], \ |
95 | (p)->port_id[4], (p)->port_id[5], (p)->port_id[6], (p)->port_id[7], \ | 76 | (p)->port_id[4], (p)->port_id[5], (p)->port_id[6], (p)->port_id[7], \ |
@@ -326,9 +307,10 @@ srp_attach_transport(struct srp_function_template *ft) | |||
326 | i->rport_attr_cont.ac.match = srp_rport_match; | 307 | i->rport_attr_cont.ac.match = srp_rport_match; |
327 | 308 | ||
328 | count = 0; | 309 | count = 0; |
329 | SETUP_RPORT_ATTRIBUTE_RD(port_id); | 310 | i->rport_attrs[count++] = &dev_attr_port_id; |
330 | SETUP_RPORT_ATTRIBUTE_RD(roles); | 311 | i->rport_attrs[count++] = &dev_attr_roles; |
331 | i->rport_attrs[count] = NULL; | 312 | i->rport_attrs[count++] = NULL; |
313 | BUG_ON(count > ARRAY_SIZE(i->rport_attrs)); | ||
332 | 314 | ||
333 | transport_container_register(&i->rport_attr_cont); | 315 | transport_container_register(&i->rport_attr_cont); |
334 | 316 | ||