Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4827463ybl; Wed, 22 Jan 2020 05:29:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzhRikAIxfj8yF989XHCA5dmETIpgljSHCAGbCqGx8Dc/DQpiqoU4ALtKWIRf9bHRY4qu9s X-Received: by 2002:a05:6830:1607:: with SMTP id g7mr7331944otr.320.1579699776323; Wed, 22 Jan 2020 05:29:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699776; cv=none; d=google.com; s=arc-20160816; b=cU4n6SD+DOMn/20ZhEXIzGTD5xUWFBFO8agUAM7BqF16pJ4Vz/mjWxlgUdPb0c2r6E HDhBPgtxkN8d2PxAlX+vOoV0lbbZZrVdl8gfYy6UIITM7X2ruqTYEWByNem1he1QcjWw pzshpX1U515jCeDUkdWlsH6pGmyaZV2E/WnaRRMXN79Be08ddvbMxFeM7jrOp0dJ59xI exQfCqbhoTgnbFF7FSWmJMyEIY0kJxAMyktfJl27QC2Ma0QHrtFcqRD07OLhC7CtwDGH CrFTIdMqZR/9X0JVuIzY/0WsaUG9ylYJlO8eVQDy1fP3A1mMZ9mXkK0ad0awlzOVWsCp mT2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ber9Ure7YPk0YxXktznfDLNMj5Xol6Xjzl1tDHmld7M=; b=ViUTr7kXTkF4nkT0HkR9BjwqmR71cHL6TWzO12i+m5nfZs4ubNSOCMZWnOnjzh/Xl4 78rfL13yKqEztNalNf4agmMsWVwH1Qm7cyRr3ZWXhEjZlmpAdjc+TDxCB43hpyfaKB8q XlvS00sRjswglSBTTcKdVZ/lUAzGg1RV5gpo90hbiBqlZgMIu4tFZDlmPpNH44cdtrEi BnLMYo7Kg0vT4HZn2tPVZNTEH5D4AUNc7UQV6xAagjOcEBUQ97sAJtzuNga1QTJE7PeH IBcVEv4qHRqTV6CIz931aXOpC5KrUxyidXfNNtlIzCAPk4qwlTPhrXnpvwyV/xBgMZDK 0PsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IX6AWryb; 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 e22si23175130oiy.124.2020.01.22.05.29.25; Wed, 22 Jan 2020 05:29:36 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=IX6AWryb; 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 S1731017AbgAVN2e (ORCPT + 99 others); Wed, 22 Jan 2020 08:28:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:50814 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730876AbgAVN2b (ORCPT ); Wed, 22 Jan 2020 08:28:31 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 76AAA24125; Wed, 22 Jan 2020 13:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699710; bh=bRPI4NEzsYbWl9R1aXwUkxxw/RBMVoVzvkO0RHLavmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IX6AWrybZdey/g6O+uGUAZg3F1rCJEhmuQzl2h+EOnYJNh9OSw999toSA9mkHx96l 4EK9B4fprgMF02QMt9qucBvTB05e0pKNnsFAr05wyU2LVm3ytXjH2mjaivFbR3CUuk KtkkTKai/4dvlIzE/R3GEk1BT9p4sM3jKKBbBPpU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Angelo Dureghello , Andrew Lunn , Miquel Raynal Subject: [PATCH 5.4 193/222] mtd: devices: fix mchp23k256 read and write Date: Wed, 22 Jan 2020 10:29:39 +0100 Message-Id: <20200122092847.495536388@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Angelo Dureghello commit 14f89e088155314d311e4d4dd9f2b4ccaeef92b2 upstream. Due to the use of sizeof(), command size set for the spi transfer was wrong. Driver was sending and receiving always 1 byte less and especially on write, it was hanging. echo -n -e "\\x1\\x2\\x3\\x4" > /dev/mtd1 And read part too now works as expected. hexdump -C -n16 /dev/mtd1 00000000 01 02 03 04 ab f3 ad c2 ab e3 f4 36 dd 38 04 15 00000010 Fixes: 4379075a870b ("mtd: mchp23k256: Add support for mchp23lcv1024") Signed-off-by: Angelo Dureghello Reviewed-by: Andrew Lunn Signed-off-by: Miquel Raynal Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/devices/mchp23k256.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/drivers/mtd/devices/mchp23k256.c +++ b/drivers/mtd/devices/mchp23k256.c @@ -64,15 +64,17 @@ static int mchp23k256_write(struct mtd_i struct spi_transfer transfer[2] = {}; struct spi_message message; unsigned char command[MAX_CMD_SIZE]; - int ret; + int ret, cmd_len; spi_message_init(&message); + cmd_len = mchp23k256_cmdsz(flash); + command[0] = MCHP23K256_CMD_WRITE; mchp23k256_addr2cmd(flash, to, command); transfer[0].tx_buf = command; - transfer[0].len = mchp23k256_cmdsz(flash); + transfer[0].len = cmd_len; spi_message_add_tail(&transfer[0], &message); transfer[1].tx_buf = buf; @@ -88,8 +90,8 @@ static int mchp23k256_write(struct mtd_i if (ret) return ret; - if (retlen && message.actual_length > sizeof(command)) - *retlen += message.actual_length - sizeof(command); + if (retlen && message.actual_length > cmd_len) + *retlen += message.actual_length - cmd_len; return 0; } @@ -101,16 +103,18 @@ static int mchp23k256_read(struct mtd_in struct spi_transfer transfer[2] = {}; struct spi_message message; unsigned char command[MAX_CMD_SIZE]; - int ret; + int ret, cmd_len; spi_message_init(&message); + cmd_len = mchp23k256_cmdsz(flash); + memset(&transfer, 0, sizeof(transfer)); command[0] = MCHP23K256_CMD_READ; mchp23k256_addr2cmd(flash, from, command); transfer[0].tx_buf = command; - transfer[0].len = mchp23k256_cmdsz(flash); + transfer[0].len = cmd_len; spi_message_add_tail(&transfer[0], &message); transfer[1].rx_buf = buf; @@ -126,8 +130,8 @@ static int mchp23k256_read(struct mtd_in if (ret) return ret; - if (retlen && message.actual_length > sizeof(command)) - *retlen += message.actual_length - sizeof(command); + if (retlen && message.actual_length > cmd_len) + *retlen += message.actual_length - cmd_len; return 0; }