Skip to content

Commit

Permalink
scsi: lpfc: Avoid usage of list iterator variable after loop
Browse files Browse the repository at this point in the history
[ Upstream commit 2850b23 ]

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 <jkl820.git@gmail.com>
Link: https://lore.kernel.org/r/20230301-scsi-lpfc-avoid-list-iterator-after-loop-v1-1-325578ae7561@gmail.com
Reviewed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Jakob Koschel authored and Greg Kroah-Hartman committed Mar 30, 2023
1 parent 67b8343 commit 60643ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/scsi/lpfc/lpfc_sli.c
Original file line number Diff line number Diff line change
Expand Up @@ -22166,20 +22166,20 @@ lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
static struct lpfc_io_buf *
lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
{
struct lpfc_io_buf *lpfc_ncmd;
struct lpfc_io_buf *lpfc_ncmd = NULL, *iter;
struct lpfc_io_buf *lpfc_ncmd_next;
unsigned long iflag;
struct lpfc_epd_pool *epd_pool;

epd_pool = &phba->epd_pool;
lpfc_ncmd = NULL;

spin_lock_irqsave(&epd_pool->lock, iflag);
if (epd_pool->count > 0) {
list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
list_for_each_entry_safe(iter, lpfc_ncmd_next,
&epd_pool->list, list) {
list_del(&lpfc_ncmd->list);
list_del(&iter->list);
epd_pool->count--;
lpfc_ncmd = iter;
break;
}
}
Expand Down

0 comments on commit 60643ef

Please sign in to comment.