Skip to content

Commit 7b27c5f

Browse files
John Garrymartinkpetersen
authored andcommitted
scsi: libsas: Stop hardcoding SAS address length
Many times we use 8 for SAS address length, while we already have a macro for this - SAS_ADDR_SIZE. Replace instances of this with the macro. However, don't touch the SAS address array sizes sas.h, as these are defined according to the SAS spec. Some missing whitespaces are also added, and whitespace indentation in sas_hash_addr() is also fixed (see sas_hash_addr()). Signed-off-by: John Garry <john.garry@huawei.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 01d4e3a commit 7b27c5f

3 files changed

Lines changed: 32 additions & 29 deletions

File tree

‎drivers/scsi/libsas/sas_expander.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ static int sas_find_sub_addr(struct domain_device *dev, u8 *sub_addr)
11511151
phy->attached_dev_type == SAS_FANOUT_EXPANDER_DEVICE) &&
11521152
phy->routing_attr == SUBTRACTIVE_ROUTING) {
11531153

1154-
memcpy(sub_addr, phy->attached_sas_addr,SAS_ADDR_SIZE);
1154+
memcpy(sub_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
11551155

11561156
return 1;
11571157
}
@@ -1163,7 +1163,7 @@ static int sas_check_level_subtractive_boundary(struct domain_device *dev)
11631163
{
11641164
struct expander_device *ex = &dev->ex_dev;
11651165
struct domain_device *child;
1166-
u8 sub_addr[8] = {0, };
1166+
u8 sub_addr[SAS_ADDR_SIZE] = {0, };
11671167

11681168
list_for_each_entry(child, &ex->children, siblings) {
11691169
if (child->dev_type != SAS_EDGE_EXPANDER_DEVICE &&
@@ -1173,7 +1173,7 @@ static int sas_check_level_subtractive_boundary(struct domain_device *dev)
11731173
sas_find_sub_addr(child, sub_addr);
11741174
continue;
11751175
} else {
1176-
u8 s2[8];
1176+
u8 s2[SAS_ADDR_SIZE];
11771177

11781178
if (sas_find_sub_addr(child, s2) &&
11791179
(SAS_ADDR(sub_addr) != SAS_ADDR(s2))) {
@@ -1760,10 +1760,11 @@ static int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id,
17601760

17611761
res = sas_get_phy_discover(dev, phy_id, disc_resp);
17621762
if (res == 0) {
1763-
memcpy(sas_addr, disc_resp->disc.attached_sas_addr, 8);
1763+
memcpy(sas_addr, disc_resp->disc.attached_sas_addr,
1764+
SAS_ADDR_SIZE);
17641765
*type = to_dev_type(dr);
17651766
if (*type == 0)
1766-
memset(sas_addr, 0, 8);
1767+
memset(sas_addr, 0, SAS_ADDR_SIZE);
17671768
}
17681769
kfree(disc_resp);
17691770
return res;
@@ -2027,10 +2028,10 @@ static int sas_rediscover_dev(struct domain_device *dev, int phy_id, bool last)
20272028
struct expander_device *ex = &dev->ex_dev;
20282029
struct ex_phy *phy = &ex->ex_phy[phy_id];
20292030
enum sas_device_type type = SAS_PHY_UNUSED;
2030-
u8 sas_addr[8];
2031+
u8 sas_addr[SAS_ADDR_SIZE];
20312032
int res;
20322033

2033-
memset(sas_addr, 0, 8);
2034+
memset(sas_addr, 0, SAS_ADDR_SIZE);
20342035
res = sas_get_phy_attached_dev(dev, phy_id, sas_addr, &type);
20352036
switch (res) {
20362037
case SMP_RESP_NO_PHY:

‎drivers/scsi/libsas/sas_init.c‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,27 @@ EXPORT_SYMBOL_GPL(sas_free_task);
8787
/*------------ SAS addr hash -----------*/
8888
void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
8989
{
90-
const u32 poly = 0x00DB2777;
91-
u32 r = 0;
92-
int i;
93-
94-
for (i = 0; i < 8; i++) {
95-
int b;
96-
for (b = 7; b >= 0; b--) {
97-
r <<= 1;
98-
if ((1 << b) & sas_addr[i]) {
99-
if (!(r & 0x01000000))
100-
r ^= poly;
101-
} else if (r & 0x01000000)
102-
r ^= poly;
103-
}
104-
}
105-
106-
hashed[0] = (r >> 16) & 0xFF;
107-
hashed[1] = (r >> 8) & 0xFF ;
108-
hashed[2] = r & 0xFF;
90+
const u32 poly = 0x00DB2777;
91+
u32 r = 0;
92+
int i;
93+
94+
for (i = 0; i < SAS_ADDR_SIZE; i++) {
95+
int b;
96+
97+
for (b = (SAS_ADDR_SIZE - 1); b >= 0; b--) {
98+
r <<= 1;
99+
if ((1 << b) & sas_addr[i]) {
100+
if (!(r & 0x01000000))
101+
r ^= poly;
102+
} else if (r & 0x01000000) {
103+
r ^= poly;
104+
}
105+
}
106+
}
107+
108+
hashed[0] = (r >> 16) & 0xFF;
109+
hashed[1] = (r >> 8) & 0xFF;
110+
hashed[2] = r & 0xFF;
109111
}
110112

111113
int sas_register_ha(struct sas_ha_struct *sas_ha)

‎include/scsi/libsas.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ static inline struct sas_discovery_event *to_sas_discovery_event(struct work_str
245245
struct sas_discovery {
246246
struct sas_discovery_event disc_work[DISC_NUM_EVENTS];
247247
unsigned long pending;
248-
u8 fanout_sas_addr[8];
249-
u8 eeds_a[8];
250-
u8 eeds_b[8];
248+
u8 fanout_sas_addr[SAS_ADDR_SIZE];
249+
u8 eeds_a[SAS_ADDR_SIZE];
250+
u8 eeds_b[SAS_ADDR_SIZE];
251251
int max_level;
252252
};
253253

0 commit comments

Comments
 (0)