[PATCH] scsi: megaraid: check kzalloc

2013-05-23 Thread Libo Chen

we should check kzalloc, avoid to hit oops

Signed-off-by: Libo Chen 
---
 drivers/scsi/megaraid.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 846f475..195b095 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4162,6 +4162,10 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, 
mega_passthru *pthru)

sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
scmd->device = sdev;
+   if (!scmd->device) {
+   scsi_free_command(GFP_KERNEL, scmd);
+   return -ENOMEM;
+   }

memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb));
scmd->cmnd = adapter->int_cdb;
-- 
1.7.1

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


Re: [PATCH] scsi: megaraid: check kzalloc

2013-05-24 Thread Libo Chen
On 2013/5/24 11:20, Santosh Y wrote:
> On Fri, May 24, 2013 at 7:52 AM, Libo Chen  
> wrote:
>>
>> we should check kzalloc, avoid to hit oops
>>
>> Signed-off-by: Libo Chen 
>> ---
>>  drivers/scsi/megaraid.c |4 
>>  1 files changed, 4 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
>> index 846f475..195b095 100644
>> --- a/drivers/scsi/megaraid.c
>> +++ b/drivers/scsi/megaraid.c
>> @@ -4162,6 +4162,10 @@ mega_internal_command(adapter_t *adapter, megacmd_t 
>> *mc, mega_passthru *pthru)
>>
>> sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
>> scmd->device = sdev;
>   ^^
> I guess assigning after the NULL check of 'sdev' is more appropriate.

Ah, there is a little different.  ok, I will update.


Thanks,

Libo

> 
>> +   if (!scmd->device) {
>> +   scsi_free_command(GFP_KERNEL, scmd);
>> +   return -ENOMEM;
>> +   }
>>
>> memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb));
>> scmd->cmnd = adapter->int_cdb;
>> --
>> 1.7.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 
> 


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


[PATCH RESEND] scsi: megaraid: check kzalloc

2013-05-24 Thread Libo Chen

we should check kzalloc, avoid to hit oops

Signed-off-by: Libo Chen 
---
 drivers/scsi/megaraid.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

instead of checking scmd->device, sdev is more appropriate.

diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 846f475..6b623cb 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4161,6 +4161,10 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, 
mega_passthru *pthru)
memset(scb, 0, sizeof(scb_t));

sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
+   if (sdev) {
+   scsi_free_command(GFP_KERNEL, scmd);
+   return -ENOMEM;
+   }
scmd->device = sdev;

memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb));
-- 
1.7.1



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


[PATCH 03/24] drivers/scsi/dmx3191d: Convert to module_pci_driver

2013-05-26 Thread Libo Chen
use module_pci_driver instead of init/exit, make code clean.

Signed-off-by: Libo Chen 
---
 drivers/scsi/dmx3191d.c |   13 +
 1 files changed, 1 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/dmx3191d.c b/drivers/scsi/dmx3191d.c
old mode 100644
new mode 100755
index 4b0dd8c..bb28062
--- a/drivers/scsi/dmx3191d.c
+++ b/drivers/scsi/dmx3191d.c
@@ -153,18 +153,7 @@ static struct pci_driver dmx3191d_pci_driver = {
.remove = dmx3191d_remove_one,
 };
 
-static int __init dmx3191d_init(void)
-{
-   return pci_register_driver(&dmx3191d_pci_driver);
-}
-
-static void __exit dmx3191d_exit(void)
-{
-   pci_unregister_driver(&dmx3191d_pci_driver);
-}
-
-module_init(dmx3191d_init);
-module_exit(dmx3191d_exit);
+module_pci_driver(dmx3191d_pci_driver);
 
 MODULE_AUTHOR("Massimo Piccioni ");
 MODULE_DESCRIPTION("Domex DMX3191D SCSI driver");
-- 
1.7.1


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


[PATCH 04/24] drivers/scsi/initio: Convert to module_pci_driver

2013-05-26 Thread Libo Chen
use module_pci_driver instead of init/exit, make code clean.

Signed-off-by: Libo Chen 
---
 drivers/scsi/initio.c |   13 +
 1 files changed, 1 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
old mode 100644
new mode 100755
index 280d5af..1befc26
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2995,19 +2995,8 @@ static struct pci_driver initio_pci_driver = {
.remove = initio_remove_one,
 };
 
-static int __init initio_init_driver(void)
-{
-   return pci_register_driver(&initio_pci_driver);
-}
-
-static void __exit initio_exit_driver(void)
-{
-   pci_unregister_driver(&initio_pci_driver);
-}
+module_pci_driver(initio_pci_driver);
 
 MODULE_DESCRIPTION("Initio INI-9X00U/UW SCSI device driver");
 MODULE_AUTHOR("Initio Corporation");
 MODULE_LICENSE("GPL");
-
-module_init(initio_init_driver);
-module_exit(initio_exit_driver);
-- 
1.7.1


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


[PATCH 05/24] drivers/scsi/mvumi: Convert to module_pci_driver

2013-05-26 Thread Libo Chen
use module_pci_driver instead of init/exit, make code clean.

Signed-off-by: Libo Chen 
---
 drivers/scsi/mvumi.c |   20 +---
 1 files changed, 1 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
old mode 100644
new mode 100755
index c3601b5..d0b6a03
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2735,22 +2735,4 @@ static struct pci_driver mvumi_pci_driver = {
 #endif
 };
 
-/**
- * mvumi_init - Driver load entry point
- */
-static int __init mvumi_init(void)
-{
-   return pci_register_driver(&mvumi_pci_driver);
-}
-
-/**
- * mvumi_exit - Driver unload entry point
- */
-static void __exit mvumi_exit(void)
-{
-
-   pci_unregister_driver(&mvumi_pci_driver);
-}
-
-module_init(mvumi_init);
-module_exit(mvumi_exit);
+module_pci_driver(mvumi_pci_driver);
-- 
1.7.1


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


[PATCH 01/24] drivers/scsi/a100u2w: Convert to module_pci_driver

2013-05-26 Thread Libo Chen
use module_pci_driver instead of init/exit, make code clean.
---
 drivers/scsi/a100u2w.c |   12 +---
 1 files changed, 1 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
old mode 100644
new mode 100755
index 0163457..db3710f
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -1227,19 +1227,9 @@ static struct pci_driver inia100_pci_driver = {
.remove = inia100_remove_one,
 };
 
-static int __init inia100_init(void)
-{
-   return pci_register_driver(&inia100_pci_driver);
-}
-
-static void __exit inia100_exit(void)
-{
-   pci_unregister_driver(&inia100_pci_driver);
-}
+module_pci_driver(inia100_pci_driver);
 
 MODULE_DESCRIPTION("Initio A100U2W SCSI driver");
 MODULE_AUTHOR("Initio Corporation");
 MODULE_LICENSE("Dual BSD/GPL");
 
-module_init(inia100_init);
-module_exit(inia100_exit);
-- 
1.7.1


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


[PATCH 02/24] drivers/scsi/dc395x: Convert to module_pci_driver

2013-05-26 Thread Libo Chen
use module_pci_driver instead of init/exit, make code clean.

Signed-off-by: Libo Chen 
---
 drivers/scsi/dc395x.c |   24 +---
 1 files changed, 1 insertions(+), 23 deletions(-)

diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
old mode 100644
new mode 100755
index 694e13c..e73445b
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -4882,29 +4882,7 @@ static struct pci_driver dc395x_driver = {
.remove = dc395x_remove_one,
 };
 
-
-/**
- * dc395x_module_init - Module initialization function
- *
- * Used by both module and built-in driver to initialise this driver.
- **/
-static int __init dc395x_module_init(void)
-{
-   return pci_register_driver(&dc395x_driver);
-}
-
-
-/**
- * dc395x_module_exit - Module cleanup function.
- **/
-static void __exit dc395x_module_exit(void)
-{
-   pci_unregister_driver(&dc395x_driver);
-}
-
-
-module_init(dc395x_module_init);
-module_exit(dc395x_module_exit);
+module_pci_driver(dc395x_driver);
 
 MODULE_AUTHOR("C.L. Huang / Erich Chen / Kurt Garloff");
 MODULE_DESCRIPTION("SCSI host adapter driver for Tekram TRM-S1040 based 
adapters: Tekram DC395 and DC315 series");
-- 
1.7.1


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


[PATCH RESEND 01/24] drivers/scsi/a100u2w: Convert to module_pci_driver

2013-05-26 Thread Libo Chen

use module_pci_driver instead of init/exit, make code clean.

Signed-off-by: Libo Chen 
---
 drivers/scsi/a100u2w.c |   12 +---
 1 files changed, 1 insertions(+), 11 deletions(-)

* add "Signed-off-by: Libo Chen "

diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
old mode 100644
new mode 100755
index 0163457..db3710f
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -1227,19 +1227,9 @@ static struct pci_driver inia100_pci_driver = {
.remove = inia100_remove_one,
 };

-static int __init inia100_init(void)
-{
-   return pci_register_driver(&inia100_pci_driver);
-}
-
-static void __exit inia100_exit(void)
-{
-   pci_unregister_driver(&inia100_pci_driver);
-}
+module_pci_driver(inia100_pci_driver);

 MODULE_DESCRIPTION("Initio A100U2W SCSI driver");
 MODULE_AUTHOR("Initio Corporation");
 MODULE_LICENSE("Dual BSD/GPL");

-module_init(inia100_init);
-module_exit(inia100_exit);
-- 
1.7.1


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


Re: [PATCH 04/24] drivers/scsi/initio: Convert to module_pci_driver

2013-05-27 Thread Libo Chen
On 2013/5/27 14:38, James Bottomley wrote:
> On Mon, 2013-05-27 at 10:28 +0800, Libo Chen wrote:
>> use module_pci_driver instead of init/exit, make code clean.
> 
> For the ancient drivers, like this, the principal is that we really
> don't touch except for tested bug fixes.  For the current ones (like
> mvumi) it's up to the maintainer.
> 
> James
Hi james,

