From patchwork Tue Nov 14 00:03:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eudean Sun X-Patchwork-Id: 10056901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F50660365 for ; Tue, 14 Nov 2017 00:04:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30C97291BE for ; Tue, 14 Nov 2017 00:04:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2428128DB6; Tue, 14 Nov 2017 00:04:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 903B028DB6 for ; Tue, 14 Nov 2017 00:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751336AbdKNAED (ORCPT ); Mon, 13 Nov 2017 19:04:03 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:46374 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751028AbdKNAED (ORCPT ); Mon, 13 Nov 2017 19:04:03 -0500 Received: by mail-qt0-f195.google.com with SMTP id 1so21824080qtn.3 for ; Mon, 13 Nov 2017 16:04:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=G0fnpAs/9ulGpYZh5DltcSOKSZwUEZZevN4ApydqbJc=; b=VXWSunOEvZ5jpgMj9QyiyS1RAJCUYlH+0BQwB49GJA0FUNDx0/KXXvyZcarFBP+VmD 8nvcPmt+uS1OTsHqSvdU5dg+Hp0zBKYkql2Ucsa9SfwFGK7Pz4suvQewZuuBWt61UtHc xxwJzuG+tD34bAKlB8M7zWaUCUdJX7umGSSvg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=G0fnpAs/9ulGpYZh5DltcSOKSZwUEZZevN4ApydqbJc=; b=lbLIn3uK9fyqtwu0NqBJXWH7lml2P91b2wTxBFdcnDQabeRJn2A15xOS3L+rBQqzUp ddisec7GEacxxNwgGk+xbgnidUykxYariMyVPOTlP66cOpNtcnH0FNa8sFgnfh/lBM/0 ExSXnOuvgB3MvEG84leM9k05sguxfuF5gU46m4IzisN3HMj6pK9KmlL3q/1+Sn0u+0Ic BjfRSZSP8b2fbMOMle2XTz7jujpPncOsllqFiSILduORCoT2V+lyVYvgdwml5mId/Wwx 96LRy8TXnHEmP7WXr2P/VaQ+9YDc+sfQZSG9RQDlg2Pk3TKD1aAYY+9lZTou7SoBwBXE ptFA== X-Gm-Message-State: AJaThX4FoaiKXGYUovaXio9idVvI7kFOs2xymDK49x1cl1tXzKX4X7yh oMGj16hPTvQDSEr/mIMH7HkKdA== X-Google-Smtp-Source: AGs4zMZ7ZCnuMB8jKuhnwV8H7VjhnB+RJSezDOw1l2lZL6Bg5OrOSQLCiuKTLIDx7UWRKI0X3FLcNw== X-Received: by 10.200.51.107 with SMTP id u40mr15035541qta.152.1510617842117; Mon, 13 Nov 2017 16:04:02 -0800 (PST) Received: from mail.arista.com ([50.232.156.226]) by smtp.gmail.com with ESMTPSA id n31sm11898777qtf.62.2017.11.13.16.04.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Nov 2017 16:04:01 -0800 (PST) Date: Mon, 13 Nov 2017 16:03:59 -0800 From: Eudean Sun To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: cp2112: Fix I2C_BLOCK_DATA transactions Message-ID: <20171114000358.GA14433@mail.arista.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The existing driver erroneously treats I2C_BLOCK_DATA and BLOCK_DATA commands the same. Fix the logic for I2C_BLOCK_DATA reads and writes. Signed-off-by: Eudean Sun --- drivers/hid/hid-cp2112.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c index 078026f..0adece2 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -692,8 +692,16 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr, (u8 *)&word, 2); break; case I2C_SMBUS_I2C_BLOCK_DATA: - size = I2C_SMBUS_BLOCK_DATA; - /* fallthrough */ + if (read_write == I2C_SMBUS_READ) { + read_length = data->block[0]; + count = cp2112_write_read_req(buf, addr, read_length, + command, NULL, 0); + } else { + count = cp2112_write_req(buf, addr, command, + data->block + 1, + data->block[0]); + } + break; case I2C_SMBUS_BLOCK_DATA: if (I2C_SMBUS_READ == read_write) { count = cp2112_write_read_req(buf, addr, @@ -781,6 +789,9 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr, case I2C_SMBUS_WORD_DATA: data->word = le16_to_cpup((__le16 *)buf); break; + case I2C_SMBUS_I2C_BLOCK_DATA: + memcpy(data->block + 1, buf, read_length); + break; case I2C_SMBUS_BLOCK_DATA: if (read_length > I2C_SMBUS_BLOCK_MAX) { ret = -EPROTO;