From patchwork Fri Nov 11 04:13:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 693560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tFRPp4g4yz9t0H for ; Fri, 11 Nov 2016 15:14:22 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3tFRPp3lhDzDvnh for ; Fri, 11 Nov 2016 15:14:22 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3tFRNt75CpzDvp7 for ; Fri, 11 Nov 2016 15:13:34 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAB48S56037385 for ; Thu, 10 Nov 2016 23:13:33 -0500 Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140]) by mx0a-001b2d01.pphosted.com with ESMTP id 26n35bmyr2-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 10 Nov 2016 23:13:32 -0500 Received: from localhost by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 11 Nov 2016 14:13:30 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 11 Nov 2016 14:13:27 +1000 Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id CC5D12CE8046 for ; Fri, 11 Nov 2016 15:13:26 +1100 (EST) Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAB4DQGa65339642 for ; Fri, 11 Nov 2016 15:13:26 +1100 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uAB4DQoB001318 for ; Fri, 11 Nov 2016 15:13:26 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uAB4DQlu001311; Fri, 11 Nov 2016 15:13:26 +1100 Received: from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 146A1A026C; Fri, 11 Nov 2016 15:13:26 +1100 (AEDT) From: Cyril Bur To: skiboot@lists.ozlabs.org Date: Fri, 11 Nov 2016 15:13:02 +1100 X-Mailer: git-send-email 2.10.2 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111104-0044-0000-0000-000001FF5336 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111104-0045-0000-0000-000005F20460 Message-Id: <20161111041302.17837-1-cyril.bur@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-11_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611110073 Subject: [Skiboot] [PATCH] external/pflash: Perform the correct cleanup X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 --- 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[] = {