All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:49 ` James Bottomley
@ 2012-03-21  8:50 ` santosh nayak
  2012-03-21 10:50   ` walter harms
  2012-03-21 11:06   ` Dan Carpenter
  2 siblings, 0 replies; 12+ messages in thread
From: santosh nayak @ 2012-03-21  8:38 UTC (permalink / raw)
  To: jack_wang
  Cc: mark_salyzyn, lindar_liu, JBottomley, linux-scsi, kernel-janitors,
	Santosh Nayak

From: Santosh Nayak <santoshprasadnayak@gmail.com>

We need to add error handler if kzalloc fails to allocate and initialize.
Otherwise it may lead to Null derefernce error in 
'pm8001_chip_get_nvmd_req()'.

Signed-off-by: Santosh Nayak <santoshprasadnayak@gmail.com>
---
 drivers/scsi/pm8001/pm8001_init.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index 36efaa7..fdce28e 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -519,6 +519,10 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
 	payload.minor_function = 0;
 	payload.length = 128;
 	payload.func_specific = kzalloc(128, GFP_KERNEL);
+	if (unlikely(!payload.func_specific)) {
+		printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
+		return;
+	}
 	PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
 	wait_for_completion(&completion);
 	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
-- 
1.7.4.4


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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:50 ` santosh nayak
  (?)
@ 2012-03-21  8:49 ` James Bottomley
  2012-03-21  8:58     ` Dan Carpenter
                     ` (2 more replies)
  -1 siblings, 3 replies; 12+ messages in thread
From: James Bottomley @ 2012-03-21  8:49 UTC (permalink / raw)
  To: santosh nayak
  Cc: jack_wang, mark_salyzyn, lindar_liu, linux-scsi, kernel-janitors

On Wed, 2012-03-21 at 14:08 +0530, santosh nayak wrote:
> From: Santosh Nayak <santoshprasadnayak@gmail.com>
> 
> We need to add error handler if kzalloc fails to allocate and initialize.
> Otherwise it may lead to Null derefernce error in 
> 'pm8001_chip_get_nvmd_req()'.

It's a GFP_KERNEL allocation.  They sleep until memory is available
(__GFP_WAIT).  It's GFP_ATOMIC that can return NULL.

James



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

* [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
@ 2012-03-21  8:50 ` santosh nayak
  0 siblings, 0 replies; 12+ messages in thread
From: santosh nayak @ 2012-03-21  8:50 UTC (permalink / raw)
  To: jack_wang
  Cc: mark_salyzyn, lindar_liu, JBottomley, linux-scsi, kernel-janitors,
	Santosh Nayak

From: Santosh Nayak <santoshprasadnayak@gmail.com>

We need to add error handler if kzalloc fails to allocate and initialize.
Otherwise it may lead to Null derefernce error in 
'pm8001_chip_get_nvmd_req()'.

Signed-off-by: Santosh Nayak <santoshprasadnayak@gmail.com>
---
 drivers/scsi/pm8001/pm8001_init.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index 36efaa7..fdce28e 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -519,6 +519,10 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
 	payload.minor_function = 0;
 	payload.length = 128;
 	payload.func_specific = kzalloc(128, GFP_KERNEL);
+	if (unlikely(!payload.func_specific)) {
+		printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
+		return;
+	}
 	PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
 	wait_for_completion(&completion);
 	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
-- 
1.7.4.4


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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:49 ` James Bottomley
@ 2012-03-21  8:58     ` Dan Carpenter
  2012-03-21 10:50   ` walter harms
  2012-03-21 11:06   ` Dan Carpenter
  2 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2012-03-21  8:58 UTC (permalink / raw)
  To: James Bottomley
  Cc: santosh nayak, jack_wang, mark_salyzyn, lindar_liu, linux-scsi,
	kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 607 bytes --]

On Wed, Mar 21, 2012 at 08:49:45AM +0000, James Bottomley wrote:
> On Wed, 2012-03-21 at 14:08 +0530, santosh nayak wrote:
> > From: Santosh Nayak <santoshprasadnayak@gmail.com>
> > 
> > We need to add error handler if kzalloc fails to allocate and initialize.
> > Otherwise it may lead to Null derefernce error in 
> > 'pm8001_chip_get_nvmd_req()'.
> 
> It's a GFP_KERNEL allocation.  They sleep until memory is available
> (__GFP_WAIT).  It's GFP_ATOMIC that can return NULL.
> 

That's not right at all.  Only __GFP_NOFAIL allocations don't need
to be checked.

regards,
dan carpenter


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
@ 2012-03-21  8:58     ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2012-03-21  8:58 UTC (permalink / raw)
  To: James Bottomley
  Cc: santosh nayak, jack_wang, mark_salyzyn, lindar_liu, linux-scsi,
	kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 607 bytes --]

On Wed, Mar 21, 2012 at 08:49:45AM +0000, James Bottomley wrote:
> On Wed, 2012-03-21 at 14:08 +0530, santosh nayak wrote:
> > From: Santosh Nayak <santoshprasadnayak@gmail.com>
> > 
> > We need to add error handler if kzalloc fails to allocate and initialize.
> > Otherwise it may lead to Null derefernce error in 
> > 'pm8001_chip_get_nvmd_req()'.
> 
> It's a GFP_KERNEL allocation.  They sleep until memory is available
> (__GFP_WAIT).  It's GFP_ATOMIC that can return NULL.
> 

That's not right at all.  Only __GFP_NOFAIL allocations don't need
to be checked.

regards,
dan carpenter


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:58     ` Dan Carpenter
  (?)
@ 2012-03-21 10:11     ` James Bottomley
  -1 siblings, 0 replies; 12+ messages in thread
From: James Bottomley @ 2012-03-21 10:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: santosh nayak, jack_wang, mark_salyzyn, lindar_liu, linux-scsi,
	kernel-janitors

On Wed, 2012-03-21 at 11:58 +0300, Dan Carpenter wrote:
> On Wed, Mar 21, 2012 at 08:49:45AM +0000, James Bottomley wrote:
> > On Wed, 2012-03-21 at 14:08 +0530, santosh nayak wrote:
> > > From: Santosh Nayak <santoshprasadnayak@gmail.com>
> > > 
> > > We need to add error handler if kzalloc fails to allocate and initialize.
> > > Otherwise it may lead to Null derefernce error in 
> > > 'pm8001_chip_get_nvmd_req()'.
> > 
> > It's a GFP_KERNEL allocation.  They sleep until memory is available
> > (__GFP_WAIT).  It's GFP_ATOMIC that can return NULL.
> > 
> 
> That's not right at all.  Only __GFP_NOFAIL allocations don't need
> to be checked.

Ah, right, that's the option I was thinking of.  __GFP_WAIT may fail if
we're in direct reclaim or the oom killer gets activated.

James



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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:49 ` James Bottomley
  2012-03-21  8:58     ` Dan Carpenter
@ 2012-03-21 10:50   ` walter harms
  2012-03-21 11:06   ` Dan Carpenter
  2 siblings, 0 replies; 12+ messages in thread
From: walter harms @ 2012-03-21 10:50 UTC (permalink / raw)
  To: kernel-janitors



Am 21.03.2012 11:11, schrieb James Bottomley:
> On Wed, 2012-03-21 at 11:58 +0300, Dan Carpenter wrote:
>> On Wed, Mar 21, 2012 at 08:49:45AM +0000, James Bottomley wrote:
>>> On Wed, 2012-03-21 at 14:08 +0530, santosh nayak wrote:
>>>> From: Santosh Nayak <santoshprasadnayak@gmail.com>
>>>>
>>>> We need to add error handler if kzalloc fails to allocate and initialize.
>>>> Otherwise it may lead to Null derefernce error in 
>>>> 'pm8001_chip_get_nvmd_req()'.
>>>
>>> It's a GFP_KERNEL allocation.  They sleep until memory is available
>>> (__GFP_WAIT).  It's GFP_ATOMIC that can return NULL.
>>>
>>
>> That's not right at all.  Only __GFP_NOFAIL allocations don't need
>> to be checked.
> 
> Ah, right, that's the option I was thinking of.  __GFP_WAIT may fail if
> we're in direct reclaim or the oom killer gets activated.
> 

I think it is ok to do it anytime. It is useles in the __GFP_NOFAIL case,
but it is more easy to check: avoid exceptions from the rule !

re,
 wh

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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:49 ` James Bottomley
  2012-03-21  8:58     ` Dan Carpenter
  2012-03-21 10:50   ` walter harms
@ 2012-03-21 11:06   ` Dan Carpenter
  2 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2012-03-21 11:06 UTC (permalink / raw)
  To: kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]

On Wed, Mar 21, 2012 at 11:50:00AM +0100, walter harms wrote:
> 
> 
> Am 21.03.2012 11:11, schrieb James Bottomley:
> > On Wed, 2012-03-21 at 11:58 +0300, Dan Carpenter wrote:
> >> On Wed, Mar 21, 2012 at 08:49:45AM +0000, James Bottomley wrote:
> >>> On Wed, 2012-03-21 at 14:08 +0530, santosh nayak wrote:
> >>>> From: Santosh Nayak <santoshprasadnayak@gmail.com>
> >>>>
> >>>> We need to add error handler if kzalloc fails to allocate and initialize.
> >>>> Otherwise it may lead to Null derefernce error in 
> >>>> 'pm8001_chip_get_nvmd_req()'.
> >>>
> >>> It's a GFP_KERNEL allocation.  They sleep until memory is available
> >>> (__GFP_WAIT).  It's GFP_ATOMIC that can return NULL.
> >>>
> >>
> >> That's not right at all.  Only __GFP_NOFAIL allocations don't need
> >> to be checked.
> > 
> > Ah, right, that's the option I was thinking of.  __GFP_WAIT may fail if
> > we're in direct reclaim or the oom killer gets activated.
> > 
> 
> I think it is ok to do it anytime. It is useles in the __GFP_NOFAIL case,
> but it is more easy to check: avoid exceptions from the rule !

That's nonsense.  Code deliberately.  I feel like I spend too much
time removing bogus NULL checks already.  Don't encourage people to
add them.

regards,
dan carpenter

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:50 ` santosh nayak
@ 2012-03-21 17:11   ` Mark Salyzyn
  -1 siblings, 0 replies; 12+ messages in thread
From: Mark Salyzyn @ 2012-03-21 17:11 UTC (permalink / raw)
  To: santosh nayak
  Cc: Mark Salyzyn, jack_wang, lindar_liu, JBottomley, linux-scsi,
	kernel-janitors

ACK based on James' concerned being extinguished by Dan's comment

Sincerely -- Mark Salyzyn

On Mar 21, 2012, at 4:38 AM, santosh nayak wrote:

> From: Santosh Nayak <santoshprasadnayak@gmail.com>
> 
> We need to add error handler if kzalloc fails to allocate and initialize.
> Otherwise it may lead to Null derefernce error in 
> 'pm8001_chip_get_nvmd_req()'.
> 
> Signed-off-by: Santosh Nayak <santoshprasadnayak@gmail.com>
> ---
> drivers/scsi/pm8001/pm8001_init.c |    4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
> index 36efaa7..fdce28e 100644
> --- a/drivers/scsi/pm8001/pm8001_init.c
> +++ b/drivers/scsi/pm8001/pm8001_init.c
> @@ -519,6 +519,10 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
> 	payload.minor_function = 0;
> 	payload.length = 128;
> 	payload.func_specific = kzalloc(128, GFP_KERNEL);
> +	if (unlikely(!payload.func_specific)) {
> +		printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
> +		return;
> +	}
> 	PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
> 	wait_for_completion(&completion);
> 	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
> -- 
> 1.7.4.4
> 


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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
@ 2012-03-21 17:11   ` Mark Salyzyn
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Salyzyn @ 2012-03-21 17:11 UTC (permalink / raw)
  To: santosh nayak
  Cc: Mark Salyzyn, jack_wang, lindar_liu, JBottomley, linux-scsi,
	kernel-janitors

ACK based on James' concerned being extinguished by Dan's comment

Sincerely -- Mark Salyzyn

On Mar 21, 2012, at 4:38 AM, santosh nayak wrote:

> From: Santosh Nayak <santoshprasadnayak@gmail.com>
> 
> We need to add error handler if kzalloc fails to allocate and initialize.
> Otherwise it may lead to Null derefernce error in 
> 'pm8001_chip_get_nvmd_req()'.
> 
> Signed-off-by: Santosh Nayak <santoshprasadnayak@gmail.com>
> ---
> drivers/scsi/pm8001/pm8001_init.c |    4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
> index 36efaa7..fdce28e 100644
> --- a/drivers/scsi/pm8001/pm8001_init.c
> +++ b/drivers/scsi/pm8001/pm8001_init.c
> @@ -519,6 +519,10 @@ static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
> 	payload.minor_function = 0;
> 	payload.length = 128;
> 	payload.func_specific = kzalloc(128, GFP_KERNEL);
> +	if (unlikely(!payload.func_specific)) {
> +		printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
> +		return;
> +	}
> 	PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
> 	wait_for_completion(&completion);
> 	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
> -- 
> 1.7.4.4
> 


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

* Re: [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
  2012-03-21  8:50 ` santosh nayak
@ 2012-03-22  1:49   ` Jack Wang
  -1 siblings, 0 replies; 12+ messages in thread
From: Jack Wang @ 2012-03-22  1:49 UTC (permalink / raw)
  To: 'santosh nayak'
  Cc: mark_salyzyn, lindar_liu, JBottomley, linux-scsi, kernel-janitors

Based on all comment from others, I ACK this patch.
Thanks.

Acked-by: Jack Wang <jack_wang@usish.com>

> 
> From: Santosh Nayak <santoshprasadnayak@gmail.com>
> 
> We need to add error handler if kzalloc fails to allocate and initialize.
> Otherwise it may lead to Null derefernce error in
> 'pm8001_chip_get_nvmd_req()'.
> 
> Signed-off-by: Santosh Nayak <santoshprasadnayak@gmail.com>
> ---
>  drivers/scsi/pm8001/pm8001_init.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/scsi/pm8001/pm8001_init.c
> b/drivers/scsi/pm8001/pm8001_init.c
> index 36efaa7..fdce28e 100644
> --- a/drivers/scsi/pm8001/pm8001_init.c
> +++ b/drivers/scsi/pm8001/pm8001_init.c
> @@ -519,6 +519,10 @@ static void pm8001_init_sas_add(struct
pm8001_hba_info
> *pm8001_ha)
>  	payload.minor_function = 0;
>  	payload.length = 128;
>  	payload.func_specific = kzalloc(128, GFP_KERNEL);
> +	if (unlikely(!payload.func_specific)) {
> +		printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
> +		return;
> +	}
>  	PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
>  	wait_for_completion(&completion);
>  	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
> --
> 1.7.4.4
> 
> --
> 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] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails.
@ 2012-03-22  1:49   ` Jack Wang
  0 siblings, 0 replies; 12+ messages in thread
From: Jack Wang @ 2012-03-22  1:49 UTC (permalink / raw)
  To: 'santosh nayak'
  Cc: mark_salyzyn, lindar_liu, JBottomley, linux-scsi, kernel-janitors

Based on all comment from others, I ACK this patch.
Thanks.

Acked-by: Jack Wang <jack_wang@usish.com>

> 
> From: Santosh Nayak <santoshprasadnayak@gmail.com>
> 
> We need to add error handler if kzalloc fails to allocate and initialize.
> Otherwise it may lead to Null derefernce error in
> 'pm8001_chip_get_nvmd_req()'.
> 
> Signed-off-by: Santosh Nayak <santoshprasadnayak@gmail.com>
> ---
>  drivers/scsi/pm8001/pm8001_init.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/scsi/pm8001/pm8001_init.c
> b/drivers/scsi/pm8001/pm8001_init.c
> index 36efaa7..fdce28e 100644
> --- a/drivers/scsi/pm8001/pm8001_init.c
> +++ b/drivers/scsi/pm8001/pm8001_init.c
> @@ -519,6 +519,10 @@ static void pm8001_init_sas_add(struct
pm8001_hba_info
> *pm8001_ha)
>  	payload.minor_function = 0;
>  	payload.length = 128;
>  	payload.func_specific = kzalloc(128, GFP_KERNEL);
> +	if (unlikely(!payload.func_specific)) {
> +		printk(KERN_ERR "%s: failed to alloc memory\n", __func__);
> +		return;
> +	}
>  	PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
>  	wait_for_completion(&completion);
>  	for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
> --
> 1.7.4.4
> 
> --
> 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

end of thread, other threads:[~2012-03-22  1:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-21  8:38 [PATCH] [SCSI] pm8001: Add error handler in pm8001_init_sas_add() if kzalloc fails santosh nayak
2012-03-21  8:50 ` santosh nayak
2012-03-21  8:49 ` James Bottomley
2012-03-21  8:58   ` Dan Carpenter
2012-03-21  8:58     ` Dan Carpenter
2012-03-21 10:11     ` James Bottomley
2012-03-21 10:50   ` walter harms
2012-03-21 11:06   ` Dan Carpenter
2012-03-21 17:11 ` Mark Salyzyn
2012-03-21 17:11   ` Mark Salyzyn
2012-03-22  1:49 ` Jack Wang
2012-03-22  1:49   ` Jack Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.