From patchwork Mon Jun 1 23:17:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 479227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AC8AB1412F8 for ; Tue, 2 Jun 2015 09:19:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=bd1cni8v; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YzYyG-0007KX-Pn; Mon, 01 Jun 2015 23:18:16 +0000 Received: from mail-pd0-x22d.google.com ([2607:f8b0:400e:c02::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YzYyB-0007Hx-JT for linux-mtd@lists.infradead.org; Mon, 01 Jun 2015 23:18:12 +0000 Received: by pdbki1 with SMTP id ki1so118536615pdb.1 for ; Mon, 01 Jun 2015 16:17:50 -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:in-reply-to:references; bh=olRpKwqJwTa96NtbsXIoH2GvfL33PhJ2afWORTzKENc=; b=bd1cni8vkfGQRc/YFyImIkP7fYMGAs5qHUhNmhEeN+78dAeLLP5sCP/WhtvYzHIrE1 b9niqtj0Mm4c4/w3sDQ74QSVfx1y1pQ0naog/e4/qjnf+evgHjf1broX1cCiVO8SLFpm f3aJJ9/L9UhA+uksvstDj/IRrhwt6DaTLWzNkpi/pP6bz+1zluurcRFQJzRX8j/mOQ+/ 9044Z9zFJFs18cvOtnU1lgR4mBF8V1g/jskrfVnHahjsAqdUhCGCKRqy8YxmQZChj3cC 6WowvXjJasVT9rskAMjHwRVZQ+UekubEMkYXZcRkWo6QNKiAq8NFyR5p1l6O7kLDZRvk DUzA== X-Received: by 10.70.103.70 with SMTP id fu6mr24302624pdb.22.1433200670366; Mon, 01 Jun 2015 16:17:50 -0700 (PDT) Received: from ld-irv-0074.broadcom.com (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPSA id fe10sm15640195pdb.59.2015.06.01.16.17.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jun 2015 16:17:49 -0700 (PDT) From: Brian Norris To: Subject: [PATCH 2/4] mtd: propagate error codes from add_mtd_device() Date: Mon, 1 Jun 2015 16:17:18 -0700 Message-Id: <1433200640-17858-2-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433200640-17858-1-git-send-email-computersforpeace@gmail.com> References: <1433200640-17858-1-git-send-email-computersforpeace@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150601_161811_703193_042EA668 X-CRM114-Status: GOOD ( 15.11 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c02:0:0:0:22d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -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: Richard Weinberger , Brian Norris X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 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" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org It makes more sense to return error statuses, not 1/0. At the same time, note a few places where error handling is not currently done. Signed-off-by: Brian Norris Reviewed-by: Richard Weinberger --- drivers/mtd/mtdcore.c | 18 +++++++++++------- drivers/mtd/mtdpart.c | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index f3ca97f139bc..8bbbb751bf45 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -379,8 +379,7 @@ static int mtd_reboot_notifier(struct notifier_block *n, unsigned long state, * * Add a device to the list of MTD devices present in the system, and * notify each currently active MTD 'user' of its arrival. Returns - * zero on success or 1 on failure, which currently will only happen - * if there is insufficient memory or a sysfs error. + * zero on success or non-zero on failure. */ int add_mtd_device(struct mtd_info *mtd) @@ -394,8 +393,10 @@ int add_mtd_device(struct mtd_info *mtd) mutex_lock(&mtd_table_mutex); i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL); - if (i < 0) + if (i < 0) { + error = i; goto fail_locked; + } mtd->index = i; mtd->usecount = 0; @@ -424,6 +425,8 @@ int add_mtd_device(struct mtd_info *mtd) printk(KERN_WARNING "%s: unlock failed, writes may not work\n", mtd->name); + /* Ignore unlock failures? */ + error = 0; } /* Caller should have set dev.parent to match the @@ -434,7 +437,8 @@ int add_mtd_device(struct mtd_info *mtd) mtd->dev.devt = MTD_DEVT(i); dev_set_name(&mtd->dev, "mtd%d", i); dev_set_drvdata(&mtd->dev, mtd); - if (device_register(&mtd->dev) != 0) + error = device_register(&mtd->dev); + if (error) goto fail_added; device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL, @@ -458,7 +462,7 @@ fail_added: idr_remove(&mtd_idr, i); fail_locked: mutex_unlock(&mtd_table_mutex); - return 1; + return error; } /** @@ -514,8 +518,8 @@ static int mtd_add_device_partitions(struct mtd_info *mtd, if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { ret = add_mtd_device(mtd); - if (ret == 1) - return -ENODEV; + if (ret) + return ret; } if (nbparts > 0) { diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index cafdb8855a79..f7aa944bc6e9 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -610,6 +610,7 @@ int mtd_add_partition(struct mtd_info *master, const char *name, list_add(&new->list, &mtd_partitions); mutex_unlock(&mtd_partitions_mutex); + /* FIXME: handle errors */ add_mtd_device(&new->mtd); mtd_add_partition_attrs(new); @@ -671,6 +672,7 @@ int add_mtd_partitions(struct mtd_info *master, list_add(&slave->list, &mtd_partitions); mutex_unlock(&mtd_partitions_mutex); + /* FIXME: handle errors */ add_mtd_device(&slave->mtd); mtd_add_partition_attrs(slave);