Received: by 10.213.65.68 with SMTP id h4csp484706imn; Fri, 16 Mar 2018 09:08:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELtkHrv/GSHl0Hj3sC3gknJMyVHrgYN5MGIWVAFD+AVXnQttt0fO/b/iW9Q5nhqfvSm+CsHp X-Received: by 2002:a17:902:858c:: with SMTP id e12-v6mr2756757plo.39.1521216538993; Fri, 16 Mar 2018 09:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521216538; cv=none; d=google.com; s=arc-20160816; b=zFtt0l9VK6mU9TVKSPP0xOjbOyGnL2oPbjRbaA1PAJ4J5YoGWU7ktNJgikXllFcBYt awICiPO5Nv1tCYyqsPgLIei+wlupWUPamETw9fawqaO/MSa9xxck+pphLKzGJ2CVrFBZ JeiG30C5NNK9j5pYA1UPtNO+xjZRUF65bJBtIJ+cMzvzLo6RC24IxLbIm3t6yqnIuPrQ zjodyC3qDlDrkM9nEiyWZaAG+9UdaUoieFq+GW/iekP6Snp1ZwAe/GF8jeOd67IUIsGg dT40NkuP8R98tU5XBog5AfqvUO5YdjiTzkhJjpR3XuWFMC+sKovNcufwDxzvrdsEOTN0 8MRQ== 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=c0IIbZW9TNHYUZRwAlZH1JiUtpqWvWyYiq2zIEpeIyI=; b=bouUjBT0NBPliUDdpw3sBdiXbOPTl9gSeAoLrtodFMdkHjspp3xm5/dudQEwwmTCc3 vE48PRsMl0oSBD6gZbS6RJXv7QUluCY4ln6Slr+ILlBv0WTVXc8AJnOkVyL8o1+66WDK HwLER7ffS713ZdPu3TrT726/zEz2x5SFFmhf0WHXo7qxvhlSbVMlFIeS1RMgegpW/C86 eIB8RMaO5DZVngQ6cUR9tBYVR1BnJnHp2od8VWGV/s7UGfbwyVC1RgIy/c4P+0NwNz3M JvOTlRZddoi1oEP7k1eSPh0MSfqk2gvYqrvI9MLZCft438rLs0wgfFuwSohlvoZ1L3e1 qlYQ== 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 u27si5676841pfk.241.2018.03.16.09.08.40; Fri, 16 Mar 2018 09:08:58 -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 S964778AbeCPQGE (ORCPT + 99 others); Fri, 16 Mar 2018 12:06:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44116 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754774AbeCPPlq (ORCPT ); Fri, 16 Mar 2018 11:41:46 -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 E4FD4F87; Fri, 16 Mar 2018 15:41:45 +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.15 059/128] mtd: nand: fix interpretation of NAND_CMD_NONE in nand_command[_lp]() Date: Fri, 16 Mar 2018 16:23:20 +0100 Message-Id: <20180316152339.757796180@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152336.199007505@linuxfoundation.org> References: <20180316152336.199007505@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.15-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; @@ -738,6 +739,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: @@ -831,7 +833,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; @@ -866,6 +870,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: