Received: by 10.213.65.68 with SMTP id h4csp467161imn; Fri, 16 Mar 2018 08:37:54 -0700 (PDT) X-Google-Smtp-Source: AG47ELsFQszpJZeHeH7mm0jYNqRSa5zCqjKppysSEpGoYAoJ/w6o/xgFmllahnD3mjpaQ3VHxACD X-Received: by 10.98.34.143 with SMTP id p15mr1951786pfj.101.1521214674562; Fri, 16 Mar 2018 08:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521214674; cv=none; d=google.com; s=arc-20160816; b=J0hsQp5vuN+wno+Kj3wmnzXCfBzqoCl6Jwy36XMR8UVKHwq7UTElveQObOSEhbFe4O RUMsPWeUE90dJulWzl6+iVz/YFIFym3jLT6GvVrGsPFrD+vvQuzGEFmnRIQzHRt1VmCM 7AigARGplMHqUSoJpCwRXg3T7jpu8Q+qkU27/K5XV4J/ClMXyLZY32TKp7KpMbIC3R/j yUVUQzhBx44njU3xLs42kE6aO7ep8HlYYRpYRWJvXvet4saFjrrjI9/rsI9BWK9uyMvO mpx/zFs18wPMcI5hJV7Vg++vRh03Mk6xwmfxKUQ/HYnTHLPHVtK7X4kfIChFXhLLewOd /jiw== 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=kq2VvXNeN2b9592u0uFZHMz+JA1D4aZUXn7joVvCW9U=; b=yDrybSrN/KwiIrUGYj7+aJkxjSbteoQ0ZRHs/pAc48qfZQ6+cO+TOq0NNgJ6lw53fy N+uyGSx/WZ3yyYOMpNFlBdzV5SYQiyvWTXBy4C3a0s9h7L9CIqI1SUYOe9X5GjUFdUg2 VrgiaFOUG+VMTFEhbx3mehxB0CQ9DnZxfAeuMQwl9XiLc/T4U88NorlCYSa+8hPWDDN3 HqhUEsYpdtwIieBnaEs5l/A+02SuZNZJzvnEprFxix1gH43Z6lhhWTWmdmc8B/4rQglj 3hrLuhD+8gnOSt0B8yFu5lbhg61WbyNGYOTqfZB47TtLdRnjhZW2gEqKmnjtqocc3Vz+ mbEA== 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 p24si4659148pgn.797.2018.03.16.08.37.40; Fri, 16 Mar 2018 08:37:54 -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 S1754452AbeCPPgA (ORCPT + 99 others); Fri, 16 Mar 2018 11:36:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:40066 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754379AbeCPPf4 (ORCPT ); Fri, 16 Mar 2018 11:35:56 -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 0E56F107D; Fri, 16 Mar 2018 15:35:55 +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.14 048/109] mtd: nand: fix interpretation of NAND_CMD_NONE in nand_command[_lp]() Date: Fri, 16 Mar 2018 16:23:17 +0100 Message-Id: <20180316152332.577034686@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152329.844663293@linuxfoundation.org> References: <20180316152329.844663293@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: 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 @@ -710,7 +710,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; @@ -739,6 +740,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: @@ -832,7 +834,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; @@ -868,6 +872,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: