linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
@ 2014-03-18 20:51 Matei Oprea
  2014-04-07 12:37 ` Matei Oprea
  2014-04-08  6:36 ` Boaz Harrosh
  0 siblings, 2 replies; 12+ messages in thread
From: Matei Oprea @ 2014-03-18 20:51 UTC (permalink / raw)
  To: jbottomley
  Cc: james.smart, linux-scsi, linux-kernel, Matei Oprea,
	ROSEdu Kernel Community

It's easier to use kcalloc for allocating arrays. While at it
also remove useless casting value.

Signed-off-by: Matei Oprea <eu@opreamatei.ro>
Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
---
 drivers/scsi/lpfc/lpfc_init.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 68c94cc..0a51ca5 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -4731,9 +4731,9 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
 	}
 
 	if (!phba->sli.ring)
-		phba->sli.ring = (struct lpfc_sli_ring *)
-			kzalloc(LPFC_SLI3_MAX_RING *
+		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
 			sizeof(struct lpfc_sli_ring), GFP_KERNEL);
+
 	if (!phba->sli.ring)
 		return -ENOMEM;
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
  2014-03-18 20:51 Matei Oprea
@ 2014-04-07 12:37 ` Matei Oprea
  2014-04-08  6:36 ` Boaz Harrosh
  1 sibling, 0 replies; 12+ messages in thread
From: Matei Oprea @ 2014-04-07 12:37 UTC (permalink / raw)
  To: jbottomley
  Cc: james.smart, linux-scsi, linux-kernel, Matei Oprea,
	ROSEdu Kernel Community

Any comments on this ?
ᐧ

On Tue, Mar 18, 2014 at 10:51 PM, Matei Oprea <eu@opreamatei.ro> wrote:
> It's easier to use kcalloc for allocating arrays. While at it
> also remove useless casting value.
>
> Signed-off-by: Matei Oprea <eu@opreamatei.ro>
> Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
> ---
>  drivers/scsi/lpfc/lpfc_init.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 68c94cc..0a51ca5 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -4731,9 +4731,9 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
>         }
>
>         if (!phba->sli.ring)
> -               phba->sli.ring = (struct lpfc_sli_ring *)
> -                       kzalloc(LPFC_SLI3_MAX_RING *
> +               phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
>                         sizeof(struct lpfc_sli_ring), GFP_KERNEL);
> +
>         if (!phba->sli.ring)
>                 return -ENOMEM;
>
> --
> 1.7.9.5
>



-- 
Oprea Matei
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
  2014-03-18 20:51 Matei Oprea
  2014-04-07 12:37 ` Matei Oprea
@ 2014-04-08  6:36 ` Boaz Harrosh
  1 sibling, 0 replies; 12+ messages in thread
From: Boaz Harrosh @ 2014-04-08  6:36 UTC (permalink / raw)
  To: Matei Oprea, jbottomley
  Cc: james.smart, linux-scsi, linux-kernel, ROSEdu Kernel Community

On 03/18/2014 10:51 PM, Matei Oprea wrote:
> It's easier to use kcalloc for allocating arrays. While at it
> also remove useless casting value.
> 
> Signed-off-by: Matei Oprea <eu@opreamatei.ro>
> Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
> ---
>  drivers/scsi/lpfc/lpfc_init.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 68c94cc..0a51ca5 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -4731,9 +4731,9 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
>  	}
>  
>  	if (!phba->sli.ring)
> -		phba->sli.ring = (struct lpfc_sli_ring *)
> -			kzalloc(LPFC_SLI3_MAX_RING *
> +		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
>  			sizeof(struct lpfc_sli_ring), GFP_KERNEL);
> +

Just a nit please put this recheck inside the if(){} so in the hot path
when phba->sli.ring is already allocated it will not test twice.

>  	if (!phba->sli.ring)

and unlikely() on this if

>  		return -ENOMEM;
>  
> 

thanks
Boaz

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
@ 2014-04-08 19:44 Matei Oprea
  2014-04-08 19:48 ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: Matei Oprea @ 2014-04-08 19:44 UTC (permalink / raw)
  To: jbottomley; +Cc: linux-scsi, linux-kernel, Matei Oprea, ROSEdu Kernel Community

It's easier to use kcalloc for allocating arrays. While at it
also remove useless casting value.

Signed-off-by: Matei Oprea <eu@opreamatei.ro>
Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
---
 drivers/scsi/lpfc/lpfc_init.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 635eeb3..e286909 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -4742,12 +4742,12 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
 			phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
 	}
 
-	if (!phba->sli.ring)
-		phba->sli.ring = (struct lpfc_sli_ring *)
-			kzalloc(LPFC_SLI3_MAX_RING *
-			sizeof(struct lpfc_sli_ring), GFP_KERNEL);
-	if (!phba->sli.ring)
+	if (!phba->sli.ring) {
+		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
+				sizeof(struct lpfc_sli_ring),
+				GFP_KERNEL);
 		return -ENOMEM;
