From patchwork Tue Nov 6 21:44:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 993897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Yfv5A0OR"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qNPV1rD0z9sBZ for ; Wed, 7 Nov 2018 08:45:02 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=G8DYz6St4seTbV1nETR4aoV/nlB3UCvUHgM3GHcWmfc=; b=Yfv 5A0ORcTRnaO8+uO2hN6zfbNP+muauj0f/nrUctENWO7ysz0xtPm7/blXn13OaY2Uqt47Rrd9/Bjzk +9NGR0Nf+mMIzcAK8bLOHtfXzEuN2gTyMkRw9Y1+69yEh4/iv6sWmJSGJ5i40+0XCuBhaCi4MubjH qFip89QIX6BA/nqDdwrNmErdVC3tsG3ANqmRmt7xpbRzLfHPz+f3ak1usVkcrFrB0RreEwJYZZOeh KaeGhZtxnVRSBFy9lJ8nNoUM93a4ac4SRD1ECb4UnSboX7NaKcyWrVm9xNtvzQ/Xz+9YHYLpp+Ux4 gdq4MskxSj+RxTsLYWE0W+ArYXF6cuQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gK99c-0000N4-2A; Tue, 06 Nov 2018 21:44:56 +0000 Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gK99R-0008CH-4R for linux-mtd@lists.infradead.org; Tue, 06 Nov 2018 21:44:47 +0000 Received: from ramsan.of.borg ([84.194.111.163]) by andre.telenet-ops.be with bizsmtp id wlkM1y00G3XaVaC01lkM05; Tue, 06 Nov 2018 22:44:27 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1gK993-0002DL-7f; Tue, 06 Nov 2018 22:44:21 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1gK993-0002xn-4j; Tue, 06 Nov 2018 22:44:21 +0100 From: Geert Uytterhoeven To: Ricardo Ribalda Delgado , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Linus Walleij Subject: [PATCH next] mtd: maps: physmap: Fix infinite loop crash in ROM type probing Date: Tue, 6 Nov 2018 22:44:16 +0100 Message-Id: <20181106214416.11342-1-geert@linux-m68k.org> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181106_134445_337865_07BA99CB X-CRM114-Status: GOOD ( 13.61 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a02:1800:120:4:0:0:f00:15 listed in] [list.dnswl.org] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mips@linux-mips.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On Toshiba RBTX4927, where map_probe is supposed to fail: Creating 2 MTD partitions on "physmap-flash.0": 0x000000c00000-0x000001000000 : "boot" 0x000000000000-0x000000c00000 : "user" physmap-flash physmap-flash.1: physmap platform flash device: [mem 0x1e000000-0x1effffff] CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 80320f40, ra == 80321004 ... Call Trace: [<80320f40>] get_mtd_chip_driver+0x30/0x8c [<80321004>] do_map_probe+0x20/0x90 [<80328448>] physmap_flash_probe+0x484/0x4ec The access to rom_probe_types[] was changed from a sentinel-based loop to an infinite loop, causing a crash when reaching the sentinel. Fix this by: - Removing the no longer needed sentinel, - Limiting the number of loop iterations to the actual number of ROM types. Fixes: c7afe08496fa463e ("mtd: maps: physmap: Invert logic on if/else branch") Signed-off-by: Geert Uytterhoeven --- drivers/mtd/maps/physmap-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/maps/physmap-core.c b/drivers/mtd/maps/physmap-core.c index 33b77bd9022ce251..e8c3b250d8421edc 100644 --- a/drivers/mtd/maps/physmap-core.c +++ b/drivers/mtd/maps/physmap-core.c @@ -396,7 +396,7 @@ static int physmap_flash_of_init(struct platform_device *dev) #endif /* IS_ENABLED(CONFIG_MTD_PHYSMAP_OF) */ static const char * const rom_probe_types[] = { - "cfi_probe", "jedec_probe", "qinfo_probe", "map_rom", NULL + "cfi_probe", "jedec_probe", "qinfo_probe", "map_rom", }; static const char * const part_probe_types[] = { @@ -524,7 +524,7 @@ static int physmap_flash_probe(struct platform_device *dev) } else { int j; - for (j = 0; ARRAY_SIZE(rom_probe_types); j++) { + for (j = 0; j < ARRAY_SIZE(rom_probe_types); j++) { info->mtds[i] = do_map_probe(rom_probe_types[j], &info->maps[i]); if (info->mtds[i])