Thank you for your explanation!


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


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


Re: [PATCH RESEND] scsi: megaraid: check kzalloc

2013-05-29 Thread Libo Chen
On 2013/5/29 23:03, Tomas Henzl wrote:
> On 05/24/2013 11:40 AM, Libo Chen wrote:
>> we should check kzalloc, avoid to hit oops
>>
>> Signed-off-by: Libo Chen 
>> ---
>>  drivers/scsi/megaraid.c |4 
>>  1 files changed, 4 insertions(+), 0 deletions(-)
>>
>> instead of checking scmd->device, sdev is more appropriate.
>>
>> diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
>> index 846f475..6b623cb 100644
>> --- a/drivers/scsi/megaraid.c
>> +++ b/drivers/scsi/megaraid.c
>> @@ -4161,6 +4161,10 @@ mega_internal_command(adapter_t *adapter, megacmd_t 
>> *mc, mega_passthru *pthru)
>>  memset(scb, 0, sizeof(scb_t));
>>
>>  sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
>> +if (sdev) {
>> +scsi_free_command(GFP_KERNEL, scmd);
> 
> I think, that a mutex_unlock(&adapter->int_mtx); is also needed
> Maybe just setting a rval = -ENOMEM and a jump to to some point below?
> 
> tomash

thanks for catching this.

when kzalloc broken, fist unlock and then return.  I will update later.


Libo

> 
>> +return -ENOMEM;
>> +}
>>  scmd->device = sdev;
>>
>>  memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb));
> 
> 
> .
> 


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


Re: [PATCH RESEND] scsi: megaraid: check kzalloc

2013-05-29 Thread Libo Chen
On 2013/5/30 9:38, Libo Chen wrote:
> On 2013/5/29 23:03, Tomas Henzl wrote:
>> On 05/24/2013 11:40 AM, Libo Chen wrote:
>>> we should check kzalloc, avoid to hit oops
>>>
>>> Signed-off-by: Libo Chen 
>>> ---
>>>  drivers/scsi/megaraid.c |4 
>>>  1 files changed, 4 insertions(+), 0 deletions(-)
>>>
>>> instead of checking scmd->device, sdev is more appropriate.
>>>
>>> diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
>>> index 846f475..6b623cb 100644
>>> --- a/drivers/scsi/megaraid.c
>>> +++ b/drivers/scsi/megaraid.c
>>> @@ -4161,6 +4161,10 @@ mega_internal_command(adapter_t *adapter, megacmd_t 
>>> *mc, mega_passthru *pthru)
>>> memset(scb, 0, sizeof(scb_t));
>>>
>>> sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
>>> +   if (sdev) {
>>> +   scsi_free_command(GFP_KERNEL, scmd);
>>
>> I think, that a mutex_unlock(&adapter->int_mtx); is also needed
>> Maybe just setting a rval = -ENOMEM and a jump to to some point below?
>>
>> tomash
> 
> thanks for catching this.
> 
> when kzalloc broken, fist unlock and then return.  I will update later.
> 

I think we can put kzalloc outside of mutex_lock(&adapter->int_mtx) ?
phase:

   mutex_lock  kzalloc
   kzalloc ->  mutex_lock


> 
> Libo
> 
>>
>>> +   return -ENOMEM;
>>> +   }
>>> scmd->device = sdev;
>>>
>>> memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb));
>>
>>
>> .
>>
> 


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


Re: [PATCH] scsi: Introduce a help function local_time_seconds() to simplify the getting time stamp operation

