Received: by 10.213.65.68 with SMTP id h4csp1754909imn; Mon, 19 Mar 2018 12:21:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELvcHpEN/nYvIwIRSUicS27iBOdGCMPbeaOmzLBMXre6j9a93viS6mmqFnA6wKL+uOu9s7ks X-Received: by 2002:a17:902:2e:: with SMTP id 43-v6mr13580719pla.282.1521487282313; Mon, 19 Mar 2018 12:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521487282; cv=none; d=google.com; s=arc-20160816; b=N4dYQKOCcMtNTs8UEo5VEbj3s/OL8JhXs5HAvONVe1q+upzJKq7N2q4Qh5P4HyQB/w zglqLqlNhUMCcqblDeP/pzNpgEIUkMS1lLtDUivi+7UKLTiLpRLcRjSJ+dDSny4lf1Uy gmiNHmM4/5cadgjWslpuBge/nb4BB8lMXnwilTwU4gDsXRtAls+oP8U26RqnZAFk83ft bL+xa9SnB/GkXdTI9WqAM5LysAytwFmk3NFTLnK0FghIkhao3VTWfqiYKhCXKv+OddrP oQIpQbWy95N8OizBnZ0siia8UOcaPRa+dVCGVUDTQqk386626xlhzEa3OlYX8vYfsTGI kBXA== 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=rIgv/vFLQZth8WYWgmcg3yZG1vfmJHv7zdzVy6XHXRE=; b=hYzDNacC64VBYqQ9X+5eZJkMvRis1VDn3bDANimUM19ClCuhk1Dq8BqKAYYt7/3MPW kJP+XxCJA3FfW7/iO3rDLuprMHmryw9pkoupG9mMcnrc0W9o9nAetlyzYbngMMyVxB0l TQXZNJPSz1rN28cF1SHylJQbjfECmcoqd/bmWTe47wskqfVvcViMw7T96O36ggHyYAxN /RWUloy52JFTxH9wvaJEYT6LVKPS1pTSfLlKEcQFrElW+Mm0bnks/uv0XgNFXIISL6tV /IePJ3JZSGOA1wf0JHzbyZq2b73rvmdWCPQkypWbJ0NzqQXo2M6zGjc8BaZZ5BWhDo4Z IRmA== 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 bd3-v6si578807plb.392.2018.03.19.12.21.08; Mon, 19 Mar 2018 12:21:22 -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 S935893AbeCSTTZ (ORCPT + 99 others); Mon, 19 Mar 2018 15:19:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50570 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S969792AbeCSSZt (ORCPT ); Mon, 19 Mar 2018 14:25:49 -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 28B6AD09; Mon, 19 Mar 2018 18:25:49 +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.9 175/241] mtd: nand: fix interpretation of NAND_CMD_NONE in nand_command[_lp]() Date: Mon, 19 Mar 2018 19:07:20 +0100 Message-Id: <20180319180758.397891892@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@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: 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 @@ -715,7 +715,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; @@ -744,6 +745,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: @@ -806,7 +808,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; @@ -842,6 +846,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: