From patchwork Wed Aug 31 20:00:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 112679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 94A8DB6EE8 for ; Thu, 1 Sep 2011 06:06:11 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qyr2l-0005K1-Q3; Wed, 31 Aug 2011 20:05:52 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qyr2l-0006pn-AB; Wed, 31 Aug 2011 20:05:51 +0000 Received: from mms1.broadcom.com ([216.31.210.17]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qyr2i-0006pV-D7 for linux-mtd@lists.infradead.org; Wed, 31 Aug 2011 20:05:49 +0000 Received: from [10.9.200.131] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Wed, 31 Aug 2011 13:11:52 -0700 X-Server-Uuid: 02CED230-5797-4B57-9875-D5D2FEE4708A Received: from mail-irva-13.broadcom.com (10.11.16.103) by IRVEXCHHUB01.corp.ad.broadcom.com (10.9.200.131) with Microsoft SMTP Server id 8.2.247.2; Wed, 31 Aug 2011 13:05:38 -0700 Received: from ld-irv-0074.broadcom.com (ld-irv-0074 [10.12.160.50]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id F3EE774D03; Wed, 31 Aug 2011 13:05:38 -0700 (PDT) From: "Brian Norris" To: "Artem Bityutskiy" Subject: [PATCH 10/10] nandwrite: use common.h "errmsg" functions Date: Wed, 31 Aug 2011 13:00:39 -0700 Message-ID: <1314820839-7107-11-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1314820839-7107-1-git-send-email-computersforpeace@gmail.com> References: <1314820839-7107-1-git-send-email-computersforpeace@gmail.com> MIME-Version: 1.0 X-WSS-ID: 62404A024R04387671-01-01 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110831_160548_660774_841E6D44 X-CRM114-Status: GOOD ( 17.12 ) X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-1.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [216.31.210.17 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 1.2 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list Cc: b35362@freescale.com, Brian Norris , linux-mtd@lists.infradead.org, Mike Frysinger X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Convert several forms of exit(), perror(), etc. to use common.h helper functions. Also, move one of our parameter checks inside the process_options() function for consistency. Signed-off-by: Brian Norris --- nandwrite.c | 44 ++++++++++++++++---------------------------- 1 files changed, 16 insertions(+), 28 deletions(-) diff --git a/nandwrite.c b/nandwrite.c index ca72f16..a42f7c9 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -182,6 +182,9 @@ static void process_options(int argc, char * const argv[]) if (autoplace && noecc) errmsg_die("Autoplacement and no-ECC are mutually exclusive"); + if (!onlyoob && (pad && writeoob)) + errmsg_die("Can't pad when oob data is present"); + argc -= optind; argv += optind; @@ -242,23 +245,16 @@ int main(int argc, char * const argv[]) process_options(argc, argv); - if (!onlyoob && (pad && writeoob)) { - fprintf(stderr, "Can't pad when oob data is present.\n"); - exit(EXIT_FAILURE); - } - /* Open the device */ - if ((fd = open(mtd_device, O_RDWR)) == -1) { - perror(mtd_device); - exit(EXIT_FAILURE); - } + if ((fd = open(mtd_device, O_RDWR)) == -1) + sys_errmsg_die("%s", mtd_device); mtd_desc = libmtd_open(); if (!mtd_desc) - return errmsg("can't initialize libmtd"); + errmsg_die("can't initialize libmtd"); /* Fill in MTD device capability structure */ if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0) - return errmsg("mtd_get_dev_info failed"); + errmsg_die("mtd_get_dev_info failed"); /* * Pretend erasesize is specified number of blocks - to match jffs2 @@ -267,13 +263,10 @@ int main(int argc, char * const argv[]) */ ebsize_aligned = mtd.eb_size * blockalign; - if (mtdoffset & (mtd.min_io_size - 1)) { - fprintf(stderr, "The start address is not page-aligned !\n" - "The pagesize of this NAND Flash is 0x%x.\n", - mtd.min_io_size); - close(fd); - exit(EXIT_FAILURE); - } + if (mtdoffset & (mtd.min_io_size - 1)) + errmsg_die("The start address is not page-aligned !\n" + "The pagesize of this NAND Flash is 0x%x.\n", + mtd.min_io_size); /* Select OOB write mode */ if (noecc) @@ -290,9 +283,7 @@ int main(int argc, char * const argv[]) case ENOTTY: errmsg_die("ioctl MTDFILEMODE is missing"); default: - perror("MTDFILEMODE"); - close(fd); - exit(EXIT_FAILURE); + sys_errmsg_die("MTDFILEMODE"); } } } @@ -341,7 +332,7 @@ int main(int argc, char * const argv[]) fprintf(stderr, "Image %d bytes, NAND page %d bytes, OOB area %d" " bytes, device size %lld bytes\n", imglen, pagelen, mtd.oob_size, mtd.size); - perror("Input file does not fit into device"); + sys_errmsg("Input file does not fit into device"); goto closeall; } @@ -557,12 +548,9 @@ closeall: free(filebuf); close(fd); - if (failed - || ((ifd != STDIN_FILENO) && (imglen > 0)) - || (writebuf < (filebuf + filebuf_len))) { - perror("Data was only partially written due to error\n"); - exit(EXIT_FAILURE); - } + if (failed || ((ifd != STDIN_FILENO) && (imglen > 0)) + || (writebuf < (filebuf + filebuf_len))) + sys_errmsg_die("Data was only partially written due to error"); /* Return happy */ return EXIT_SUCCESS;