Received: by 10.213.65.68 with SMTP id h4csp39414imn; Mon, 19 Mar 2018 18:50:19 -0700 (PDT) X-Google-Smtp-Source: AG47ELsQE0j1fsw3OoqO2uHpQ2c95QA+MYLf4HV939+KJTOM0Bgmh5BdGKRpFZ+ovxgRob97WOqP X-Received: by 2002:a17:902:24c7:: with SMTP id l7-v6mr11721225plg.320.1521510619919; Mon, 19 Mar 2018 18:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510619; cv=none; d=google.com; s=arc-20160816; b=kMDEmBiYnY//c2xLxmPr9OsYv130P/TNo8B+LjSSQFJywgDDaPLjJZ3iK5VgH/bsws zQBO8KuzSaHj/z/e8jt8DGlMw3TiyHAC26OfLNHwMp8Jy0ZuApHFTuiMHX5WgT41U524 G+2xbcMcEt36uVp7eLJocqWN9BGt6AB4WXogwWjzI3M0JV2KqOOflqx8KLbPVWVC2GrO 1+7i4Ft9kAvfsiqDYw/XjrojsEBvqiQRZi48EQkvzk+2DMJSCKmXYsvuMeqmoCU3qn7o 4M8TvtrSXFMBK9x9ubMExVr/0FF7+QTgRPi97XsDQU/c35UhNzrvjDtzxmAk0Fb9h8bU ZAzw== 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=gRWMszJOfj6s5QMGBMLzLYY1xzTObKCSFwvjJhroHyw=; b=NJEr7o6bLK7dSdv0NXiP7RuLEMzZoglGdSyNNkTJLRdDJozBEP/XYDqs2+nZJt3N0h 4pLHJ3vTsNGssdMRqWcqEqkpUvDf+HfKOVD5Wan2OEg5UarHkm7uXNGikDaI11EP72tU 1RYcCdtSkV0c53BFeR4rCt+6rhIDjeu4CS+oMAd3Mg/KocRTd++OF9oVVaLq0D+0BL0L 0Di3p5JHnlNqithGFe3Ch0wkyXz/CF8QRaycfhk3mSeAXgRYJCBxUYh+OFSog97kK9lP aTBXr77Z021/Yh8SxaqhVfErKqxmcpHHQzEs8S1lrnJuGO/IuBxSyZPIwUXaMQ27m36a fTYQ== 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 a64-v6si575196pla.117.2018.03.19.18.50.04; Mon, 19 Mar 2018 18:50:19 -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 S971176AbeCSURz (ORCPT + 99 others); Mon, 19 Mar 2018 16:17:55 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44664 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968964AbeCSSPh (ORCPT ); Mon, 19 Mar 2018 14:15:37 -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 B0750101D; Mon, 19 Mar 2018 18:15:35 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miquel Raynal , Boris Brezillon , Sasha Levin Subject: [PATCH 4.4 087/134] mtd: nand: fix interpretation of NAND_CMD_NONE in nand_command[_lp]() Date: Mon, 19 Mar 2018 19:06:10 +0100 Message-Id: <20180319171901.863994566@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Miquel Raynal [ Upstream commit df467899da0b71465760b4e35127bce837244eee ] Some drivers (like nand_hynix.c) call ->cmdfunc() with NAND_CMD_NONE and a column address and expect the controller to only send address cycles. Right now, the default ->cmdfunc() implementations provided by the core do not filter out the command cycle in this case and forwards the request to the controller driver through the ->cmd_ctrl() method. The thing is, NAND controller drivers can get this wrong and send a command cycle with a NAND_CMD_NONE opcode and since NAND_CMD_NONE is -1, and the command field is usually casted to an u8, we end up sending the 0xFF command which is actually a RESET operation. Add conditions in nand_command[_lp]() functions to sending the initial command cycle when command == NAND_CMD_NONE. Signed-off-by: Miquel Raynal Signed-off-by: Boris Brezillon Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/nand_base.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -626,7 +626,8 @@ static void nand_command(struct mtd_info chip->cmd_ctrl(mtd, readcmd, ctrl); ctrl &= ~NAND_CTRL_CHANGE; } - chip->cmd_ctrl(mtd, command, ctrl); + if (command != NAND_CMD_NONE) + chip->cmd_ctrl(mtd, command, ctrl); /* Address cycle, when necessary */ ctrl = NAND_CTRL_ALE | NAND_CTRL_CHANGE; @@ -655,6 +656,7 @@ static void nand_command(struct mtd_info */ switch (command) { + case NAND_CMD_NONE: case NAND_CMD_PAGEPROG: case NAND_CMD_ERASE1: case NAND_CMD_ERASE2: @@ -717,7 +719,9 @@ static void nand_command_lp(struct mtd_i } /* Command latch cycle */ - chip->cmd_ctrl(mtd, command, NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); + if (command != NAND_CMD_NONE) + chip->cmd_ctrl(mtd, command, + NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); if (column != -1 || page_addr != -1) { int ctrl = NAND_CTRL_CHANGE | NAND_NCE | NAND_ALE; @@ -750,6 +754,7 @@ static void nand_command_lp(struct mtd_i */ switch (command) { + case NAND_CMD_NONE: case NAND_CMD_CACHEDPROG: case NAND_CMD_PAGEPROG: case NAND_CMD_ERASE1: