From patchwork Wed Jun 23 10:48:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 56615 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 39C12B6F16 for ; Wed, 23 Jun 2010 18:50:57 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1ORLdu-00034O-CC; Wed, 23 Jun 2010 08:49:10 +0000 Received: from smtp.seznam.cz ([77.75.72.43]) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1ORLdp-00033h-9C for linux-mtd@lists.infradead.org; Wed, 23 Jun 2010 08:49:06 +0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=seznam.cz; h=Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-Smtpd:X-Seznam-User:X-QM-Mark; b=QTvw1TnHxqwmC2q1dncxNSUKRRqFK3alqjoEhsOnnzcvTinOW/gUfagJ/IHee0qso kvlElrra9KTzO3pC0l6tzg0/oxs2QUsM0UVZwHLLyxfkqTBd1AEoYTH9K0PiPoFigYQ FoYmzSFmIVirZNWHBIJb1niNROzcP5A8197ga3Y= Received: from debian (34.24.broadband3.iol.cz [85.70.24.34]) by email-relay2.go.seznam.cz (Seznam SMTPD 1.1.7@13984) with ESMTP; Wed, 23 Jun 2010 10:48:58 +0200 (CEST) Received: by debian (sSMTP sendmail emulation); Wed, 23 Jun 2010 12:48:58 +0200 Date: Wed, 23 Jun 2010 12:48:58 +0200 From: Ladislav Michl To: linux-mtd@lists.infradead.org Subject: [PATCH] flash_eraseall: do not use exit() Message-ID: <20100623104858.GA2442@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Smtpd: 1.1.7@13984 X-Seznam-User: ladislav.michl@seznam.cz X-QM-Mark: email-qm5<495645174> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100623_044905_596641_FBD2CFD5 X-CRM114-Status: GOOD ( 12.46 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [77.75.72.43 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (ladislav.michl[at]seznam.cz) -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Ladislav Michl 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 From: Ladislav Michl Returning from main() instead of using exit() makes code more readable and smaller. text data bss dec hex filename 6440 324 68 6832 1ab0 flash_eraseall 6405 320 68 6793 1a89 flash_eraseall.noexit Signed-off-by: Ladislav Michl --- flash_eraseall.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/flash_eraseall.c b/flash_eraseall.c index 531bbe6..db65553 100644 --- a/flash_eraseall.c +++ b/flash_eraseall.c @@ -51,14 +51,6 @@ static int jffs2; /* format for jffs2 usage */ static struct jffs2_unknown_node cleanmarker; int target_endian = __BYTE_ORDER; -static void show_progress(mtd_info_t *meminfo, erase_info_t *erase) -{ - printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.", - meminfo->erasesize / 1024, erase->start, - (unsigned long long) erase->start * 100 / meminfo->size); - fflush(stdout); -} - static void display_help(void) { printf("Usage: %s [OPTION] MTD_DEVICE\n" @@ -70,10 +62,8 @@ static void display_help(void) " --help display this help and exit\n" " --version output version information and exit\n", exe_name); - exit(0); } - static void display_version(void) { printf(PROGRAM " " VERSION "\n" @@ -86,12 +76,22 @@ static void display_version(void) "You may redistribute copies of " PROGRAM "\n" "under the terms of the GNU General Public Licence.\n" "See the file `COPYING' for more information.\n"); - exit(0); } -static void process_options(int argc, char *argv[]) +static void show_progress(mtd_info_t *meminfo, erase_info_t *erase) +{ + printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.", + meminfo->erasesize / 1024, erase->start, + (unsigned long long) erase->start * 100 / meminfo->size); + fflush(stdout); +} + +int main(int argc, char *argv[]) { - int error = 0; + mtd_info_t meminfo; + int fd, error = 0, clmpos = 0, clmlen = 8; + erase_info_t erase; + int isNAND, bbtest = 1; exe_name = argv[0]; @@ -119,10 +119,10 @@ static void process_options(int argc, char *argv[]) switch (option_index) { case 0: display_help(); - break; + return 0; case 1: display_version(); - break; + return 0; } break; case 'q': @@ -143,20 +143,10 @@ static void process_options(int argc, char *argv[]) if (error) { fprintf(stderr, "Try `%s --help' for more information.\n", exe_name); - exit(1); + return 1; } mtd_device = argv[optind]; -} - -int main(int argc, char *argv[]) -{ - mtd_info_t meminfo; - int fd, clmpos = 0, clmlen = 8; - erase_info_t erase; - int isNAND, bbtest = 1; - - process_options(argc, argv); if ((fd = open(mtd_device, O_RDWR)) < 0) { fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno));