Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1556909
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 07/18] mtd-cfi_cmdset_0001: One function call and an unnecessary check less in cfi_intelext_setup() |
| Date | 2017-01-11 21:50 +0100 |
| Message-ID | <sYy0h-37v-9@gated-at.bofh.it> (permalink) |
| References | <sYxQC-34a-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 11 Jan 2017 17:27:53 +0100
The kfree() function was called in one case by the cfi_intelext_setup()
function during error handling even if the passed data structure member
contained a null pointer.
* Adjust a jump target according to the Linux coding style convention
so that memory will be also released for members of a data structure
before the container "mtd" in the error handling case.
* Delete a check which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/mtd/chips/cfi_cmdset_0001.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index d7d3d398e4d4..7f6ed7293e40 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -601,7 +601,7 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
sizeof(*mtd->eraseregions),
GFP_KERNEL);
if (!mtd->eraseregions)
- goto setup_err;
+ goto free_priv;
for (i = 0; i < cfi->cfiq->NumEraseRegions; i++) {
unsigned long ernum, ersize;
@@ -657,16 +657,14 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
return mtd;
setup_err:
- if (mtd->eraseregions)
- for (i = 0; i < cfi->cfiq->NumEraseRegions; i++)
- for (j = 0; j < cfi->numchips; j++)
- kfree(mtd->eraseregions[j
- * cfi->cfiq
- ->NumEraseRegions
- + i].lockmap);
+ for (i = 0; i < cfi->cfiq->NumEraseRegions; i++)
+ for (j = 0; j < cfi->numchips; j++)
+ kfree(mtd->eraseregions[j * cfi->cfiq->NumEraseRegions
+ + i].lockmap);
kfree(mtd->eraseregions);
- kfree(mtd);
+free_priv:
kfree(cfi->cmdset_priv);
+ kfree(mtd);
return NULL;
}
--
2.11.0
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/18] MTD-CFI: Fine-tuning for several function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:40 +0100
[PATCH 03/18] mtd-cfi_cmdset_0001: Add some spaces for better code readability SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
Re: [PATCH 03/18] mtd-cfi_cmdset_0001: Add some spaces for better code readability Dan Carpenter <dan.carpenter@oracle.com> - 2017-01-12 10:30 +0100
[PATCH 04/18] mtd-cfi_cmdset_0001: Delete an unnecessary variable initialisation in do_write_oneword() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 07/18] mtd-cfi_cmdset_0001: One function call and an unnecessary check less in cfi_intelext_setup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 05/18] mtd-cfi_cmdset_0001: Use common error handling code in do_write_oneword() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 09/18] mtd-cfi_cmdset_0002: Use kmalloc_array() in cfi_amdstd_setup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 11/18] mtd-cfi_cmdset_0002: Rename a jump label in cfi_amdstd_setup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 08/18] mtd-cfi_cmdset_0001: Rename a jump label in cfi_intelext_setup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 10/18] mtd-cfi_cmdset_0002: One function call less in cfi_amdstd_setup() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 06/18] mtd-cfi_cmdset_0001: Use kcalloc() in cfi_intelext_setup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:50 +0100
[PATCH 14/18] mtd-cfi_cmdset_0002: Use common error handling code in do_write_oneword() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 22:00 +0100
[PATCH 16/18] mtd-cfi_cmdset_0020: Use kmalloc_array() in cfi_staa_setup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 22:00 +0100
[PATCH 17/18] mtd-cfi_cmdset_0020: Use common error handling code in cfi_staa_setup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 22:00 +0100
[PATCH 18/18] mtd-cfi_cmdset_0020: Add some spaces for better code readability SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 22:00 +0100
Re: [PATCH 18/18] mtd-cfi_cmdset_0020: Add some spaces for better code readability Dan Carpenter <dan.carpenter@oracle.com> - 2017-01-12 10:40 +0100
[PATCH 13/18] mtd-cfi_cmdset_0002: Delete an unnecessary variable initialisation in do_write_oneword() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 22:00 +0100
[PATCH 15/18] mtd-cfi_cmdset_0002: Use kcalloc() in cfi_ppb_unlock() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 22:00 +0100
[PATCH 12/18] mtd-cfi_cmdset_0002: Add some spaces for better code readability SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 22:00 +0100
Re: [PATCH 00/18] MTD-CFI: Fine-tuning for several function implementations Boris Brezillon <boris.brezillon@free-electrons.com> - 2017-01-11 23:00 +0100
Re: [PATCH 00/18] MTD-CFI: Fine-tuning for several function implementations Marek Vasut <marek.vasut@gmail.com> - 2017-01-11 23:10 +0100
csiph-web