From patchwork Wed Jul 15 20:53:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 6800581 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6D099C05AC for ; Wed, 15 Jul 2015 20:53:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8CF77206B5 for ; Wed, 15 Jul 2015 20:53:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F5D4206A7 for ; Wed, 15 Jul 2015 20:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753429AbbGOUxd (ORCPT ); Wed, 15 Jul 2015 16:53:33 -0400 Received: from smtp10.smtpout.orange.fr ([80.12.242.132]:50407 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752581AbbGOUxd (ORCPT ); Wed, 15 Jul 2015 16:53:33 -0400 Received: from localhost.localdomain ([92.140.160.103]) by mwinf5d45 with ME id sktV1q0032E8xV003ktV2m; Wed, 15 Jul 2015 22:53:31 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 15 Jul 2015 22:53:31 +0200 X-ME-IP: 92.140.160.103 From: Christophe JAILLET To: JBottomley@odin.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] csiostor: Use list_for_each_safe instead of re-implementing it Date: Wed, 15 Jul 2015 22:53:26 +0200 Message-Id: <69b8506362a7564f7ec5cf8acb40197b634239e9.1436993298.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.1.4 X-Antivirus: avast! (VPS 150715-1, 15/07/2015), Outbound message X-Antivirus-Status: Clean Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Johannes Thumshirn --- 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);