Received: by 10.213.65.68 with SMTP id h4csp901673imn; Tue, 27 Mar 2018 10:52:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx48TUUH7mwYFgBUJVuMcuwM5/gUa1ubAxljjMtvbB2kZhn3MUCnputP2L2n3E0/fpOZSr1BA X-Received: by 10.98.223.16 with SMTP id u16mr240000pfg.146.1522173129484; Tue, 27 Mar 2018 10:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522173129; cv=none; d=google.com; s=arc-20160816; b=JW1Wz8DBO3u1mJtLUXMGjKaPnJLz8ROnt+jnKplhmL36yGhLTw3GlF8S3/rGiJmDcL YiftG3fL17EFLi+csRnNaiB22TEK/eWHuiTVkgbMbTAj1aXL5fHz83iGKTitMVu9tyz7 xVq3iQJeblT8QRtlaJB17yVjK01vl8DhCEpWQ+mmcJltrDraDq3FguYdsdMCfqe/HGPg Gif9BnXdtUkcTE53PQt5VX2UyGpSiYM4Y/xJqeWtHgeE5g0zk0F++x14iL9Kw7AqNXw4 BOAcjOBwkiZRP16ghjEzrOjDaMqHYXVQyWB0Y2xgRqUvgy9Scc8a21AIGdZuB68AAOeF Koyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=41qtkUHovDPKLh/wZvBW0ClTa4vVhk9Fa9KK7zkrTts=; b=GOeomLDTvG4hO4zL39FQ/DmhshMoOexjrkHwGRf1WfQFoPXzLIHDJoUvwm0SWYl0WA BKBuuVl9ZY84vDwla8JI811Ijxl8smOHc9NpTrXyKIJuLs4EvPIf2tV9G7I642shItk5 6MndPmJ9A3ATnpnBse50YxFdPq0Yo/oR+l04mMcK0qwraMCZsAHut1xg1VXRsKDgl1ds cAF8LYobk9BHgAbrrhjTABk2k50e/kYTbCFCPF8o/7JRD8Cy5AfB/fbLXz3D7i6ohiGD oBYAqH/tpjzHMhrv8kkvNyat8qYQq1IxJm87v92guZi0yz/mzAbPO0SkP7RpwuOXVTRY vA7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9si1286182pfg.8.2018.03.27.10.51.55; Tue, 27 Mar 2018 10:52:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753678AbeC0Qcd (ORCPT + 99 others); Tue, 27 Mar 2018 12:32:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43352 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753661AbeC0Qc3 (ORCPT ); Tue, 27 Mar 2018 12:32:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 86EA3FA1; Tue, 27 Mar 2018 16:32:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Prabhakar Kushwaha , Jagdish Gediya , Boris Brezillon Subject: [PATCH 4.9 40/67] mtd: nand: fsl_ifc: Fix eccstat array overflow for IFC ver >= 2.0.0 Date: Tue, 27 Mar 2018 18:27:32 +0200 Message-Id: <20180327162729.208870444@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162726.702411083@linuxfoundation.org> References: <20180327162726.702411083@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jagdish Gediya commit 843c3a59997f18060848b8632607dd04781b52d1 upstream. Number of ECC status registers i.e. (ECCSTATx) has been increased in IFC version 2.0.0 due to increase in SRAM size. This is causing eccstat array to over flow. So, replace eccstat array with u32 variable to make it fail-safe and independent of number of ECC status registers or SRAM size. Fixes: bccb06c353af ("mtd: nand: ifc: update bufnum mask for ver >= 2.0.0") Cc: stable@vger.kernel.org # 3.18+ Signed-off-by: Prabhakar Kushwaha Signed-off-by: Jagdish Gediya Signed-off-by: Boris Brezillon Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/fsl_ifc_nand.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) --- a/drivers/mtd/nand/fsl_ifc_nand.c +++ b/drivers/mtd/nand/fsl_ifc_nand.c @@ -201,14 +201,9 @@ static int is_blank(struct mtd_info *mtd /* returns nonzero if entire page is blank */ static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl, - u32 *eccstat, unsigned int bufnum) + u32 eccstat, unsigned int bufnum) { - u32 reg = eccstat[bufnum / 4]; - int errors; - - errors = (reg >> ((3 - bufnum % 4) * 8)) & 15; - - return errors; + return (eccstat >> ((3 - bufnum % 4) * 8)) & 15; } /* @@ -221,7 +216,7 @@ static void fsl_ifc_run_command(struct m struct fsl_ifc_ctrl *ctrl = priv->ctrl; struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl; struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs; - u32 eccstat[4]; + u32 eccstat; int i; /* set the chip select for NAND Transaction */ @@ -256,8 +251,8 @@ static void fsl_ifc_run_command(struct m if (nctrl->eccread) { int errors; int bufnum = nctrl->page & priv->bufnum_mask; - int sector = bufnum * chip->ecc.steps; - int sector_end = sector + chip->ecc.steps - 1; + int sector_start = bufnum * chip->ecc.steps; + int sector_end = sector_start + chip->ecc.steps - 1; __be32 *eccstat_regs; if (ctrl->version >= FSL_IFC_VERSION_2_0_0) @@ -265,10 +260,12 @@ static void fsl_ifc_run_command(struct m else eccstat_regs = ifc->ifc_nand.v1_nand_eccstat; - for (i = sector / 4; i <= sector_end / 4; i++) - eccstat[i] = ifc_in32(&eccstat_regs[i]); + eccstat = ifc_in32(&eccstat_regs[sector_start / 4]); + + for (i = sector_start; i <= sector_end; i++) { + if (i != sector_start && !(i % 4)) + eccstat = ifc_in32(&eccstat_regs[i / 4]); - for (i = sector; i <= sector_end; i++) { errors = check_read_ecc(mtd, ctrl, eccstat, i); if (errors == 15) {