2013-05-29 Thread Libo Chen
On 2013/5/29 17:33, Gu Zheng wrote:
>>From 4d4caa16f3886ae910ad6dfe13353fc836f546cc Mon Sep 17 00:00:00 2001
> From: Gu Zheng 
> Date: Wed, 29 May 2013 17:34:22 +0900
> Subject: [PATCH] driver/scsi: Introduce a help function local_time_seconds() 
> to simplify the getting time stamp operation
> 
hi gu,

next time, you can remove above info.


thanks,

Libo


> Signed-off-by: Gu Zheng 
> ---
>  drivers/scsi/3w-9xxx.c |   14 ++
>  drivers/scsi/3w-sas.c  |   14 ++
>  include/scsi/scsi.h|9 +
>  3 files changed, 13 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
> index 5e1e12c..44b3ea8 100644
> --- a/drivers/scsi/3w-9xxx.c
> +++ b/drivers/scsi/3w-9xxx.c
> @@ -374,8 +374,6 @@ out:
>  /* This function will queue an event */
>  static void twa_aen_queue_event(TW_Device_Extension *tw_dev, 
> TW_Command_Apache_Header *header)
>  {
> - u32 local_time;
> - struct timeval time;
>   TW_Event *event;
>   unsigned short aen;
>   char host[16];
> @@ -398,9 +396,7 @@ static void twa_aen_queue_event(TW_Device_Extension 
> *tw_dev, TW_Command_Apache_H
>   memset(event, 0, sizeof(TW_Event));
>  
>   event->severity = TW_SEV_OUT(header->status_block.severity__reserved);
> - do_gettimeofday(&time);
> - local_time = (u32)(time.tv_sec - (sys_tz.tz_minuteswest * 60));
> - event->time_stamp_sec = local_time;
> + event->time_stamp_sec = local_time_seconds();
>   event->aen_code = aen;
>   event->retrieved = TW_AEN_NOT_RETRIEVED;
>   event->sequence_id = tw_dev->error_sequence_id;
> @@ -479,11 +475,9 @@ out:
>  static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id)
>  {
>   u32 schedulertime;
> - struct timeval utc;
>   TW_Command_Full *full_command_packet;
>   TW_Command *command_packet;
>   TW_Param_Apache *param;
> - u32 local_time;
>  
>   /* Fill out the command packet */
>   full_command_packet = tw_dev->command_packet_virt[request_id];
> @@ -503,11 +497,7 @@ static void twa_aen_sync_time(TW_Device_Extension 
> *tw_dev, int request_id)
>   param->parameter_id = cpu_to_le16(0x3); /* SchedulerTime */
>   param->parameter_size_bytes = cpu_to_le16(4);
>  
> - /* Convert system time in UTC to local time seconds since last 
> -   Sunday 12:00AM */
> - do_gettimeofday(&utc);
> - local_time = (u32)(utc.tv_sec - (sys_tz.tz_minuteswest * 60));
> - schedulertime = local_time - (3 * 86400);
> + schedulertime = local_time_seconds() - (3 * 86400);
>   schedulertime = cpu_to_le32(schedulertime % 604800);
>  
>   memcpy(param->data, &schedulertime, sizeof(u32));
> diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
> index c845bdb..69f1d8a 100644
> --- a/drivers/scsi/3w-sas.c
> +++ b/drivers/scsi/3w-sas.c
> @@ -236,8 +236,6 @@ out:
>  /* This function will queue an event */
>  static void twl_aen_queue_event(TW_Device_Extension *tw_dev, 
> TW_Command_Apache_Header *header)
>  {
> - u32 local_time;
> - struct timeval time;
>   TW_Event *event;
>   unsigned short aen;
>   char host[16];
> @@ -256,9 +254,7 @@ static void twl_aen_queue_event(TW_Device_Extension 
> *tw_dev, TW_Command_Apache_H
>   memset(event, 0, sizeof(TW_Event));
>  
>   event->severity = TW_SEV_OUT(header->status_block.severity__reserved);
> - do_gettimeofday(&time);
> - local_time = (u32)(time.tv_sec - (sys_tz.tz_minuteswest * 60));
> - event->time_stamp_sec = local_time;
> + event->time_stamp_sec = local_time_seconds();
>   event->aen_code = aen;
>   event->retrieved = TW_AEN_NOT_RETRIEVED;
>   event->sequence_id = tw_dev->error_sequence_id;
> @@ -444,11 +440,9 @@ out:
>  static void twl_aen_sync_time(TW_Device_Extension *tw_dev, int request_id)
>  {
>   u32 schedulertime;
> - struct timeval utc;
>   TW_Command_Full *full_command_packet;
>   TW_Command *command_packet;
>   TW_Param_Apache *param;
> - u32 local_time;
>  
>   /* Fill out the command packet */
>   full_command_packet = tw_dev->command_packet_virt[request_id];
> @@ -468,11 +462,7 @@ static void twl_aen_sync_time(TW_Device_Extension 
> *tw_dev, int request_id)
>   param->parameter_id = cpu_to_le16(0x3); /* SchedulerTime */
>   param->parameter_size_bytes = cpu_to_le16(4);
>  
> - /* Convert system time in UTC to local time seconds since last 
> -   Sunday 12:00AM */
> - do_gettimeofday(&utc);
> - local_time = (u32)(utc.tv_sec - (sys_tz.tz_minuteswest * 60));
> - schedulertime = local_time - (3 * 86400);
> + schedulertime = local_time_seconds() - (3 * 86400);
>   schedulertime = cpu_to_le32(schedulertime % 604800);
>  
>   memcpy(param->data, &schedulertime, sizeof(u32));
> diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
> index 66216c1..f3377ca 100644
> --- a/include/scsi/scsi.h
> +++ b/include/scsi/scsi.h
> @@ -574,4 +574,13 @@ stati

Re: [PATCH v2] scsi: megaraid: check kzalloc

2013-06-04 Thread Libo Chen

we should check kzalloc, avoid to hit oops

Change from v1:
- put kzalloc outside of mutex

Signed-off-by: Libo Chen 
---
 drivers/scsi/megaraid.c |7 ++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 846f475..cc599cc 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4150,6 +4150,12 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, 
mega_passthru *pthru)
if (!scmd)
return -ENOMEM;

+   sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
+   if (!sdev) {
+   scsi_free_command(GFP_KERNEL, scmd);
+   return -ENOMEM;
+   }
+
/*
 * The internal commands share one command id and hence are
 * serialized. This is so because we want to reserve maximum number of
@@ -4160,7 +4166,6 @@ mega_internal_command(adapter_t *adapter, megacmd_t *mc, 
mega_passthru *pthru)
scb = &adapter->int_scb;
memset(scb, 0, sizeof(scb_t));

-   sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
scmd->device = sdev;

memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb));
-- 
1.7.1


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


Re: [PATCH v2] scsi: megaraid: check kzalloc

2013-06-04 Thread Libo Chen
On 2013/6/4 20:14, Tomas Henzl wrote:
> On 06/04/2013 11:33 AM, Libo Chen wrote:
>> we should check kzalloc, avoid to hit oops
>>
>> Change from v1:
>> - put kzalloc outside of mutex
>>
>> Signed-off-by: Libo Chen 
> 
> Your patch looks fine to me:
> Acked-by: Tomas Henzl 
> 

your ack is very helpfull for me.

Thanks,

Libo

> Cheers,
> Tomas
> 
> 
> .
> 


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


Re: [PATCH v2] scsi: Add 'retry_timeout' to avoid infinite command retry

2014-02-06 Thread Libo Chen
On 2014/2/7 13:46, James Bottomley wrote:
> On Fri, 2014-02-07 at 09:22 +0900, Eiichi Tsukata wrote:
>> Currently, scsi error handling in scsi_io_completion() tries to
>> unconditionally requeue scsi command when device keeps some error state.
>> For example, UNIT_ATTENTION causes infinite retry with
>> action == ACTION_RETRY.
>> This is because retryable errors are thought to be temporary and the scsi
>> device will soon recover from those errors. Normally, such retry policy is
>> appropriate because the device will soon recover from temporary error state.
> 
> 
> 
>> But there is no guarantee that device is able to recover from error state
>> immediately. Actually, we've experienced an infinite retry on some hardware.
>> Therefore hardware error can results in infinite command retry loop.
> 
> Could you please add an analysis of the actual failure; which devices
> and what conditions.
> 


same question, can you explain?

>> This patch adds 'retry_timeout' sysfs attribute which limits the retry time
>> of each scsi command. This attribute is located in scsi sysfs directory
>> for example "/sys/bus/scsi/devices/X:X:X:X/" and value is in seconds.
>> Once scsi command retry time is longer than this timeout,
>> the command is treated as failure. 'retry_timeout' is set to '0' by default
>> which means no timeout set.
> 
> Don't do this ... you're mixing a feature (which you'd need to justify)
> with an apparent bug fix.
> 
> Once you dump all the complexity, I think the patch boils down to a
> simple check before the action switch in scsi_io_completion():
> 
>   if (action !=  ACTION_FAIL &&
>   time_before(cmd->jiffies_at_alloc + wait_for, jiffies)) {
>   action = ACTION_FAIL;
>   description = "command timed out";
>   }
> 
> 
> James
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 
> 


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