mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Vasyl Gomonovych <gomonovych@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: pmcraid: Use dma_pool_zalloc rather than dma_pool_alloc
Date: Thu, 18 Jul 2019 11:37:14 -0700	[thread overview]
Message-ID: <649403d7dbf2e4e21a96bd9a20b7cb659b97fe38.camel@perches.com> (raw)
In-Reply-To: <20190718181051.22882-1-gomonovych@gmail.com>

On Thu, 2019-07-18 at 20:10 +0200, Vasyl Gomonovych wrote:
> Use *_pool_zalloc rather than *_pool_alloc followed by memset with 0
> The semantic patch that makes this change is available
> in scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci.
[]
> diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
[]
> @@ -4653,9 +4653,7 @@ static int pmcraid_allocate_control_blocks(struct pmcraid_instance *pinstance)
>  		return -ENOMEM;
>  
>  	for (i = 0; i < PMCRAID_MAX_CMD; i++) {
> -		pinstance->cmd_list[i]->ioa_cb =
> -			dma_pool_alloc(
> -				pinstance->control_pool,
> +		pinstance->cmd_list[i]->ioa_cb = dma_pool_zalloc(pinstance->control_pool,
>  				GFP_KERNEL,
>  				&(pinstance->cmd_list[i]->ioa_cb_bus_addr));
>  
> @@ -4663,8 +4661,6 @@ static int pmcraid_allocate_control_blocks(struct pmcraid_instance *pinstance)
>  			pmcraid_release_control_blocks(pinstance, i);
>  			return -ENOMEM;
>  		}
> -		memset(pinstance->cmd_list[i]->ioa_cb, 0,
> -			sizeof(struct pmcraid_control_block));
>  	}
>  	return 0;
>  }

While this change is somewhat overdone as only
dma_pool_alloc could be changed to dma_pool_zalloc
on the same line without rewrapping other arguments,
I'd generally write this with a temporary like:
---
 drivers/scsi/pmcraid.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 71ff3936da4f..88e7b18ad44d 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -4653,19 +4653,17 @@ static int pmcraid_allocate_control_blocks(struct pmcraid_instance *pinstance)
 		return -ENOMEM;
 
 	for (i = 0; i < PMCRAID_MAX_CMD; i++) {
-		pinstance->cmd_list[i]->ioa_cb =
-			dma_pool_alloc(
-				pinstance->control_pool,
-				GFP_KERNEL,
-				&(pinstance->cmd_list[i]->ioa_cb_bus_addr));
+		struct pmcraid_cmd *cmd = pinstance->cmd_list[i];
 
-		if (!pinstance->cmd_list[i]->ioa_cb) {
+		cmd->ioa_cb = dma_pool_zalloc(pinstance->control_pool,
+					      GFP_KERNEL,
+					      &cmd->ioa_cb_bus_addr);
+		if (!cmd->ioa_cb) {
 			pmcraid_release_control_blocks(pinstance, i);
 			return -ENOMEM;
 		}
-		memset(pinstance->cmd_list[i]->ioa_cb, 0,
-			sizeof(struct pmcraid_control_block));
 	}
+
 	return 0;
 }
 


  reply	other threads:[~2019-07-18 18:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-18 18:10 Vasyl Gomonovych
2019-07-18 18:37 ` Joe Perches [this message]
2019-07-18 18:11 Vasyl Gomonovych

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=649403d7dbf2e4e21a96bd9a20b7cb659b97fe38.camel@perches.com \
    --to=joe@perches.com \
    --cc=gomonovych@gmail.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®