Skip to contentSkip to conversation

pstore/platform: fix potential mem leak if pstore_init_fs failed

PATCH Applied [email protected] 2 participants 5 messages Feb 7, 2020 – Feb 25, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pstore/platform: fix potential mem leak if pstore_init_fs failed

From: chenqiwu <[email protected]>

There is a potential mem leak when pstore_init_fs failed, since the pstore compression maybe unlikey to initialized successfully. We must clean up the allocation once this unlikey issue happens.

---
 fs/pstore/platform.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/pstore/platform.c +3 -3
index d896457..114dbdf15 100644
@@ -822,10 +822,10 @@ static int __init pstore_init(void)
 	allocate_buf_for_compression();
 
 	ret = pstore_init_fs();
-	if (ret)
-		return ret;
+	if (ret < 0)
+		free_buf_for_compression();
 
-	return 0;
+	return ret;
 }
 late_initcall(pstore_init);
 
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 pstore/ram: remove unnecessary ramoops_unregister_dummy()

From: chenqiwu <[email protected]>

Remove unnecessary ramoops_unregister_dummy() if ramoops platform device register failed.

---
 fs/pstore/ram.c | 1 -
 1 file changed, 1 deletion(-)
fs/pstore/ram.c +0 -1
index 013486b..7956221 100644
@@ -963,7 +963,6 @@ static void __init ramoops_register_dummy(void)
 		pr_info("could not create platform device: %ld\n",
 			PTR_ERR(dummy));
 		dummy = NULL;
-		ramoops_unregister_dummy();
 	}
 }
 
Signature · 1 line
1.9.1
Applied
#2 lore raw

Re: [PATCH 2/2] pstore/ram: remove unnecessary ramoops_unregister_dummy()

Quoted 6 lines · On Fri, Feb 07, 2020 at 05:46:40PM +0800, [email protected] wrote:

From: chenqiwu <[email protected]>

Remove unnecessary ramoops_unregister_dummy() if ramoops platform device register failed.

Thanks! Applied to for-next/pstore.

-Kees

Quoted 19 lines
---
 fs/pstore/ram.c | 1 -
 1 file changed, 1 deletion(-)
fs/pstore/ram.c +0 -1
index 013486b..7956221 100644
@@ -963,7 +963,6 @@ static void __init ramoops_register_dummy(void)
 		pr_info("could not create platform device: %ld\n",
 			PTR_ERR(dummy));
 		dummy = NULL;
-		ramoops_unregister_dummy();
 	}
 }
 
Signature · 1 line
1.9.1
Signature · 1 line
Kees Cook
author
#3 lore raw
In reply to [email protected]
Quoted 20 lines · On Fri, Feb 07, 2020 at 05:46:39PM +0800, [email protected] wrote:

From: chenqiwu <[email protected]>

There is a potential mem leak when pstore_init_fs failed, since the pstore compression maybe unlikey to initialized successfully. We must clean up the allocation once this unlikey issue happens.

---
 fs/pstore/platform.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/pstore/platform.c +0 -0
index d896457..114dbdf15 100644
@@ -822,10 +822,10 @@ static int __init pstore_init(void)
 	allocate_buf_for_compression();
 
 	ret = pstore_init_fs();

fs/pstore/platform.c static int __init pstore_init(void) · line 831

Quoted 10 lines
fs/pstore/platform.c +3 -3
-	if (ret)
-		return ret;
+	if (ret < 0)
+		free_buf_for_compression();
 
-	return 0;
+	return ret;
 }
 late_initcall(pstore_init);
 

Deal all,
Any update about two fixes?

BRs,
Qiwu

Applied
#4 lore raw
In reply to [email protected]
Quoted 8 lines · On Fri, Feb 07, 2020 at 05:46:39PM +0800, [email protected] wrote:

From: chenqiwu <[email protected]>

There is a potential mem leak when pstore_init_fs failed, since the pstore compression maybe unlikey to initialized successfully. We must clean up the allocation once this unlikey issue happens.

Thanks! Applied to for-next/pstore.

-Kees

Quoted 25 lines
---
 fs/pstore/platform.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/pstore/platform.c +3 -3
index d896457..114dbdf15 100644
@@ -822,10 +822,10 @@ static int __init pstore_init(void)
 	allocate_buf_for_compression();
 
 	ret = pstore_init_fs();
-	if (ret)
-		return ret;
+	if (ret < 0)
+		free_buf_for_compression();
 
-	return 0;
+	return ret;
 }
 late_initcall(pstore_init);
 
Signature · 1 line
1.9.1
Signature · 1 line
Kees Cook