From patchwork Sun Jul 13 07:23:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 369391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id F141A1400E4 for ; Sun, 13 Jul 2014 17:23:35 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752739AbaGMHXe (ORCPT ); Sun, 13 Jul 2014 03:23:34 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45340 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751555AbaGMHXe (ORCPT ); Sun, 13 Jul 2014 03:23:34 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7FA30ABA2; Sun, 13 Jul 2014 07:23:33 +0000 (UTC) Date: Sun, 13 Jul 2014 09:23:31 +0200 From: Jean Delvare To: Linux I2C Cc: Wolfram Sang , Guenter Roeck Subject: [PATCH v2] i2c-stub: Allow increasing the SMBus block write length Message-ID: <20140713092331.67d4f5b3@endymion.delvare> Organization: SUSE Linux X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.22; x86_64-suse-linux-gnu) MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This is no good reason to not allow SMBus block writes longer than the first one was. Lift this limitation, this makes the code more simple. Signed-off-by: Jean Delvare Reviewed-by: Guenter Roeck Tested-by: Guenter Roeck --- Changes since v1: * Sent in a separate thread * Added Guenter's Reviewed-by * Fixed subject Documentation/i2c/i2c-stub | 5 ++--- drivers/i2c/i2c-stub.c | 12 +++--------- 2 files changed, 5 insertions(+), 12 deletions(-) --- linux-3.16-rc4.orig/Documentation/i2c/i2c-stub 2014-07-12 09:41:26.508195718 +0200 +++ linux-3.16-rc4/Documentation/i2c/i2c-stub 2014-07-12 10:40:05.064578130 +0200 @@ -20,9 +20,8 @@ operations. This allows for continuous EEPROMs, among others. SMBus block commands must be written to configure an SMBus command for -SMBus block operations. The first SMBus block write selects the block length. -Subsequent writes can be partial. Block read commands always return -the number of bytes selected with the first write. +SMBus block operations. Writes can be partial. Block read commands always +return the number of bytes selected with the largest write so far. The typical use-case is like this: 1. load this module --- linux-3.16-rc4.orig/drivers/i2c/i2c-stub.c 2014-07-12 09:41:26.508195718 +0200 +++ linux-3.16-rc4/drivers/i2c/i2c-stub.c 2014-07-12 11:19:40.908827183 +0200 @@ -254,13 +254,6 @@ static s32 stub_xfer(struct i2c_adapter ret = -EINVAL; break; } - if (b && len > b->len) { - dev_dbg(&adap->dev, - "Attempt to write more data (%d) than with initial SMBus block write (%d)\n", - len, b->len); - ret = -EINVAL; - break; - } if (b == NULL) { b = stub_find_block(&adap->dev, chip, command, true); @@ -268,9 +261,10 @@ static s32 stub_xfer(struct i2c_adapter ret = -ENOMEM; break; } - /* First write sets block length */ - b->len = len; } + /* Largest write sets read block length */ + if (len > b->len) + b->len = len; for (i = 0; i < len; i++) b->block[i] = data->block[i + 1]; /* update for byte and word commands */