+	}
 
 	/*
 	 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
  2014-04-08 19:44 Matei Oprea
@ 2014-04-08 19:48 ` Joe Perches
  0 siblings, 0 replies; 12+ messages in thread
From: Joe Perches @ 2014-04-08 19:48 UTC (permalink / raw)
  To: Matei Oprea; +Cc: jbottomley, linux-scsi, linux-kernel, ROSEdu Kernel Community

On Tue, 2014-04-08 at 22:44 +0300, Matei Oprea wrote:
> It's easier to use kcalloc for allocating arrays. While at it
> also remove useless casting value.
> 
> Signed-off-by: Matei Oprea <eu@opreamatei.ro>
> Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
> ---
>  drivers/scsi/lpfc/lpfc_init.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 635eeb3..e286909 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -4742,12 +4742,12 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
>  			phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
>  	}
>  
> -	if (!phba->sli.ring)
> -		phba->sli.ring = (struct lpfc_sli_ring *)
> -			kzalloc(LPFC_SLI3_MAX_RING *
> -			sizeof(struct lpfc_sli_ring), GFP_KERNEL);
> -	if (!phba->sli.ring)
> +	if (!phba->sli.ring) {
> +		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
> +				sizeof(struct lpfc_sli_ring),
> +				GFP_KERNEL);
>  		return -ENOMEM;
> +	}

You seem to be returning -ENOMEM after kcalloc.

You need to put back the

	if (!phba->sli.ring)
		return -ENOMEM;

after the alloc.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
@ 2014-04-08 20:18 Matei Oprea
  2014-04-08 20:20 ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: Matei Oprea @ 2014-04-08 20:18 UTC (permalink / raw)
  To: jbottomley; +Cc: linux-scsi, linux-kernel, Matei Oprea, ROSEdu Kernel Community

It's easier to use kcalloc for allocating arrays. While at it
also remove useless casting value.

Signed-off-by: Matei Oprea <eu@opreamatei.ro>
Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
---
 drivers/scsi/lpfc/lpfc_init.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index e286909..2b1a786 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -4742,12 +4742,14 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
 			phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
 	}
 
-	if (!phba->sli.ring) {
+	if (unlikely(!phba->sli.ring)) {
 		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
 				sizeof(struct lpfc_sli_ring),
 				GFP_KERNEL);
-		return -ENOMEM;
 	}
+
+	if (!phba->sli.ring)
+		return -ENOMEM;
 
 	/*
 	 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
  2014-04-08 20:18 [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory Matei Oprea
@ 2014-04-08 20:20 ` Joe Perches
  2014-04-08 20:21   ` Matei Oprea
  0 siblings, 1 reply; 12+ messages in thread
From: Joe Perches @ 2014-04-08 20:20 UTC (permalink / raw)
  To: Matei Oprea; +Cc: jbottomley, linux-scsi, linux-kernel, ROSEdu Kernel Community

On Tue, 2014-04-08 at 23:18 +0300, Matei Oprea wrote:
> It's easier to use kcalloc for allocating arrays. While at it
> also remove useless casting value.

Don't send a patch against your bad patch.
Send a new patch with just the appropriate
changes.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
  2014-04-08 20:20 ` Joe Perches
@ 2014-04-08 20:21   ` Matei Oprea
  0 siblings, 0 replies; 12+ messages in thread
From: Matei Oprea @ 2014-04-08 20:21 UTC (permalink / raw)
  To: Joe Perches; +Cc: jbottomley, linux-scsi, linux-kernel, ROSEdu Kernel Community

Ok. Sorry.
ᐧ

On Tue, Apr 8, 2014 at 11:20 PM, Joe Perches <joe@perches.com> wrote:
> On Tue, 2014-04-08 at 23:18 +0300, Matei Oprea wrote:
>> It's easier to use kcalloc for allocating arrays. While at it
>> also remove useless casting value.
>
> Don't send a patch against your bad patch.
> Send a new patch with just the appropriate
> changes.
>
>



-- 
Oprea Matei

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
@ 2014-04-08 20:42 Matei Oprea
  2014-04-09  0:04 ` Joe Perches
  2014-04-09 10:48 ` Boaz Harrosh
  0 siblings, 2 replies; 12+ messages in thread
From: Matei Oprea @ 2014-04-08 20:42 UTC (permalink / raw)
  To: jbottomley; +Cc: linux-scsi, linux-kernel, Matei Oprea, ROSEdu Kernel Community

It's easier to use kcalloc for allocating arrays. While at it
also remove useless casting value.

Signed-off-by: Matei Oprea <eu@opreamatei.ro>
Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
---
 drivers/scsi/lpfc/lpfc_init.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 635eeb3..1528f34 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -4742,12 +4742,14 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
 			phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
 	}
 
-	if (!phba->sli.ring)
-		phba->sli.ring = (struct lpfc_sli_ring *)
-			kzalloc(LPFC_SLI3_MAX_RING *
-			sizeof(struct lpfc_sli_ring), GFP_KERNEL);
-	if (!phba->sli.ring)
-		return -ENOMEM;
+	if (unlikely(!phba->sli.ring)) {
+		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
+				sizeof(struct lpfc_sli_ring),
+				GFP_KERNEL);
+
+		if (!phba->sli.ring)
+			return -ENOMEM;
+	}
 
 	/*
 	 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
  2014-04-08 20:42 Matei Oprea
@ 2014-04-09  0:04 ` Joe Perches
  2014-04-09 10:48 ` Boaz Harrosh
  1 sibling, 0 replies; 12+ messages in thread
From: Joe Perches @ 2014-04-09  0:04 UTC (permalink / raw)
  To: Matei Oprea; +Cc: jbottomley, linux-scsi, linux-kernel, ROSEdu Kernel Community

On Tue, 2014-04-08 at 23:42 +0300, Matei Oprea wrote:
> It's easier to use kcalloc for allocating arrays. While at it
> also remove useless casting value.
[]
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
[]
> @@ -4742,12 +4742,14 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
[]
> -	if (!phba->sli.ring)
[]
> +	if (unlikely(!phba->sli.ring)) {

Why add the unlikely?

Glancing at the code it seems more like that this
should be likely than unlikely.

> +		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
> +				sizeof(struct lpfc_sli_ring),
> +				GFP_KERNEL);

It'd be nicer looking if aligned better

		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
					 sizeof(struct lpfc_sli_ring),
					 GFP_KERNEL);



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
  2014-04-08 20:42 Matei Oprea
  2014-04-09  0:04 ` Joe Perches
@ 2014-04-09 10:48 ` Boaz Harrosh
  1 sibling, 0 replies; 12+ messages in thread
From: Boaz Harrosh @ 2014-04-09 10:48 UTC (permalink / raw)
  To: Matei Oprea, jbottomley; +Cc: linux-scsi, linux-kernel, ROSEdu Kernel Community

On 04/08/2014 11:42 PM, Matei Oprea wrote:
> It's easier to use kcalloc for allocating arrays. While at it
> also remove useless casting value.
> 
> Signed-off-by: Matei Oprea <eu@opreamatei.ro>
> Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
> ---
>  drivers/scsi/lpfc/lpfc_init.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 635eeb3..1528f34 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -4742,12 +4742,14 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
>  			phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
>  	}
>  
> -	if (!phba->sli.ring)
> -		phba->sli.ring = (struct lpfc_sli_ring *)
> -			kzalloc(LPFC_SLI3_MAX_RING *
> -			sizeof(struct lpfc_sli_ring), GFP_KERNEL);
> -	if (!phba->sli.ring)
> -		return -ENOMEM;
> +	if (unlikely(!phba->sli.ring)) {

As Joe Perches said this one is not unlikely, it might or it might not
depending on state.

> +		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
> +				sizeof(struct lpfc_sli_ring),
> +				GFP_KERNEL);
> +
> +		if (!phba->sli.ring)

but this one is unlikely. This is the error path so we want
the hot path to be decoded by the CPU.

> +			return -ENOMEM;
> +	}
>  
>  	/*
>  	 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
> 

Cheers
Boaz

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory
@ 2014-04-11  9:21 Matei Oprea
  0 siblings, 0 replies; 12+ messages in thread
From: Matei Oprea @ 2014-04-11  9:21 UTC (permalink / raw)
  To: jbottomley; +Cc: linux-scsi, linux-kernel, Matei Oprea, ROSEdu Kernel Community

It's easier to use kcalloc for allocating arrays. While at it
also remove useless casting value.

Signed-off-by: Matei Oprea <eu@opreamatei.ro>
Cc: ROSEdu Kernel Community <firefly@lists.rosedu.org>
---
 drivers/scsi/lpfc/lpfc_init.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 635eeb3..7e58c22 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -4742,12 +4742,13 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
 			phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
 	}
 
-	if (!phba->sli.ring)
-		phba->sli.ring = (struct lpfc_sli_ring *)
-			kzalloc(LPFC_SLI3_MAX_RING *
-			sizeof(struct lpfc_sli_ring), GFP_KERNEL);
-	if (!phba->sli.ring)
-		return -ENOMEM;
+	if (!phba->sli.ring) {
+		phba->sli.ring = kcalloc(LPFC_SLI3_MAX_RING,
+					 sizeof(struct lpfc_sli_ring),
+					 GFP_KERNEL);
+		if (!phba->sli.ring)
+			return -ENOMEM;
+	}
 
 	/*
 	 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-04-11  9:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-08 20:18 [PATCH] scsi: lpfc: lpfc_init: use kcalloc for allocating memory Matei Oprea
2014-04-08 20:20 ` Joe Perches
2014-04-08 20:21   ` Matei Oprea
  -- strict thread matches above, loose matches on Subject: below --
2014-04-11  9:21 Matei Oprea
2014-04-08 20:42 Matei Oprea
2014-04-09  0:04 ` Joe Perches
2014-04-09 10:48 ` Boaz Harrosh
2014-04-08 19:44 Matei Oprea
2014-04-08 19:48 ` Joe Perches
2014-03-18 20:51 Matei Oprea
2014-04-07 12:37 ` Matei Oprea
2014-04-08  6:36 ` Boaz Harrosh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).