linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Douthit <stephend@adiengineering.com>
To: seth.heasley@intel.com, nhorman@tuxdriver.com
Cc: wsa@the-dreams.de, danp@adiengineering.com,
	stephend@adiengineering.com, linux-i2c@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] i2c: ismt: Don't duplicate the receive length for block reads
Date: Mon,  7 Aug 2017 17:10:59 -0400	[thread overview]
Message-ID: <1502140260-13789-2-git-send-email-stephend@adiengineering.com> (raw)
In-Reply-To: <1502140260-13789-1-git-send-email-stephend@adiengineering.com>

According to Table 15-14 of the C2000 EDS (Intel doc #510524) the
rx data pointed to by the descriptor dptr contains the byte count.

desc->rxbytes reports all bytes read on the wire, including the
"byte count" byte.  So if a device sends 4 bytes in response to a
block read, on the wire and in the DMA buffer we see:

count data1 data2 data3 data4
 0x04  0xde  0xad  0xbe  0xef

That's what we want to return in data->block to the next level.

Instead we were actually prefixing that with desc->rxbytes:

bad
count count data1 data2 data3 data4
 0x05  0x04  0xde  0xad  0xbe  0xef

This was discovered while developing a BMC solution relying on the
ipmi_ssif.c driver which was trying to interpret the bogus length
field as part of the IPMI response.

Signed-off-by: Stephen Douthit <stephend@adiengineering.com>
Tested-by: Dan Priamo <danp@adiengineering.com>
---
 drivers/i2c/busses/i2c-ismt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index e98e44e..9af2337 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -341,8 +341,8 @@ static int ismt_process_desc(const struct ismt_desc *desc,
 			break;
 		case I2C_SMBUS_BLOCK_DATA:
 		case I2C_SMBUS_I2C_BLOCK_DATA:
-			memcpy(&data->block[1], dma_buffer, desc->rxbytes);
-			data->block[0] = desc->rxbytes;
+			memcpy(data->block, dma_buffer, desc->rxbytes);
+			data->block[0] = desc->rxbytes - 1;
 			break;
 		}
 		return 0;
-- 
2.7.5

  reply	other threads:[~2017-08-07 21:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-07 21:10 [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Stephen Douthit
2017-08-07 21:10 ` Stephen Douthit [this message]
2017-08-07 21:11 ` [PATCH 2/2] i2c: ismt: Return EMSGSIZE for block reads with bogus length Stephen Douthit
2017-08-14 19:31 ` [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Wolfram Sang
2017-08-28 13:50   ` Stephen Douthit
2017-08-29 10:22     ` Wolfram Sang
2017-08-29 11:35       ` Neil Horman
2017-08-29 11:49         ` Wolfram Sang
2017-08-29 18:12           ` Dan Priamo
2017-08-29 20:08             ` Wolfram Sang
2017-08-29 20:10               ` Dan Priamo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502140260-13789-2-git-send-email-stephend@adiengineering.com \
    --to=stephend@adiengineering.com \
    --cc=danp@adiengineering.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=seth.heasley@intel.com \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).