From patchwork Sun Sep 2 10:54:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Bityutskiy X-Patchwork-Id: 181178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [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 EEECC2C0093 for ; Sun, 2 Sep 2012 20:57:13 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T87pm-0001JO-PD; Sun, 02 Sep 2012 10:55:18 +0000 Received: from mail-wi0-f171.google.com ([209.85.212.171]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T87pj-0001JA-0i for linux-mtd@lists.infradead.org; Sun, 02 Sep 2012 10:55:15 +0000 Received: by wibhq4 with SMTP id hq4so2224992wib.0 for ; Sun, 02 Sep 2012 03:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=66gfafe/hau+20PjnVK9548hzdOmmhVAk3MxbskCzrk=; b=Io+9MaLnwaOjqwLrgjkTrzlbMaDsKkTGPTKBbzW2ApG9tsSh6jVrHmMDS7M9LbBPbm KGpcPcSjQFjPGf1M5TYBj4xPvFbFl8kpNsw550Ne5dm5Z5qyd7KA+MHeTm9m7o4p0CoQ ksAcJFIk3ZGScw1lQ40T6T0iG40ZJ3/8UEIE3pFiRBfm6RO9XtmVPfVHxhPgsWPyLUJt xbbCamOFzhf2uXCeeb7ho0m8JCwxLt3SIRSh6te3XwVzIxL/OLLt/hQwqqIWDPOOoNwp MiFPusIXV0XZLRAWTot6JVT4UBYsVvrxuOIEw0yr//27zjwPB0LmxVO5GcrIu1II9P/4 19NA== Received: by 10.180.77.34 with SMTP id p2mr16299210wiw.0.1346583308649; Sun, 02 Sep 2012 03:55:08 -0700 (PDT) Received: from localhost.localdomain (host-94-101-1-70.igua.fi. [94.101.1.70]) by mx.google.com with ESMTPS id w7sm12561845wiz.0.2012.09.02.03.55.06 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 02 Sep 2012 03:55:07 -0700 (PDT) From: Artem Bityutskiy To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: cmdlinepart: revise error handling Date: Sun, 2 Sep 2012 13:54:14 +0300 Message-Id: <1346583254-9190-1-git-send-email-dedekind1@gmail.com> X-Mailer: git-send-email 1.7.11.4 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.171 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dedekind1[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (dedekind1[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 Cc: Artem Bityutskiy X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Artem Bityutskiy This patch revises and fixes error handling in the command line mtd partitions parser. Namely: 1. we ignored return code of 'mtdpart_setup_real()'. 2. instead of returning 0 for failure and 1 for success, teach 'mtdpart_setup_real()' to return real error codes. Signed-off-by: Artem Bityutskiy --- drivers/mtd/cmdlinepart.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c index b4faca2..5bddecf 100644 --- a/drivers/mtd/cmdlinepart.c +++ b/drivers/mtd/cmdlinepart.c @@ -110,7 +110,7 @@ static struct mtd_partition * newpart(char *s, if (size < PAGE_SIZE) { printk(KERN_ERR ERRP "partition size too small (%lx)\n", size); - return NULL; + return ERR_PTR(-EINVAL); } } @@ -138,7 +138,7 @@ static struct mtd_partition * newpart(char *s, if (!p) { printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim); - return NULL; + return ERR_PTR(-EINVAL); } name_len = p - name; s = p + 1; @@ -172,13 +172,13 @@ static struct mtd_partition * newpart(char *s, if (size == SIZE_REMAINING) { printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n"); - return NULL; + return ERR_PTR(-EINVAL); } /* more partitions follow, parse them */ parts = newpart(s + 1, &s, num_parts, this_part + 1, &extra_mem, extra_mem_size); - if (!parts) - return NULL; + if (IS_ERR(parts)) + return parts; } else { /* this is the last partition: allocate space for all */ @@ -189,7 +189,7 @@ static struct mtd_partition * newpart(char *s, extra_mem_size; parts = kzalloc(alloc_size, GFP_KERNEL); if (!parts) - return NULL; + return PTR_ERR(-ENOMEM); extra_mem = (unsigned char *)(parts + *num_parts); } /* enter this partition (offset will be calculated later if it is zero at this point) */ @@ -245,7 +245,7 @@ static int mtdpart_setup_real(char *s) if (!(p = strchr(s, ':'))) { printk(KERN_ERR ERRP "no mtd-id\n"); - return 0; + return -EINVAL; } mtd_id_len = p - mtd_id; @@ -262,7 +262,7 @@ static int mtdpart_setup_real(char *s) (unsigned char**)&this_mtd, /* out: extra mem */ mtd_id_len + 1 + sizeof(*this_mtd) + sizeof(void*)-1 /*alignment*/); - if(!parts) + if(IS_ERR(parts)) { /* * An error occurred. We're either: @@ -271,7 +271,7 @@ static int mtdpart_setup_real(char *s) * Either way, this mtd is hosed and we're * unlikely to succeed in parsing any more */ - return 0; + return ERR_PTR(parts); } /* align this_mtd */ @@ -299,11 +299,11 @@ static int mtdpart_setup_real(char *s) if (*s != ';') { printk(KERN_ERR ERRP "bad character after partition (%c)\n", *s); - return 0; + return -EINVAL; } s++; } - return 1; + return 0; } /* @@ -318,13 +318,16 @@ static int parse_cmdline_partitions(struct mtd_info *master, struct mtd_part_parser_data *data) { unsigned long offset; - int i; + int i, err; struct cmdline_mtd_partition *part; const char *mtd_id = master->name; /* parse command line */ - if (!cmdline_parsed) - mtdpart_setup_real(cmdline); + if (!cmdline_parsed) { + err = mtdpart_setup_real(cmdline); + if (err) + return err; + } for(part = partitions; part; part = part->next) {