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: 185517 Delivered-To: patch@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp561287ilf; Fri, 17 Apr 2020 07:27:21 -0700 (PDT) X-Google-Smtp-Source: APiQypLIIFHzXXuPz4+KenUYd1m56bwvsKQ2wAjRd3c2OfJ4143kjyU0xe1JCrWn+8VlEzYrhtPu X-Received: by 2002:a17:90b:956:: with SMTP id dw22mr4681264pjb.152.1587133641668; Fri, 17 Apr 2020 07:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587133641; cv=none; d=google.com; s=arc-20160816; b=LhZ5NBw8KGEoI4DGjeGfcL/LM9ghDz2UK7YK8wVnOLxUoPmoDsZSuilHukZv+LHcIu 2cOfj+0YgNkMdda8QsUv1eppQeiU2yF8HX6MfgJ7NNANTOIf7VkeXPIkqVlhEk2YdqYF nTxeD5WKpmb/8lwrafIZpgThbxgXR6AhGTSl6uI27yXeeY0bV/G8BAfI4qkt439V3EJy leZtdUo0BUYE1HPav9JWA4zQ0Qu/1ZQzO93tOSz1Mg5QNEs9xFO80eslOSVTayKym4Ds 0Moy5eaQS7fAtmjYJj3CtzAS+gD7Yh9SYQmbdrCVfEGqgJk2cfDNneoNM0O0TnTR81j5 3Spw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :dkim-signature:dkim-signature; bh=TPHfbqZIhbWIlPtk3ShC17oGKEYCREgiViVyN5zwIjg=; b=aWU+dypu5wg3SzjaXhTpZMkDB3T6vlp2ceUM+xehgrt76eAcm1hvlVqtm9XuqFNrca FZa2z2XmE3qhEU4+i+EoCieuhpyATK99dPEk5avRKvWmkzrJ7QNp23r7nakFaD2OHUrR luVDXN1JoKrqJ/0SRtj326k0yms0OBpJi8i7+8/wJtlUlg8jXWkLfhMv+Wg2v/wU06M0 sWY0ed47m6mqJcokyImbGEJuF8bmnhOVovG8HRVtCjC+V3MS9sYnS65dH1t7vPD/F29P 4BHv8wmlwI2lqZedGyElmjDOrediVdgUod4lITGpDMiDNF4sIlU+UmraUVBnmAYEVx1l UAtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Vkeyai9F; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="QShcQD3/"; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id z199si17718043pfc.7.2020.04.17.07.27.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2020 07:27:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Vkeyai9F; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="QShcQD3/"; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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=TPHfbqZIhbWIlPtk3ShC17oGKEYCREgiViVyN5zwIjg=; b=Vkeyai9FbP9bpE 8HpjPTaqL1fkAHnucldL9/YmkBLmrXW9OC8WvVOawIXlSQAsJSrXJVDQ2PwPoH7/1aeU1ttP1BL81 skqgoFSYEZUz8/ZsI6VxsmgGZZIJNYhVMU+MvPa9Mwhb8/l8pgUvtrQ9q+b/FExzZNQ3FWfsgzlLg YAAff7AgtRc/BQoCx0LE2eeRCS3djoNcm3uhWQTFElPswOlDz1zEGjsJ5CZsD/JYs4qPtrtMD/UMp PsPGPEudlxBS/GGIRE4P+aAhJtrBseVv4cf7NU9g9mH19C60x1VzRGXwCannzfOnwyo+2YJhzepwP gcx3zGMu1yqXU3WHzKpA==; 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 1jPRxT-000548-KG; Fri, 17 Apr 2020 14:27:07 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPRxN-00053H-K6 for linux-mtd@lists.infradead.org; Fri, 17 Apr 2020 14:27:03 +0000 Received: by mail-wr1-x442.google.com with SMTP id a25so3315400wrd.0 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=AVZdfjlZ9mxDTsR94E39hgauGdZk62t1m4vOZRbXdHaszYLGee0XEIQaLomHcb/+Pc iLhzw5klyzhk9DJkHk8D8xk4t8ZhCgUWK7SIXoypEdkQM02P8avHKK9nimEJyOFTEO0y 1u4oG+oMMsb5uJuCu/gWC008BNTgSzwgyZUWs3MgqRcqloU9+H3aonGwTRQXpmN4R6nJ JIKur+CidDzhIR4L77dMlAehtYQ5p5H5olYidgMWmRHJ15H1GwcZhDquxe7aC4k/LQzv kSFC5EsXJ8lEphozVbhVqAD6Hoid/KbaCGqZ1vDPDoVVKTqoc9KM8D2Lv642ZL8eMD+K ln8A== X-Gm-Message-State: AGi0PuafN5O6zaXQno8hF0Lq7rl+zYJrVvmAyP6jZDdLR+TmRhMFlj/h G/JOgt5sWSBr8SM1Mz7ts+dbbsqnAWk= 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_008013_6A4C093F X-CRM114-Status: GOOD ( 12.76 ) 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:442 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-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list 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-mtd" Errors-To: linux-mtd-bounces+patch=linaro.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;