Skip to content

Commit 2850b23

Browse files
Jakob-Koschelmartinkpetersen
authored andcommitted
scsi: lpfc: Avoid usage of list iterator variable after loop
If the &epd_pool->list is empty when executing lpfc_get_io_buf_from_expedite_pool() the function would return an invalid pointer. Even in the case if the list is guaranteed to be populated, the iterator variable should not be used after the loop to be more robust for future changes. Linus proposed to avoid any use of the list iterator variable after the loop, in the attempt to move the list iterator variable declaration into the macro to avoid any potential misuse after the loop [1]. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel <[email protected]> Link: https://lore.kernel.org/r/20230301-scsi-lpfc-avoid-list-iterator-after-loop-v1-1-325578ae7561@gmail.com Reviewed-by: Justin Tee <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 312320b commit 2850b23

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/scsi/lpfc/lpfc_sli.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21899,20 +21899,20 @@ lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
2189921899
static struct lpfc_io_buf *
2190021900
lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
2190121901
{
21902-
struct lpfc_io_buf *lpfc_ncmd;
21902+
struct lpfc_io_buf *lpfc_ncmd = NULL, *iter;
2190321903
struct lpfc_io_buf *lpfc_ncmd_next;
2190421904
unsigned long iflag;
2190521905
struct lpfc_epd_pool *epd_pool;
2190621906

2190721907
epd_pool = &phba->epd_pool;
21908-
lpfc_ncmd = NULL;
2190921908

2191021909
spin_lock_irqsave(&epd_pool->lock, iflag);
2191121910
if (epd_pool->count > 0) {
21912-
list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21911+
list_for_each_entry_safe(iter, lpfc_ncmd_next,
2191321912
&epd_pool->list, list) {
21914-
list_del(&lpfc_ncmd->list);
21913+
list_del(&iter->list);
2191521914
epd_pool->count--;
21915+
lpfc_ncmd = iter;
2191621916
break;
2191721917
}
2191821918
}

0 commit comments

Comments
 (0)