* [PATCH 1/1] scsi: mvsas:fix memory leak
@ 2018-04-04 2:15 Xidong Wang
2018-04-04 10:53 ` kbuild test robot
2018-04-04 11:39 ` kbuild test robot
0 siblings, 2 replies; 4+ messages in thread
From: Xidong Wang @ 2018-04-04 2:15 UTC (permalink / raw)
To: James E . J . Bottomley, Martin K . Petersen, Jack Wang,
Johannes Thumshirn, Peter Senna Tschudin, Hannes Reinecke
Cc: Kees Cook, Pan Bian, Xidong Wang, Romain Perier, linux-scsi,
linux-kernel
In function mvs_pci_init(), the memory allocated by
scsi_host_alloc() is not released on the error path that mvi,
which holds the return value of mvs_pci_alloc(), is NULL.
This will result in a memory leak bug.
Signed-off-by: Xidong Wang <wangxidong_97@163.com>
---
drivers/scsi/mvsas/mv_init.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index 8c91637..bde4b50 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -371,6 +371,7 @@ static struct mvs_info *mvs_pci_alloc(struct pci_dev *pdev,
(1L << mvs_chips[ent->driver_data].slot_width) *
sizeof(struct mvs_slot_info), GFP_KERNEL);
if (!mvi)
+ scsi_host_put(shost);
return NULL;
mvi->pdev = pdev;
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] scsi: mvsas:fix memory leak
2018-04-04 2:15 [PATCH 1/1] scsi: mvsas:fix memory leak Xidong Wang
@ 2018-04-04 10:53 ` kbuild test robot
2018-04-04 11:39 ` kbuild test robot
1 sibling, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2018-04-04 10:53 UTC (permalink / raw)
To: Xidong Wang
Cc: kbuild-all, James E . J . Bottomley, Martin K . Petersen,
Jack Wang, Johannes Thumshirn, Peter Senna Tschudin,
Hannes Reinecke, Kees Cook, Pan Bian, Xidong Wang, Romain Perier,
linux-scsi, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 4806 bytes --]
Hi Xidong,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on v4.16 next-20180403]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Xidong-Wang/scsi-mvsas-fix-memory-leak/20180404-182132
base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: i386-randconfig-x016-201813 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All warnings (new ones prefixed by >>):
In file included from include/linux/kernel.h:10:0,
from drivers/scsi/mvsas/mv_sas.h:29,
from drivers/scsi/mvsas/mv_init.c:27:
drivers/scsi/mvsas/mv_init.c: In function 'mvs_pci_alloc':
include/linux/compiler.h:58:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
^
include/linux/compiler.h:56:23: note: in expansion of macro '__trace_if'
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
^~~~~~~~~~
>> drivers/scsi/mvsas/mv_init.c:373:2: note: in expansion of macro 'if'
if (!mvi)
^~
drivers/scsi/mvsas/mv_init.c:375:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
return NULL;
^~~~~~
vim +/if +373 drivers/scsi/mvsas/mv_init.c
20b09c29 Andy Yan 2009-05-08 362
6f039790 Greg Kroah-Hartman 2012-12-21 363 static struct mvs_info *mvs_pci_alloc(struct pci_dev *pdev,
20b09c29 Andy Yan 2009-05-08 364 const struct pci_device_id *ent,
20b09c29 Andy Yan 2009-05-08 365 struct Scsi_Host *shost, unsigned int id)
20b09c29 Andy Yan 2009-05-08 366 {
84fbd0ce Xiangliang Yu 2011-05-24 367 struct mvs_info *mvi = NULL;
20b09c29 Andy Yan 2009-05-08 368 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
20b09c29 Andy Yan 2009-05-08 369
b89e8f53 Xiangliang Yu 2011-05-24 370 mvi = kzalloc(sizeof(*mvi) +
b89e8f53 Xiangliang Yu 2011-05-24 371 (1L << mvs_chips[ent->driver_data].slot_width) *
b89e8f53 Xiangliang Yu 2011-05-24 372 sizeof(struct mvs_slot_info), GFP_KERNEL);
20b09c29 Andy Yan 2009-05-08 @373 if (!mvi)
549079d1 Xidong Wang 2018-04-04 374 scsi_host_put(shost);
20b09c29 Andy Yan 2009-05-08 375 return NULL;
dd4969a8 Jeff Garzik 2009-05-08 376
20b09c29 Andy Yan 2009-05-08 377 mvi->pdev = pdev;
20b09c29 Andy Yan 2009-05-08 378 mvi->dev = &pdev->dev;
20b09c29 Andy Yan 2009-05-08 379 mvi->chip_id = ent->driver_data;
20b09c29 Andy Yan 2009-05-08 380 mvi->chip = &mvs_chips[mvi->chip_id];
20b09c29 Andy Yan 2009-05-08 381 INIT_LIST_HEAD(&mvi->wq_list);
20b09c29 Andy Yan 2009-05-08 382
20b09c29 Andy Yan 2009-05-08 383 ((struct mvs_prv_info *)sha->lldd_ha)->mvi[id] = mvi;
20b09c29 Andy Yan 2009-05-08 384 ((struct mvs_prv_info *)sha->lldd_ha)->n_phy = mvi->chip->n_phy;
20b09c29 Andy Yan 2009-05-08 385
20b09c29 Andy Yan 2009-05-08 386 mvi->id = id;
20b09c29 Andy Yan 2009-05-08 387 mvi->sas = sha;
20b09c29 Andy Yan 2009-05-08 388 mvi->shost = shost;
20b09c29 Andy Yan 2009-05-08 389
b89e8f53 Xiangliang Yu 2011-05-24 390 mvi->tags = kzalloc(MVS_CHIP_SLOT_SZ>>3, GFP_KERNEL);
b89e8f53 Xiangliang Yu 2011-05-24 391 if (!mvi->tags)
b89e8f53 Xiangliang Yu 2011-05-24 392 goto err_out;
b89e8f53 Xiangliang Yu 2011-05-24 393
20b09c29 Andy Yan 2009-05-08 394 if (MVS_CHIP_DISP->chip_ioremap(mvi))
20b09c29 Andy Yan 2009-05-08 395 goto err_out;
20b09c29 Andy Yan 2009-05-08 396 if (!mvs_alloc(mvi, shost))
20b09c29 Andy Yan 2009-05-08 397 return mvi;
dd4969a8 Jeff Garzik 2009-05-08 398 err_out:
dd4969a8 Jeff Garzik 2009-05-08 399 mvs_free(mvi);
dd4969a8 Jeff Garzik 2009-05-08 400 return NULL;
dd4969a8 Jeff Garzik 2009-05-08 401 }
dd4969a8 Jeff Garzik 2009-05-08 402
:::::: The code at line 373 was first introduced by commit
:::::: 20b09c2992fefbe78f8cede7b404fb143a413c52 [SCSI] mvsas: add support for 94xx; layout change; bug fixes
:::::: TO: Andy Yan <ayan@marvell.com>
:::::: CC: James Bottomley <James.Bottomley@HansenPartnership.com>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 27858 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/1] scsi: mvsas:fix memory leak
2018-04-04 2:15 [PATCH 1/1] scsi: mvsas:fix memory leak Xidong Wang
2018-04-04 10:53 ` kbuild test robot
@ 2018-04-04 11:39 ` kbuild test robot
1 sibling, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2018-04-04 11:39 UTC (permalink / raw)
To: Xidong Wang
Cc: kbuild-all, James E . J . Bottomley, Martin K . Petersen,
Jack Wang, Johannes Thumshirn, Peter Senna Tschudin,
Hannes Reinecke, Kees Cook, Pan Bian, Xidong Wang, Romain Perier,
linux-scsi, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 7974 bytes --]
Hi Xidong,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on v4.16 next-20180403]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Xidong-Wang/scsi-mvsas-fix-memory-leak/20180404-182132
base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: x86_64-randconfig-x010-201813 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64
All warnings (new ones prefixed by >>):
drivers/scsi//mvsas/mv_init.c: In function 'mvs_pci_alloc':
>> drivers/scsi//mvsas/mv_init.c:373:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (!mvi)
^~
drivers/scsi//mvsas/mv_init.c:375:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
return NULL;
^~~~~~
Cyclomatic Complexity 1 arch/x86/include/asm/bitops.h:test_and_set_bit
Cyclomatic Complexity 1 arch/x86/include/asm/bitops.h:fls64
Cyclomatic Complexity 1 include/linux/log2.h:__ilog2_u64
Cyclomatic Complexity 1 include/linux/mem_encrypt.h:sme_get_me_mask
Cyclomatic Complexity 1 include/asm-generic/getorder.h:__get_order
Cyclomatic Complexity 1 arch/x86/include/asm/paravirt.h:arch_local_save_flags
Cyclomatic Complexity 1 arch/x86/include/asm/irqflags.h:arch_irqs_disabled_flags
Cyclomatic Complexity 1 include/linux/device.h:dev_get_drvdata
Cyclomatic Complexity 1 include/linux/device.h:dev_set_drvdata
Cyclomatic Complexity 1 include/linux/dma-debug.h:debug_dma_free_coherent
Cyclomatic Complexity 1 arch/x86/include/asm/dma-mapping.h:get_arch_dma_ops
Cyclomatic Complexity 4 include/linux/dma-mapping.h:get_dma_ops
Cyclomatic Complexity 1 include/linux/kasan.h:kasan_kmalloc
Cyclomatic Complexity 28 include/linux/slab.h:kmalloc_index
Cyclomatic Complexity 1 include/linux/slab.h:kmem_cache_alloc_trace
Cyclomatic Complexity 1 include/linux/slab.h:kmalloc_order_trace
Cyclomatic Complexity 68 include/linux/slab.h:kmalloc_large
Cyclomatic Complexity 5 include/linux/slab.h:kmalloc
Cyclomatic Complexity 1 include/linux/slab.h:kzalloc
Cyclomatic Complexity 1 include/linux/pci.h:pci_get_drvdata
Cyclomatic Complexity 1 include/linux/pci.h:pci_set_drvdata
Cyclomatic Complexity 5 drivers/scsi//mvsas/mv_init.c:mvs_post_sas_ha_init
Cyclomatic Complexity 8 drivers/scsi//mvsas/mv_init.c:mvs_store_interrupt_coalescing
Cyclomatic Complexity 1 drivers/scsi//mvsas/mv_init.c:mvs_show_interrupt_coalescing
Cyclomatic Complexity 1 drivers/scsi//mvsas/mv_init.c:mvs_show_driver_version
Cyclomatic Complexity 1 arch/x86/include/asm/io.h:ioremap
Cyclomatic Complexity 1 drivers/scsi//mvsas/mv_init.c:mvs_exit
Cyclomatic Complexity 2 drivers/scsi//mvsas/mv_init.c:mvs_pci_alloc
Cyclomatic Complexity 4 include/linux/dma-mapping.h:dma_free_attrs
Cyclomatic Complexity 1 include/linux/dma-mapping.h:dma_free_coherent
Cyclomatic Complexity 13 drivers/scsi//mvsas/mv_init.c:mvs_free
Cyclomatic Complexity 2 drivers/scsi//mvsas/mv_init.c:mvs_pci_remove
Cyclomatic Complexity 3 drivers/scsi//mvsas/mv_init.c:mvs_tasklet
Cyclomatic Complexity 2 include/linux/interrupt.h:tasklet_schedule
Cyclomatic Complexity 3 drivers/scsi//mvsas/mv_init.c:mvs_interrupt
Cyclomatic Complexity 4 include/linux/dma-mapping.h:dma_supported
Cyclomatic Complexity 3 include/linux/dma-mapping.h:dma_check_mask
Cyclomatic Complexity 3 include/linux/dma-mapping.h:dma_set_mask
Cyclomatic Complexity 1 include/linux/pci-dma-compat.h:pci_set_dma_mask
Cyclomatic Complexity 2 include/linux/dma-mapping.h:dma_set_coherent_mask
Cyclomatic Complexity 1 include/linux/pci-dma-compat.h:pci_set_consistent_dma_mask
Cyclomatic Complexity 6 drivers/scsi//mvsas/mv_init.c:pci_go_64
Cyclomatic Complexity 5 include/linux/slab.h:kmalloc_array
Cyclomatic Complexity 1 include/linux/slab.h:kcalloc
Cyclomatic Complexity 3 drivers/scsi//mvsas/mv_init.c:mvs_prep_sas_ha_init
Cyclomatic Complexity 2 drivers/scsi//mvsas/mv_init.c:mvs_init_sas_add
Cyclomatic Complexity 1 include/scsi/scsi_host.h:scsi_add_host
Cyclomatic Complexity 1 include/linux/interrupt.h:request_irq
Cyclomatic Complexity 13 drivers/scsi//mvsas/mv_init.c:mvs_pci_init
Cyclomatic Complexity 3 drivers/scsi//mvsas/mv_init.c:mvs_init
Cyclomatic Complexity 13 drivers/scsi//mvsas/mv_init.c:mvs_ioremap
Cyclomatic Complexity 1 drivers/scsi//mvsas/mv_init.c:mvs_iounmap
vim +/if +373 drivers/scsi//mvsas/mv_init.c
20b09c29 Andy Yan 2009-05-08 362
6f039790 Greg Kroah-Hartman 2012-12-21 363 static struct mvs_info *mvs_pci_alloc(struct pci_dev *pdev,
20b09c29 Andy Yan 2009-05-08 364 const struct pci_device_id *ent,
20b09c29 Andy Yan 2009-05-08 365 struct Scsi_Host *shost, unsigned int id)
20b09c29 Andy Yan 2009-05-08 366 {
84fbd0ce Xiangliang Yu 2011-05-24 367 struct mvs_info *mvi = NULL;
20b09c29 Andy Yan 2009-05-08 368 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
20b09c29 Andy Yan 2009-05-08 369
b89e8f53 Xiangliang Yu 2011-05-24 370 mvi = kzalloc(sizeof(*mvi) +
b89e8f53 Xiangliang Yu 2011-05-24 371 (1L << mvs_chips[ent->driver_data].slot_width) *
b89e8f53 Xiangliang Yu 2011-05-24 372 sizeof(struct mvs_slot_info), GFP_KERNEL);
20b09c29 Andy Yan 2009-05-08 @373 if (!mvi)
549079d1 Xidong Wang 2018-04-04 374 scsi_host_put(shost);
20b09c29 Andy Yan 2009-05-08 375 return NULL;
dd4969a8 Jeff Garzik 2009-05-08 376
20b09c29 Andy Yan 2009-05-08 377 mvi->pdev = pdev;
20b09c29 Andy Yan 2009-05-08 378 mvi->dev = &pdev->dev;
20b09c29 Andy Yan 2009-05-08 379 mvi->chip_id = ent->driver_data;
20b09c29 Andy Yan 2009-05-08 380 mvi->chip = &mvs_chips[mvi->chip_id];
20b09c29 Andy Yan 2009-05-08 381 INIT_LIST_HEAD(&mvi->wq_list);
20b09c29 Andy Yan 2009-05-08 382
20b09c29 Andy Yan 2009-05-08 383 ((struct mvs_prv_info *)sha->lldd_ha)->mvi[id] = mvi;
20b09c29 Andy Yan 2009-05-08 384 ((struct mvs_prv_info *)sha->lldd_ha)->n_phy = mvi->chip->n_phy;
20b09c29 Andy Yan 2009-05-08 385
20b09c29 Andy Yan 2009-05-08 386 mvi->id = id;
20b09c29 Andy Yan 2009-05-08 387 mvi->sas = sha;
20b09c29 Andy Yan 2009-05-08 388 mvi->shost = shost;
20b09c29 Andy Yan 2009-05-08 389
b89e8f53 Xiangliang Yu 2011-05-24 390 mvi->tags = kzalloc(MVS_CHIP_SLOT_SZ>>3, GFP_KERNEL);
b89e8f53 Xiangliang Yu 2011-05-24 391 if (!mvi->tags)
b89e8f53 Xiangliang Yu 2011-05-24 392 goto err_out;
b89e8f53 Xiangliang Yu 2011-05-24 393
20b09c29 Andy Yan 2009-05-08 394 if (MVS_CHIP_DISP->chip_ioremap(mvi))
20b09c29 Andy Yan 2009-05-08 395 goto err_out;
20b09c29 Andy Yan 2009-05-08 396 if (!mvs_alloc(mvi, shost))
20b09c29 Andy Yan 2009-05-08 397 return mvi;
dd4969a8 Jeff Garzik 2009-05-08 398 err_out:
dd4969a8 Jeff Garzik 2009-05-08 399 mvs_free(mvi);
dd4969a8 Jeff Garzik 2009-05-08 400 return NULL;
dd4969a8 Jeff Garzik 2009-05-08 401 }
dd4969a8 Jeff Garzik 2009-05-08 402
:::::: The code at line 373 was first introduced by commit
:::::: 20b09c2992fefbe78f8cede7b404fb143a413c52 [SCSI] mvsas: add support for 94xx; layout change; bug fixes
:::::: TO: Andy Yan <ayan@marvell.com>
:::::: CC: James Bottomley <James.Bottomley@HansenPartnership.com>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32895 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] scsi:mvsas:fix memory leak
@ 2018-04-04 2:37 Xidong Wang
0 siblings, 0 replies; 4+ messages in thread
From: Xidong Wang @ 2018-04-04 2:37 UTC (permalink / raw)
To: James E . J . Bottomley, Martin K . Petersen, Jack Wang,
Johannes Thumshirn, Hannes Reinecke
Cc: Kees Cook, Pan Bian, Xidong Wang, Romain Perier, linux-scsi,
linux-kernel
In function mvs_pci_init(), the memory allocated by
scsi_host_alloc() is not released on the error path that mvi,
which holds the return value of mvs_pci_alloc(), is NULL.
This will result in a memory leak bug.
Signed-off-by: Xidong Wang <wangxidong_97@163.com>
---
drivers/scsi/mvsas/mv_init.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index 8c91637..936b8ef 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -370,8 +370,10 @@ static struct mvs_info *mvs_pci_alloc(struct pci_dev *pdev,
mvi = kzalloc(sizeof(*mvi) +
(1L << mvs_chips[ent->driver_data].slot_width) *
sizeof(struct mvs_slot_info), GFP_KERNEL);
- if (!mvi)
+ if (!mvi) {
+ scsi_host_put(shost);
return NULL;
+ }
mvi->pdev = pdev;
mvi->dev = &pdev->dev;
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-04-04 11:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-04 2:15 [PATCH 1/1] scsi: mvsas:fix memory leak Xidong Wang
2018-04-04 10:53 ` kbuild test robot
2018-04-04 11:39 ` kbuild test robot
2018-04-04 2:37 [PATCH 1/1] scsi:mvsas:fix " Xidong Wang
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®