From patchwork Fri Apr 17 14:23:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 11495303 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 143F96CA for ; Fri, 17 Apr 2020 14:27:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3CA320857 for ; Fri, 17 Apr 2020 14:27:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HXdoyDIe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QShcQD3/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3CA320857 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=6I5Ze1mlQRkdyGcHKSKdYblQSnXJ/DSDHKi3Opxkz4Y=; b=HXdoyDIedbrYZw gwovzAL3bZPbCsyI9Kw0JCeGTPpDm3PYk748UqwMn5jrcWzWNCVkCJhVpxen23UqHKhHiA7ujuSDn T4enCaWrV/t7AX70pxtPjUxcQDRJLfMmcMWt8+HZULb/GgzhFrIlIh+S41b+GzooIV48foEQ5Dp0j VerjqOlvJy9hb9ldRx7wO0hML18+OkOSehhurjlIxSJ0JpGIYfXV+Mf7jZ5hUmqMDDNHAO96otAR9 uYYcW+fBkFIs0a93f0qftJwPJOmVaOXUHGITU3UM6UpM+D74Pe5vcanC6BhxN1FbTDJnruRtuERyk I60c55aC+lxxgPdiSj5Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPRxb-0005Br-Mp; Fri, 17 Apr 2020 14:27:15 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPRxN-00053G-ER for linux-arm-kernel@lists.infradead.org; Fri, 17 Apr 2020 14:27:03 +0000 Received: by mail-wr1-x441.google.com with SMTP id t14so3231168wrw.12 for ; Fri, 17 Apr 2020 07:27:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PHFxusB8wA5WqPB2sIr0XZtrSers8hydd/1i7jfoyIM=; b=QShcQD3/K5G7PhsyLb+vZfLdWTAN41ha5G6ulcEMrf8GhM4uaK8YsBVonWPtth9WWd 6oTIBmj5FiXyMmvQAPoHg8pNnBD2gXKAYBOIlXjMYEIjzC7LvvtX1KetO0yjpjteIS/B S318g17YhYlnT4VwdAqdus2oUwoYJE0KnO3JZ8Fi/kZcUmY5o/ictTKsVa+uH2IOCogP YaYD0eN6kpvhE+TwSaXN1MwETTHUaNqEPQVdAg2eEOec0cc48M33gkY3vEE0dZDrcXby n9+QDI02e/PYKnPObUk1C8WZ0LtUtNeThWDUVy8icysQamXRYzki1uCbUNlXk0w89lLL W8Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PHFxusB8wA5WqPB2sIr0XZtrSers8hydd/1i7jfoyIM=; b=HSrBF2SWJy8WN/IXyQdwd9z2udPgJz5j17U0WPmF+BQwg1oyqJ2rwee8bDjJXOMqdu jIjHlh7S8Io9J45tQhLikutus2hizy+XPxc+r99axPum7SC97XRkwvteKpwLySuVLNwb k5EVq9j9FNBNghKXEE+/3x8cWIbreD/X6XYDvMMyfxxkeGuOqk3JfdoWDzIJkk6MNYma hfJlH74SNh0IZJP7nBA6XAWMWEgy/72OgChJpJQ8CY3UOy5R8DREX6fpjjIY6gl6fAAN EFZSn2P8O5a2F/DJYgzMaMkF7TtCWgaOQo37mc6aQ1CXC8UHwenQbiya/kOGS9VuOaha eIqw== X-Gm-Message-State: AGi0Pub3tXJMpHpo231GOLcwl3mV3QI6p6YFqt08eLwfTu5+ghuZbueO 1TPTPQjXGQG2AbshEyQlF/eDvA== X-Google-Smtp-Source: APiQypIQeo4qw1hhOGPpOoyM89JM24bpa+h+F3bZbfjwtpTKTN/uPVbfWNixkdcH2WIW7Jp6P6/ENA== X-Received: by 2002:adf:97ce:: with SMTP id t14mr4271829wrb.263.1587133619437; Fri, 17 Apr 2020 07:26:59 -0700 (PDT) Received: from localhost.localdomain ([2001:171b:226b:54a0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id a205sm7863556wmh.29.2020.04.17.07.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2020 07:26:58 -0700 (PDT) From: Jean-Philippe Brucker To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: cfi_cmdset_0001: Support the absence of protection registers Date: Fri, 17 Apr 2020 16:23:26 +0200 Message-Id: <20200417142325.2931423-1-jean-philippe@linaro.org> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200417_072702_011176_0440C3B1 X-CRM114-Status: GOOD ( 13.39 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , vigneshr@ti.com, richard@nod.at, miquel.raynal@bootlin.com, sudeep.holla@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The flash controller implemented by the Arm Base platform behaves like the Intel StrataFlash J3 device, but omits several features. In particular it doesn't implement a protection register, so "Number of Protection register fields" in the Primary Vendor-Specific Extended Query, is 0. The Intel StrataFlash J3 datasheet only lists 1 as a valid value for NumProtectionFields. It describes the field as: "Number of Protection register fields in JEDEC ID space. “00h,” indicates that 256 protection bytes are available" While a value of 0 may arguably not be architecturally valid, the driver's current behavior is certainly wrong: if NumProtectionFields is 0, read_pri_intelext() adds a negative value to the unsigned extra_size, and ends up in an infinite loop. Fix it by ignoring a NumProtectionFields of 0. Signed-off-by: Jean-Philippe Brucker Tested-by: Sudeep Holla Tested-by: Catalin Marinas --- I guess this flash device has never been tested on Linux. The bug showed up when trying to boot the latest arm64 defconfig, which enabled CONFIG_MTD_PHYSMAP_OF, on the RevC FastModel. Without this config option the device isn't probed. --- drivers/mtd/chips/cfi_cmdset_0001.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c index 142c0f9485fe1..42001c49833b9 100644 --- a/drivers/mtd/chips/cfi_cmdset_0001.c +++ b/drivers/mtd/chips/cfi_cmdset_0001.c @@ -420,8 +420,9 @@ read_pri_intelext(struct map_info *map, __u16 adr) extra_size = 0; /* Protection Register info */ - extra_size += (extp->NumProtectionFields - 1) * - sizeof(struct cfi_intelext_otpinfo); + if (extp->NumProtectionFields) + extra_size += (extp->NumProtectionFields - 1) * + sizeof(struct cfi_intelext_otpinfo); } if (extp->MinorVersion >= '1') { @@ -695,14 +696,16 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd, */ if (extp && extp->MajorVersion == '1' && extp->MinorVersion >= '3' && extp->FeatureSupport & (1 << 9)) { + int offs = 0; struct cfi_private *newcfi; struct flchip *chip; struct flchip_shared *shared; - int offs, numregions, numparts, partshift, numvirtchips, i, j; + int numregions, numparts, partshift, numvirtchips, i, j; /* Protection Register info */ - offs = (extp->NumProtectionFields - 1) * - sizeof(struct cfi_intelext_otpinfo); + if (extp->NumProtectionFields) + offs = (extp->NumProtectionFields - 1) * + sizeof(struct cfi_intelext_otpinfo); /* Burst Read info */ offs += extp->extra[offs+1]+2;