[Skiboot] [PATCH] external/pflash: Perform the correct cleanup

Cyril Bur cyril.bur at au1.ibm.com
Fri Nov 11 15:13:02 AEDT 2016


If the -F flag is used then pflash uses a regular file as the flash.

On cleanup pflash fails to tell arch_flash_close() if it had passed a
filename to arch_flash_init() as such arch_flash_close() assumes that
it needs to close the actual flash structure and not simply a file
descriptor leading to a NULL dereference.

Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
Note: This fix is correct but I'm not particularly fond of it. A
better solution is to refactor and stop relying on atexit() to perform
cleanup after the use of exit(). This cleanup would also benifit
debugging, this work and tests to avoid this situation in future is in
my work queue.

 external/pflash/pflash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index c93bbd4..fb45870 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -42,6 +42,7 @@
 /* Full pflash version number (possibly includes gitid). */
 extern const char version[];
 
+const char *flashfilename = NULL;
 static bool must_confirm = true;
 static bool dummy_run;
 static int need_relock;
@@ -524,7 +525,7 @@ void exiting(void)
 {
 	if (need_relock)
 		arch_flash_set_wrprotect(bl, 1);
-	arch_flash_close(bl, NULL);
+	arch_flash_close(bl, flashfilename);
 }
 
 int main(int argc, char *argv[])
@@ -540,7 +541,6 @@ int main(int argc, char *argv[])
 	char *write_file = NULL, *read_file = NULL, *part_name = NULL;
 	bool ffs_toc_seen = false, direct = false;
 	int rc;
-	const char *flashfilename = NULL;
 
 	while(1) {
 		struct option long_opts[] = {
-- 
2.10.2



More information about the Skiboot mailing list