* [PATCH] csiostor: Use list_for_each_safe instead of re-implementing it
@ 2015-07-15 20:53 Christophe JAILLET
2015-07-16 6:50 ` Johannes Thumshirn
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2015-07-15 20:53 UTC (permalink / raw)
To: JBottomley; +Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET
Use 'list_for_each_safe' instead of 'list_for_each' + own logic to keep
safe when a list entry is deleted.
Delete the now useless 'csio_list_prev' macro.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/scsi/csiostor/csio_defs.h | 1 -
drivers/scsi/csiostor/csio_hw.c | 10 ++++------
drivers/scsi/csiostor/csio_scsi.c | 10 ++++------
3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/scsi/csiostor/csio_defs.h b/drivers/scsi/csiostor/csio_defs.h
index c38017b..4b3557c 100644
--- a/drivers/scsi/csiostor/csio_defs.h
+++ b/drivers/scsi/csiostor/csio_defs.h
@@ -70,7 +70,6 @@ csio_list_deleted(struct list_head *list)
}
#define csio_list_next(elem) (((struct list_head *)(elem))->next)
-#define csio_list_prev(elem) (((struct list_head *)(elem))->prev)
/* State machine */
typedef void (*csio_sm_state_t)(void *, uint32_t);
diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c
index 622bdab..61ee6cb 100644
--- a/drivers/scsi/csiostor/csio_hw.c
+++ b/drivers/scsi/csiostor/csio_hw.c
@@ -3643,20 +3643,19 @@ static void
csio_mgmt_tmo_handler(uintptr_t data)
{
struct csio_mgmtm *mgmtm = (struct csio_mgmtm *) data;
- struct list_head *tmp;
+ struct list_head *tmp, *next;
struct csio_ioreq *io_req;
csio_dbg(mgmtm->hw, "Mgmt timer invoked!\n");
spin_lock_irq(&mgmtm->hw->lock);
- list_for_each(tmp, &mgmtm->active_q) {
+ list_for_each_safe(tmp, next, &mgmtm->active_q) {
io_req = (struct csio_ioreq *) tmp;
io_req->tmo -= min_t(uint32_t, io_req->tmo, ECM_MIN_TMO);
if (!io_req->tmo) {
/* Dequeue the request from retry Q. */
- tmp = csio_list_prev(tmp);
list_del_init(&io_req->sm.sm_list);
if (io_req->io_cbfn) {
/* io_req will be freed by completion handler */
@@ -3680,7 +3679,7 @@ csio_mgmtm_cleanup(struct csio_mgmtm *mgmtm)
{
struct csio_hw *hw = mgmtm->hw;
struct csio_ioreq *io_req;
- struct list_head *tmp;
+ struct list_head *tmp, *next;
uint32_t count;
count = 30;
@@ -3692,9 +3691,8 @@ csio_mgmtm_cleanup(struct csio_mgmtm *mgmtm)
}
/* release outstanding req from ACTIVEQ */
- list_for_each(tmp, &mgmtm->active_q) {
+ list_for_each_safe(tmp, next, &mgmtm->active_q) {
io_req = (struct csio_ioreq *) tmp;
- tmp = csio_list_prev(tmp);
list_del_init(&io_req->sm.sm_list);
mgmtm->stats.n_active--;
if (io_req->io_cbfn) {
diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c
index 2c4562d..2bfb401 100644
--- a/drivers/scsi/csiostor/csio_scsi.c
+++ b/drivers/scsi/csiostor/csio_scsi.c
@@ -2322,7 +2322,7 @@ csio_scsi_alloc_ddp_bufs(struct csio_scsim *scm, struct csio_hw *hw,
int buf_size, int num_buf)
{
int n = 0;
- struct list_head *tmp;
+ struct list_head *tmp, *next;
struct csio_dma_buf *ddp_desc = NULL;
uint32_t unit_size = 0;
@@ -2370,9 +2370,8 @@ csio_scsi_alloc_ddp_bufs(struct csio_scsim *scm, struct csio_hw *hw,
return 0;
no_mem:
/* release dma descs back to freelist and free dma memory */
- list_for_each(tmp, &scm->ddp_freelist) {
+ list_for_each_safe(tmp, next, &scm->ddp_freelist) {
ddp_desc = (struct csio_dma_buf *) tmp;
- tmp = csio_list_prev(tmp);
pci_free_consistent(hw->pdev, ddp_desc->len, ddp_desc->vaddr,
ddp_desc->paddr);
list_del_init(&ddp_desc->list);
@@ -2393,13 +2392,12 @@ no_mem:
static void
csio_scsi_free_ddp_bufs(struct csio_scsim *scm, struct csio_hw *hw)
{
- struct list_head *tmp;
+ struct list_head *tmp, *next;
struct csio_dma_buf *ddp_desc;
/* release dma descs back to freelist and free dma memory */
- list_for_each(tmp, &scm->ddp_freelist) {
+ list_for_each_safe(tmp, next, &scm->ddp_freelist) {
ddp_desc = (struct csio_dma_buf *) tmp;
- tmp = csio_list_prev(tmp);
pci_free_consistent(hw->pdev, ddp_desc->len, ddp_desc->vaddr,
ddp_desc->paddr);
list_del_init(&ddp_desc->list);
--
2.1.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] csiostor: Use list_for_each_safe instead of re-implementing it
2015-07-15 20:53 [PATCH] csiostor: Use list_for_each_safe instead of re-implementing it Christophe JAILLET
@ 2015-07-16 6:50 ` Johannes Thumshirn
0 siblings, 0 replies; 2+ messages in thread
From: Johannes Thumshirn @ 2015-07-16 6:50 UTC (permalink / raw)
To: Christophe JAILLET; +Cc: JBottomley, linux-scsi, linux-kernel, kernel-janitors
Christophe JAILLET <christophe.jaillet@wanadoo.fr> writes:
> Use 'list_for_each_safe' instead of 'list_for_each' + own logic to keep
> safe when a list entry is deleted.
> Delete the now useless 'csio_list_prev' macro.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/scsi/csiostor/csio_defs.h | 1 -
> drivers/scsi/csiostor/csio_hw.c | 10 ++++------
> drivers/scsi/csiostor/csio_scsi.c | 10 ++++------
> 3 files changed, 8 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/scsi/csiostor/csio_defs.h b/drivers/scsi/csiostor/csio_defs.h
> index c38017b..4b3557c 100644
> --- a/drivers/scsi/csiostor/csio_defs.h
> +++ b/drivers/scsi/csiostor/csio_defs.h
> @@ -70,7 +70,6 @@ csio_list_deleted(struct list_head *list)
> }
>
> #define csio_list_next(elem) (((struct list_head *)(elem))->next)
> -#define csio_list_prev(elem) (((struct list_head *)(elem))->prev)
>
> /* State machine */
> typedef void (*csio_sm_state_t)(void *, uint32_t);
> diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c
> index 622bdab..61ee6cb 100644
> --- a/drivers/scsi/csiostor/csio_hw.c
> +++ b/drivers/scsi/csiostor/csio_hw.c
> @@ -3643,20 +3643,19 @@ static void
> csio_mgmt_tmo_handler(uintptr_t data)
> {
> struct csio_mgmtm *mgmtm = (struct csio_mgmtm *) data;
> - struct list_head *tmp;
> + struct list_head *tmp, *next;
> struct csio_ioreq *io_req;
>
> csio_dbg(mgmtm->hw, "Mgmt timer invoked!\n");
>
> spin_lock_irq(&mgmtm->hw->lock);
>
> - list_for_each(tmp, &mgmtm->active_q) {
> + list_for_each_safe(tmp, next, &mgmtm->active_q) {
> io_req = (struct csio_ioreq *) tmp;
> io_req->tmo -= min_t(uint32_t, io_req->tmo, ECM_MIN_TMO);
>
> if (!io_req->tmo) {
> /* Dequeue the request from retry Q. */
> - tmp = csio_list_prev(tmp);
> list_del_init(&io_req->sm.sm_list);
> if (io_req->io_cbfn) {
> /* io_req will be freed by completion handler */
> @@ -3680,7 +3679,7 @@ csio_mgmtm_cleanup(struct csio_mgmtm *mgmtm)
> {
> struct csio_hw *hw = mgmtm->hw;
> struct csio_ioreq *io_req;
> - struct list_head *tmp;
> + struct list_head *tmp, *next;
> uint32_t count;
>
> count = 30;
> @@ -3692,9 +3691,8 @@ csio_mgmtm_cleanup(struct csio_mgmtm *mgmtm)
> }
>
> /* release outstanding req from ACTIVEQ */
> - list_for_each(tmp, &mgmtm->active_q) {
> + list_for_each_safe(tmp, next, &mgmtm->active_q) {
> io_req = (struct csio_ioreq *) tmp;
> - tmp = csio_list_prev(tmp);
> list_del_init(&io_req->sm.sm_list);
> mgmtm->stats.n_active--;
> if (io_req->io_cbfn) {
> diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c
> index 2c4562d..2bfb401 100644
> --- a/drivers/scsi/csiostor/csio_scsi.c
> +++ b/drivers/scsi/csiostor/csio_scsi.c
> @@ -2322,7 +2322,7 @@ csio_scsi_alloc_ddp_bufs(struct csio_scsim *scm, struct csio_hw *hw,
> int buf_size, int num_buf)
> {
> int n = 0;
> - struct list_head *tmp;
> + struct list_head *tmp, *next;
> struct csio_dma_buf *ddp_desc = NULL;
> uint32_t unit_size = 0;
>
> @@ -2370,9 +2370,8 @@ csio_scsi_alloc_ddp_bufs(struct csio_scsim *scm, struct csio_hw *hw,
> return 0;
> no_mem:
> /* release dma descs back to freelist and free dma memory */
> - list_for_each(tmp, &scm->ddp_freelist) {
> + list_for_each_safe(tmp, next, &scm->ddp_freelist) {
> ddp_desc = (struct csio_dma_buf *) tmp;
> - tmp = csio_list_prev(tmp);
> pci_free_consistent(hw->pdev, ddp_desc->len, ddp_desc->vaddr,
> ddp_desc->paddr);
> list_del_init(&ddp_desc->list);
> @@ -2393,13 +2392,12 @@ no_mem:
> static void
> csio_scsi_free_ddp_bufs(struct csio_scsim *scm, struct csio_hw *hw)
> {
> - struct list_head *tmp;
> + struct list_head *tmp, *next;
> struct csio_dma_buf *ddp_desc;
>
> /* release dma descs back to freelist and free dma memory */
> - list_for_each(tmp, &scm->ddp_freelist) {
> + list_for_each_safe(tmp, next, &scm->ddp_freelist) {
> ddp_desc = (struct csio_dma_buf *) tmp;
> - tmp = csio_list_prev(tmp);
> pci_free_consistent(hw->pdev, ddp_desc->len, ddp_desc->vaddr,
> ddp_desc->paddr);
> list_del_init(&ddp_desc->list);
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-16 6:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15 20:53 [PATCH] csiostor: Use list_for_each_safe instead of re-implementing it Christophe JAILLET
2015-07-16 6:50 ` Johannes Thumshirn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®