Skip to content

Commit b1b9d38

Browse files
Bikash Hazarikamartinkpetersen
authored andcommitted
scsi: qla2xxx: Correct the index of array
Klocwork reported array 'port_dstate_str' of size 10 may use index value(s) 10..15. Add a fix to correct the index of array. Cc: [email protected] Signed-off-by: Bikash Hazarika <[email protected]> Signed-off-by: Nilesh Javali <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Himanshu Madhani <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 00eca15 commit b1b9d38

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/scsi/qla2xxx/qla_inline.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,22 @@ qla2x00_set_fcport_disc_state(fc_port_t *fcport, int state)
109109
{
110110
int old_val;
111111
uint8_t shiftbits, mask;
112+
uint8_t port_dstate_str_sz;
112113

113114
/* This will have to change when the max no. of states > 16 */
114115
shiftbits = 4;
115116
mask = (1 << shiftbits) - 1;
116117

118+
port_dstate_str_sz = sizeof(port_dstate_str) / sizeof(char *);
117119
fcport->disc_state = state;
118120
while (1) {
119121
old_val = atomic_read(&fcport->shadow_disc_state);
120122
if (old_val == atomic_cmpxchg(&fcport->shadow_disc_state,
121123
old_val, (old_val << shiftbits) | state)) {
122124
ql_dbg(ql_dbg_disc, fcport->vha, 0x2134,
123125
"FCPort %8phC disc_state transition: %s to %s - portid=%06x.\n",
124-
fcport->port_name, port_dstate_str[old_val & mask],
126+
fcport->port_name, (old_val & mask) < port_dstate_str_sz ?
127+
port_dstate_str[old_val & mask] : "Unknown",
125128
port_dstate_str[state], fcport->d_id.b24);
126129
return;
127130
}

0 commit comments

Comments
 (0)