Received: by 10.213.65.68 with SMTP id h4csp873882imn; Tue, 27 Mar 2018 10:21:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xGPJzzyEATV1W5opo4gJlqlGVVR1nGRTPF0WrM/plRntbpRxm5F2xkkXc4abUOyJRm7bZ X-Received: by 2002:a17:902:9686:: with SMTP id n6-v6mr154519plp.331.1522171267721; Tue, 27 Mar 2018 10:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522171267; cv=none; d=google.com; s=arc-20160816; b=J1bCNEXi8e9Tv0HK5u3+RaWkqgjyfdyAAZRYggf8WhpuvrVj/JAmXSc+STEKeSh9ZO yHadRQFeypnEqntvF08E9B696hm+MCSWi4ayEDW/dIDxbY43hqS7Tyx+vg+yPteGFRED 9x+5V9fLP2cDO4j1wYOpJBgLnLSxzdosoc2rB7OBFSFLBXku2wazlqpGNAk6b9uoYMN/ lQNwFqHeqLyImpVfwz05UDQHHzA5xR8C8dbji81Yb504fWL69UL1PvlktwnACccK9VGW JpswPpusRg880iSg+yqvWODH3LnwonPVe1sHxCe4rZx2hTyQfmyDMKGdiZSsOfAZRpHG pJrA== 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=KuOq4+X6VmB/CshTVEW7qvHngP1Bygzt0aJPt2SbDqs=; b=QJ8i7KVQ3mohjTfnL32YIK94tCo0KcyMgFNuCWxm6tZikhWAU2s0L5fTs+ujjUO3au HuenKgSbkMT2UdghiNYffiq+xNRsreb5iJnwhPN3sogv+3Y91eNAIb64TkYvsdEGET8b xEnobwszUCwKzvWbhmaozDIi1FcSL2aiA2ELmnjlytFp2BKImcAnuRIb8NhCWxUkfEcQ tz2qMaHGSlT0tNXUkfhdjRKD/4DoUrMYJkOaVFqTIuM6RePbKkJiORby4l6Yg+W2NiVf nmFqIFskjToYyZd9pAAYDbI3uaQQqRib3EjBhySMhMBV3kCo1zGQJiKcMgCB3ZTgJw3O xSEA== 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 j11-v6si1532748plt.266.2018.03.27.10.20.53; Tue, 27 Mar 2018 10:21:07 -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 S1755183AbeC0QiV (ORCPT + 99 others); Tue, 27 Mar 2018 12:38:21 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46702 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754765AbeC0QiS (ORCPT ); Tue, 27 Mar 2018 12:38:18 -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 07F07FFB; Tue, 27 Mar 2018 16:38:17 +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.14 067/101] mtd: nand: fsl_ifc: Fix eccstat array overflow for IFC ver >= 2.0.0 Date: Tue, 27 Mar 2018 18:27:39 +0200 Message-Id: <20180327162754.143057893@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@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.14-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 @@ -173,14 +173,9 @@ static void set_addr(struct mtd_info *mt /* 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; } /* @@ -193,7 +188,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 */ @@ -228,8 +223,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) @@ -237,10 +232,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) {