Skip to content

Commit e402ee0

Browse files
Chaohai Chenmartinkpetersen
authored andcommitted
scsi: core: Use a switch statement when attaching VPD pages
The original code used if statements to update discovered VPD pages when found. This had the side-effect of not breaking the loop when a page was found. Use an idiomatic switch statement instead. Signed-off-by: Chaohai Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent ffd6c17 commit e402ee0

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

drivers/scsi/scsi.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -510,22 +510,34 @@ void scsi_attach_vpd(struct scsi_device *sdev)
510510
return;
511511

512512
for (i = 4; i < vpd_buf->len; i++) {
513-
if (vpd_buf->data[i] == 0x0)
513+
switch (vpd_buf->data[i]) {
514+
case 0x0:
514515
scsi_update_vpd_page(sdev, 0x0, &sdev->vpd_pg0);
515-
if (vpd_buf->data[i] == 0x80)
516+
break;
517+
case 0x80:
516518
scsi_update_vpd_page(sdev, 0x80, &sdev->vpd_pg80);
517-
if (vpd_buf->data[i] == 0x83)
519+
break;
520+
case 0x83:
518521
scsi_update_vpd_page(sdev, 0x83, &sdev->vpd_pg83);
519-
if (vpd_buf->data[i] == 0x89)
522+
break;
523+
case 0x89:
520524
scsi_update_vpd_page(sdev, 0x89, &sdev->vpd_pg89);
521-
if (vpd_buf->data[i] == 0xb0)
525+
break;
526+
case 0xb0:
522527
scsi_update_vpd_page(sdev, 0xb0, &sdev->vpd_pgb0);
523-
if (vpd_buf->data[i] == 0xb1)
528+
break;
529+
case 0xb1:
524530
scsi_update_vpd_page(sdev, 0xb1, &sdev->vpd_pgb1);
525-
if (vpd_buf->data[i] == 0xb2)
531+
break;
532+
case 0xb2:
526533
scsi_update_vpd_page(sdev, 0xb2, &sdev->vpd_pgb2);
527-
if (vpd_buf->data[i] == 0xb7)
534+
break;
535+
case 0xb7:
528536
scsi_update_vpd_page(sdev, 0xb7, &sdev->vpd_pgb7);
537+
break;
538+
default:
539+
break;
540+
}
529541
}
530542
kfree(vpd_buf);
531543
}

0 commit comments

Comments
 (0)