Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF4CAC282D8 for ; Wed, 30 Jan 2019 11:56:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A064220882 for ; Wed, 30 Jan 2019 11:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548849363; bh=SW+v5g3vVgunS9Kiw13bmPIXNmrcd+9uQEhthl5WBV0=; h=From:To:Cc:Subject:Date:List-ID:From; b=D/olm9Pv6xDAtHC+FUpHVyIMAVF9bKJgfc+S5kXVO8hwbW9jqGmyldRjkVSO0ncen x5TlH99E7/m/ZpkepNLLibelz0s2tC15g88xLdmqs4tJWYhDrWPb+IBmqljsVjJU1k CL1a+AW5mcyb+oHzYPD6InXqAUcPZUuMlCuRY3nU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727878AbfA3L4D (ORCPT ); Wed, 30 Jan 2019 06:56:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:51956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbfA3L4D (ORCPT ); Wed, 30 Jan 2019 06:56:03 -0500 Received: from localhost.localdomain (91-160-177-164.subs.proxad.net [91.160.177.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9FF1720855; Wed, 30 Jan 2019 11:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548849362; bh=SW+v5g3vVgunS9Kiw13bmPIXNmrcd+9uQEhthl5WBV0=; h=From:To:Cc:Subject:Date:From; b=g50rF8Yd9ahm9GPmJUmUy5Z+6Jy2vSANPn8qlwVBGi0w3gCKj4gM0BdA6bYolWkp6 ZGtP6gPt3fq4+iu1wyXuBpJ3M3Mh0sF92a3uhKJH1+fxhW6pr46zQ0T26hj16o1hk6 CULPA1kioKlyB0r20NKUEDV20ZifE44r0Rlf2eik= From: Boris Brezillon To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Cc: stable@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] mtd: Make sure mtd->erasesize is valid even if the partition is of size 0 Date: Wed, 30 Jan 2019 12:55:52 +0100 Message-Id: <20190130115552.9610-1-bbrezillon@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Commit 33f45c44d68b ("mtd: Do not allow MTD devices with inconsistent erase properties") introduced a check to make sure ->erasesize and ->_erase values are consistent with the MTD_NO_ERASE flag. This patch did not take the 0 bytes partition case into account which can happen when the defined partition is outside the flash device memory range. Fix that by setting the partition erasesize to the parent erasesize. Fixes: 33f45c44d68b ("mtd: Do not allow MTD devices with inconsistent erase properties") Reported-by: Geert Uytterhoeven Cc: Cc: Geert Uytterhoeven Signed-off-by: Boris Brezillon --- drivers/mtd/mtdpart.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index e6d9467f6be0..37f174ccbcec 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -480,6 +480,10 @@ static struct mtd_part *allocate_partition(struct mtd_info *parent, /* let's register it anyway to preserve ordering */ slave->offset = 0; slave->mtd.size = 0; + + /* Initialize ->erasesize to make add_mtd_device() happy. */ + slave->mtd.erasesize = parent->erasesize; + printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", part->name); goto out_register; -- 2.17.1