linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] firmware: Google VPD: fix error handling on allocation failures
@ 2017-05-03 15:49 Colin King
  2017-05-03 15:58 ` walter harms
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2017-05-03 15:49 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Wei-Ning Huang, Thierry Escande, Wei Yongjun
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Fix two allocation failure checks. Firstly, ensure info is checked
for a failed allocation; this fixes a potential null pointer
dereference issue on info->key.  Secondly, free info is info->key
fails to allocate to fix a memory leak.

Detected by CoverityScan, CID#1430064 ("Resource Leak")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/firmware/google/vpd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
index 3ce813110d5e..2eb15b1dabcc 100644
--- a/drivers/firmware/google/vpd.c
+++ b/drivers/firmware/google/vpd.c
@@ -116,9 +116,13 @@ static int vpd_section_attrib_add(const u8 *key, s32 key_len,
 		return VPD_OK;
 
 	info = kzalloc(sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
 	info->key = kzalloc(key_len + 1, GFP_KERNEL);
-	if (!info->key)
+	if (!info->key) {
+		kfree(info);
 		return -ENOMEM;
+	}
 
 	memcpy(info->key, key, key_len);
 
-- 
2.11.0

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

end of thread, other threads:[~2017-05-03 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-03 15:49 [PATCH] firmware: Google VPD: fix error handling on allocation failures Colin King
2017-05-03 15:58 ` walter harms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).