Re: [PATCH 3/3] megaraid_sas: return -ENOMEM when create DMA pool for cmd frames failed
From: Johannes Thumshirn
Date: Tue Oct 27 2015 - 06:17:14 EST
On Tue, 2015-10-27 at 16:26 +0800, Weidong Wang wrote:
> when create DMA pool for cmd frames failed, we should return -ENOMEM,
> instead of 0.
> In some case in:
>
> ÂÂÂÂmegasas_init_adapter_fusion()
>
> ÂÂÂÂ-->megasas_alloc_cmds()
> ÂÂÂÂÂÂÂ-->megasas_create_frame_pool
> ÂÂÂÂÂÂÂÂÂÂcreate DMA pool failed,
> ÂÂÂÂÂÂÂÂ--> megasas_free_cmds() [1]
>
> ÂÂÂÂ-->megasas_alloc_cmds_fusion()
> ÂÂÂÂÂÂÂfailed, then goto fail_alloc_cmds.
> ÂÂÂÂ-->megasas_free_cmds() [2]
>
> we will call megasas_free_cmds twice, [1] will kfree cmd_list,
> [2] will use cmd_list.it will cause a problem:
>
> Unable to handle kernel NULL pointer dereference at virtual address
> 00000000
> pgd = ffffffc000f70000
> [00000000] *pgd=0000001fbf893003, *pud=0000001fbf893003,
> *pmd=0000001fbf894003, *pte=006000006d000707
> Internal error: Oops: 96000005 [#1] SMP
> ÂModules linked in:
> ÂCPU: 18 PID: 1 Comm: swapper/0 Not tainted
> Âtask: ffffffdfb9290000 ti: ffffffdfb923c000 task.ti:
> ffffffdfb923c000
> ÂPC is at megasas_free_cmds+0x30/0x70
> ÂLR is at megasas_free_cmds+0x24/0x70
>
> Â...
>
> ÂCall trace:
> Â[<ffffffc0005b779c>] megasas_free_cmds+0x30/0x70
> Â[<ffffffc0005bca74>] megasas_init_adapter_fusion+0x2f4/0x4d8
> Â[<ffffffc0005b926c>] megasas_init_fw+0x2dc/0x760
> Â[<ffffffc0005b9ab0>] megasas_probe_one+0x3c0/0xcd8
> Â[<ffffffc0004a5abc>] local_pci_probe+0x4c/0xb4
> Â[<ffffffc0004a5c40>] pci_device_probe+0x11c/0x14c
> Â[<ffffffc00053a5e4>] driver_probe_device+0x1ec/0x430
> Â[<ffffffc00053a92c>] __driver_attach+0xa8/0xb0
> Â[<ffffffc000538178>] bus_for_each_dev+0x74/0xc8
> Â [<ffffffc000539e88>] driver_attach+0x28/0x34
> Â[<ffffffc000539a18>] bus_add_driver+0x16c/0x248
> Â[<ffffffc00053b234>] driver_register+0x6c/0x138
> Â[<ffffffc0004a5350>] __pci_register_driver+0x5c/0x6c
> Â[<ffffffc000ce3868>] megasas_init+0xc0/0x1a8
> Â[<ffffffc000082a58>] do_one_initcall+0xe8/0x1ec
> Â[<ffffffc000ca7be8>] kernel_init_freeable+0x1c8/0x284
> Â[<ffffffc0008d90b8>] kernel_init+0x1c/0xe4
>
> Signed-off-by: Weidong Wang <wangweidong1@xxxxxxxxxx>
> ---
> Âdrivers/scsi/megaraid/megaraid_sas_base.c | 3 ++-
> Â1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c
> b/drivers/scsi/megaraid/megaraid_sas_base.c
> index 2287aa1..8215218 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -3746,8 +3746,9 @@ int megasas_alloc_cmds(struct megasas_instance
> *instance)
> Â Â* Create a frame pool and assign one frame to each cmd
> Â Â*/
> Â if (megasas_create_frame_pool(instance)) {
> - dev_dbg(&instance->pdev->dev, "Error creating frame
> DMA pool\n");
> + dev_err(&instance->pdev->dev, "Error creating frame
> DMA pool\n");
> Â megasas_free_cmds(instance);
> + return -ENOMEM;
> Â }
> Â
> Â return 0;
I think this is needed for stable as well.
Other than that,
Reviewed-by: Johannes Thumshirn <jthumshirn@xxxxxxx>
Thanks,
Johannes
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/