From patchwork Tue Nov 12 20:31:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1193845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oP9T2kDq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47CKCp73pcz9sPh for ; Wed, 13 Nov 2019 07:31:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbfKLUbi (ORCPT ); Tue, 12 Nov 2019 15:31:38 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35771 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfKLUbi (ORCPT ); Tue, 12 Nov 2019 15:31:38 -0500 Received: by mail-pf1-f195.google.com with SMTP id q13so1740383pff.2; Tue, 12 Nov 2019 12:31:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r3O5SP52V9myM7E1RnL3DmYndjXCh1kG1PX4UPfcdCc=; b=oP9T2kDqsUJAzI5z3z/CGplFM2kuATFfZf3Ny/0ejWrkn2jvCMWo3JOMV7oit3HjID ORFdoOZG9pwKM/VA0ovibh++P30DsUPRgHmg0su6eZJ0uNLlWIiXCpvRlYc8W9oPRtUs UymvKCkts84RerAuGN82i21Jy8uPA5spxxE9PxZx0oKJbZQGP1k6BcVa+EbqrFcHbkTu frtsKT5y7k1x962P0RjXRDtTkBXlfzyOdsmJ4phznpM48L5c0yhcAJfrEYg1lh33Kh41 l4I7iia3721/usTcqIRPHnaF9FpujlJtpqUlxyBECdzje5JmwrnOC/4qkUVST89+v7Y/ 7/hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r3O5SP52V9myM7E1RnL3DmYndjXCh1kG1PX4UPfcdCc=; b=lNYYDQ9ylZizeTmy7e8jfin1OBcu1pS/TPYayXavI2NMq2PkECcv6tReEcz0URqiEZ C4QINC4ftvwx6QWiZQvwXQofSrlRkqDUB/y4njpFZa0JfMI2LosPUuf91u4hYt2RtO2R +PacghljnsWmdleTAqXfOko9ciSQc/R0OYtNCJY3GUL/dK+U29EuHVBQWrPVGOZLcpr0 8IQ3pzT6ibZique9eIcMWOz2tqkaOfdXAiH8ZmyL4g62hzuneUUAOGg78XMZP1QiBbrE SUb9tlrqoDZcCmpAl6xSyYNi7qaAYp7lEpDhztPz5R8zoL0xNfR7x75jZOgubFqYLHm9 hHgg== X-Gm-Message-State: APjAAAVxzMRJWHEr94ADIsdJ/VUgPtn0g36VYFnTCXPj/WRid/o/ET+4 bfBpguTFfXFGKMvt8yPKCGc= X-Google-Smtp-Source: APXvYqwjpKCk55926/GFRWlG4nTX3TLvhkdCsjbFl8J5ckkVeT4wmehoLhWE85BbiGqslu7aP7zJVQ== X-Received: by 2002:aa7:9432:: with SMTP id y18mr182796pfo.250.1573590696965; Tue, 12 Nov 2019 12:31:36 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id h13sm23264084pfr.98.2019.11.12.12.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 12:31:36 -0800 (PST) From: Dmitry Torokhov To: Wolfram Sang Cc: linux-iio@vger.kernel.orgi, Luca Ceresoli , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron , Hartmut Knaack , Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v3 1/3] i2c: use void pointers for supplying data for reads and writes Date: Tue, 12 Nov 2019 12:31:30 -0800 Message-Id: <20191112203132.163306-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog In-Reply-To: <20191112203132.163306-1-dmitry.torokhov@gmail.com> References: <20191112203132.163306-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org There is no need to force users of i2c_master_send()/i2c_master_recv() and other i2c read/write bulk data API to cast everything into u8 pointers. While everything can be considered byte stream, the drivers are usually work with more structured data. Let's switch the APIs to accept [const] void pointers to cut amount of casting needed. Acked-by: Jonathan Cameron Signed-off-by: Dmitry Torokhov Reviewed-by: Luca Ceresoli --- Changes in v3: - addressed Luca's comments - added Jonathan's Acked-by Changes in v2: - adjusted max1363 to the new i2c_master_send/recv signatures drivers/i2c/i2c-core-base.c | 2 +- drivers/i2c/i2c-core-smbus.c | 17 +++++++++-------- drivers/iio/adc/max1363.c | 14 ++++++++------ include/linux/i2c.h | 28 +++++++++++++++------------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 6a5183cffdfc3..aeb4201ef55e4 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -2065,7 +2065,7 @@ EXPORT_SYMBOL(i2c_transfer); * * Returns negative errno, or else the number of bytes transferred. */ -int i2c_transfer_buffer_flags(const struct i2c_client *client, char *buf, +int i2c_transfer_buffer_flags(const struct i2c_client *client, void *buf, int count, u16 flags) { int ret; diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index 3ac426a8ab5ab..f8708409b4dbc 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -213,7 +213,7 @@ EXPORT_SYMBOL(i2c_smbus_write_word_data); * mechanism (I2C_M_RECV_LEN) which may not be implemented. */ s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command, - u8 *values) + void *values) { union i2c_smbus_data data; int status; @@ -240,7 +240,7 @@ EXPORT_SYMBOL(i2c_smbus_read_block_data); * else zero on success. */ s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command, - u8 length, const u8 *values) + u8 length, const void *values) { union i2c_smbus_data data; @@ -256,7 +256,7 @@ EXPORT_SYMBOL(i2c_smbus_write_block_data); /* Returns the number of read bytes */ s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command, - u8 length, u8 *values) + u8 length, void *values) { union i2c_smbus_data data; int status; @@ -276,7 +276,7 @@ s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command, EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command, - u8 length, const u8 *values) + u8 length, const void *values) { union i2c_smbus_data data; @@ -628,8 +628,9 @@ EXPORT_SYMBOL(__i2c_smbus_xfer); * transfer. */ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, - u8 command, u8 length, u8 *values) + u8 command, u8 length, void *values) { + u8 *bytes = values; u8 i = 0; int status; @@ -647,8 +648,8 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, status = i2c_smbus_read_word_data(client, command + i); if (status < 0) return status; - values[i] = status & 0xff; - values[i + 1] = status >> 8; + bytes[i] = status & 0xff; + bytes[i + 1] = status >> 8; i += 2; } } @@ -657,7 +658,7 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, status = i2c_smbus_read_byte_data(client, command + i); if (status < 0) return status; - values[i] = status; + bytes[i] = status; i++; } diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 5c2cc61b666e7..48ed76a0e83d4 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -182,9 +182,9 @@ struct max1363_state { struct regulator *vref; u32 vref_uv; int (*send)(const struct i2c_client *client, - const char *buf, int count); + const void *buf, int count); int (*recv)(const struct i2c_client *client, - char *buf, int count); + void *buf, int count); }; #define MAX1363_MODE_SINGLE(_num, _mask) { \ @@ -310,27 +310,29 @@ static const struct max1363_mode return NULL; } -static int max1363_smbus_send(const struct i2c_client *client, const char *buf, +static int max1363_smbus_send(const struct i2c_client *client, const void *buf, int count) { + const u8 *data = buf; int i, err; for (i = err = 0; err == 0 && i < count; ++i) - err = i2c_smbus_write_byte(client, buf[i]); + err = i2c_smbus_write_byte(client, data[i]); return err ? err : count; } -static int max1363_smbus_recv(const struct i2c_client *client, char *buf, +static int max1363_smbus_recv(const struct i2c_client *client, void *buf, int count) { + u8 *data = buf; int i, ret; for (i = 0; i < count; ++i) { ret = i2c_smbus_read_byte(client); if (ret < 0) return ret; - buf[i] = ret; + data[i] = ret; } return count; diff --git a/include/linux/i2c.h b/include/linux/i2c.h index aaf57d9b41dbb..64cf92e191aa8 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -51,7 +51,7 @@ struct property_entry; * @count must be be less than 64k since msg.len is u16. */ extern int i2c_transfer_buffer_flags(const struct i2c_client *client, - char *buf, int count, u16 flags); + void *buf, int count, u16 flags); /** * i2c_master_recv - issue a single I2C message in master receive mode @@ -62,7 +62,7 @@ extern int i2c_transfer_buffer_flags(const struct i2c_client *client, * Returns negative errno, or else the number of bytes read. */ static inline int i2c_master_recv(const struct i2c_client *client, - char *buf, int count) + void *buf, int count) { return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD); }; @@ -77,7 +77,7 @@ static inline int i2c_master_recv(const struct i2c_client *client, * Returns negative errno, or else the number of bytes read. */ static inline int i2c_master_recv_dmasafe(const struct i2c_client *client, - char *buf, int count) + void *buf, int count) { return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD | I2C_M_DMA_SAFE); @@ -92,9 +92,10 @@ static inline int i2c_master_recv_dmasafe(const struct i2c_client *client, * Returns negative errno, or else the number of bytes written. */ static inline int i2c_master_send(const struct i2c_client *client, - const char *buf, int count) + const void *buf, int count) { - return i2c_transfer_buffer_flags(client, (char *)buf, count, 0); + return i2c_transfer_buffer_flags(client, (void *)buf /* const cast */, + count, 0); }; /** @@ -107,10 +108,10 @@ static inline int i2c_master_send(const struct i2c_client *client, * Returns negative errno, or else the number of bytes written. */ static inline int i2c_master_send_dmasafe(const struct i2c_client *client, - const char *buf, int count) + const void *buf, int count) { - return i2c_transfer_buffer_flags(client, (char *)buf, count, - I2C_M_DMA_SAFE); + return i2c_transfer_buffer_flags(client, (void *)buf /* const cast */, + count, I2C_M_DMA_SAFE); }; /* Transfer num messages. @@ -166,18 +167,19 @@ i2c_smbus_write_word_swapped(const struct i2c_client *client, /* Returns the number of read bytes */ extern s32 i2c_smbus_read_block_data(const struct i2c_client *client, - u8 command, u8 *values); + u8 command, void *values); extern s32 i2c_smbus_write_block_data(const struct i2c_client *client, - u8 command, u8 length, const u8 *values); + u8 command, u8 length, + const void *values); /* Returns the number of read bytes */ extern s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, - u8 command, u8 length, u8 *values); + u8 command, u8 length, void *values); extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command, u8 length, - const u8 *values); + const void *values); extern s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, - u8 command, u8 length, u8 *values); + u8 command, u8 length, void *values); int i2c_get_device_id(const struct i2c_client *client, struct i2c_device_identity *id); #endif /* I2C */ From patchwork Tue Nov 12 20:31:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1193846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ax7gbBbq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47CKCr3ZLTz9sQp for ; Wed, 13 Nov 2019 07:31:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727275AbfKLUbk (ORCPT ); Tue, 12 Nov 2019 15:31:40 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45261 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfKLUbk (ORCPT ); Tue, 12 Nov 2019 15:31:40 -0500 Received: by mail-pg1-f194.google.com with SMTP id w11so12576648pga.12; Tue, 12 Nov 2019 12:31:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6mlu28jucR3FhUlKEOLugpYNISyaantEq1qNa01r0ZE=; b=ax7gbBbqGn/nSwxQS8lZLXMRIG8M/VjKChYXSGCcl6dD/kCer39gy70PU/p6Me/hrI le/83kDm+i9GrS2I6b5eUkFf/kKbXpaLuavjSXl31pglyUK41Dcrl3pqsSvy0EggN/WM l3Qdr5ZnoFQZtmZAzaenh8XQqnfMtqsIisGSf+vqgr1+gRWj6fX0M3esaTl0a0P7fCvU 5k/qwrt5tgHltjO0AhTBdPkjRLQTbxFmimysQKZR9uKaFJjHsvYid3b0JLA1cZ55H356 rlCMjPrHA4YZGZKVPlOjv9/ddUZj1q043uCH7yZMINzhwyW8oXe/RS6qulvlU17wit3W Wj2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6mlu28jucR3FhUlKEOLugpYNISyaantEq1qNa01r0ZE=; b=rnVWy4CMD0qTsjbzzlTYMh5yr7gOf9lOvgMyPwssi981em40WvtcsWlB8zVW/fj5Pb k9yXY2rZpyvwEN2PnBUbR0xYXCbM1LgtZ/qK9b5aS03+rhQvfrCQxSwnaLzvfqfC0iN3 hjzPSOx6NynQWXjOgxkNt2S2ocsrg0qSLyaCvvcwnTG+0efuF9Ap7jXMdkWWfs3kmCYv ChTfxbhmB7plsukogmjlkhL7cj+yrfYnzsALtgPrmwYWuhPoDi9oiiOy8bruTfNEd1Zt cwrK+ZlJ8Ukwvqaj7vZ/azjq9jILOpaE+NsDr8KmoFtbuFjogmDV6hUVPnxsxED4X2pq M5qQ== X-Gm-Message-State: APjAAAUN8Q1R0Qplw4n6/Epxvlrz8TpnM/H7anziygFtNX+vueOrfoAH v0N75qlVOorx0qlRc0Wxu9w= X-Google-Smtp-Source: APXvYqwpgKjpkHDXU54TfXMHHDvFO38zrJRNs0wsCdohYBSt2gsIQc6XdipvCdyjk5m7M0Talrpu2A== X-Received: by 2002:a65:6208:: with SMTP id d8mr20277265pgv.167.1573590699040; Tue, 12 Nov 2019 12:31:39 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id h13sm23264084pfr.98.2019.11.12.12.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 12:31:37 -0800 (PST) From: Dmitry Torokhov To: Wolfram Sang Cc: linux-iio@vger.kernel.orgi, Luca Ceresoli , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] i2c: smbus: use get/put_unaligned_le16 when working with word data Date: Tue, 12 Nov 2019 12:31:31 -0800 Message-Id: <20191112203132.163306-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog In-Reply-To: <20191112203132.163306-1-dmitry.torokhov@gmail.com> References: <20191112203132.163306-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org It is potentially more performant, and also shows intent more clearly, to use get_unaligned_le16() and put_unaligned_le16() when working with word data. Signed-off-by: Dmitry Torokhov Reviewed-by: Luca Ceresoli --- Changes in v3: - split put_unaligned_le16 into a separate patch - more call sites converted to get/put_unaligned_le16 drivers/i2c/i2c-core-smbus.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index f8708409b4dbc..7b4e2270eeda1 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "i2c-core.h" @@ -370,8 +371,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, msg[1].len = 2; else { msg[0].len = 3; - msgbuf0[1] = data->word & 0xff; - msgbuf0[2] = data->word >> 8; + put_unaligned_le16(data->word, msgbuf0 + 1); } break; case I2C_SMBUS_PROC_CALL: @@ -379,8 +379,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, read_write = I2C_SMBUS_READ; msg[0].len = 3; msg[1].len = 2; - msgbuf0[1] = data->word & 0xff; - msgbuf0[2] = data->word >> 8; + put_unaligned_le16(data->word, msgbuf0 + 1); break; case I2C_SMBUS_BLOCK_DATA: if (read_write == I2C_SMBUS_READ) { @@ -487,7 +486,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, break; case I2C_SMBUS_WORD_DATA: case I2C_SMBUS_PROC_CALL: - data->word = msgbuf1[0] | (msgbuf1[1] << 8); + data->word = get_unaligned_le16(msgbuf1); break; case I2C_SMBUS_I2C_BLOCK_DATA: for (i = 0; i < data->block[0]; i++) @@ -648,8 +647,7 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, status = i2c_smbus_read_word_data(client, command + i); if (status < 0) return status; - bytes[i] = status & 0xff; - bytes[i + 1] = status >> 8; + put_unaligned_le16(status, values + i); i += 2; } } From patchwork Tue Nov 12 20:31:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1193847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bswZwNR7"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47CKCs0VLHz9sR4 for ; Wed, 13 Nov 2019 07:31:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727312AbfKLUbm (ORCPT ); Tue, 12 Nov 2019 15:31:42 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45264 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727302AbfKLUbl (ORCPT ); Tue, 12 Nov 2019 15:31:41 -0500 Received: by mail-pg1-f194.google.com with SMTP id w11so12576686pga.12; Tue, 12 Nov 2019 12:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rv3NgB/HI4HOG6PeUsJv3rPgClgEcZt4wiNXEd63Cgw=; b=bswZwNR7sRmVA3WWoPIHeJJIu1Z4xq/oDcvC/1osBDKlvgVxOyEcZ8YgDtjf8xjusN 6Err1SFQbWaWqlRrtkdnR25r/Iec126QRoW8Rm2s079btBpfNpwAZsZTocwFMxuy18im inyMBaaV1xDfsh8kxoLqZ9JLhOYlEhTo7A9L2A33Ug7+XtbxvM43I1KUtwJvSNWzarwu 5GkQs4ytCb5OMAwZ/CVOSiJuYa3KBHJ73eR6CTsbn1TbTBjv6gSohPmXXBf6kWyrmA6s 9Svhldh1nRgCO+DaNicBNCrP78wU3/F2d3BSNSbN9MEL/69q3ZLUHL/D5G5jYTniqmt9 0VGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rv3NgB/HI4HOG6PeUsJv3rPgClgEcZt4wiNXEd63Cgw=; b=m+DcntiTIEFUdNA/i3wLZH8B1poJPuWn1PRcI7ewLha5vNJkDTAgoNrp30NwuZeBds kcJqwRb7+YzCikWGoBym93wiZWdNro0GHfeRUOM8bAFHWhnGf01wzPQyjsI383UEfBvl mvgo9VxIK8PwXQpjcfn36tqkkIilAUUVfKmNKh8qoRwG6qo5bUmQAQGdg/vzXQS3I+Po pEpQl84ONOnuyh8ndZhX/VPq2E7bvcOTH4yz+iNtXwWJ0/hni+f4zIEAIqkvdfy0u/OI QADc4mNie3tb0OXn8yMnIRU3JsHPCPDkUYuJVL8RqC1nfOYZwIEYaTt+Vn0FsTyei6RG mWew== X-Gm-Message-State: APjAAAWhJJ8M7DKj0UA0DVLkw8oDl6iZ3zjqndBn/MoahkSOO8T1t/5Q gfMEyakKXSQcSUsdnjBqqCs= X-Google-Smtp-Source: APXvYqw+QqaH2zk3DQvOgVXtpKLNg/CK4RYGmbqYsj2kGca1XXvsMOc5klvGa+NuoxuMYiI46Z7Okg== X-Received: by 2002:a62:aa0d:: with SMTP id e13mr39529400pff.214.1573590700755; Tue, 12 Nov 2019 12:31:40 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id h13sm23264084pfr.98.2019.11.12.12.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 12:31:40 -0800 (PST) From: Dmitry Torokhov To: Wolfram Sang Cc: linux-iio@vger.kernel.orgi, Luca Ceresoli , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] i2c: smbus: switch from loops to memcpy Date: Tue, 12 Nov 2019 12:31:32 -0800 Message-Id: <20191112203132.163306-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog In-Reply-To: <20191112203132.163306-1-dmitry.torokhov@gmail.com> References: <20191112203132.163306-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org When copying memory from one buffer to another, instead of open-coding loops with byte-by-byte copies let's use memcpy() which might be a bit faster and makes intent more clear. Signed-off-by: Dmitry Torokhov Reviewed-by: Luca Ceresoli Acked-by: Uwe Kleine-König --- Changes in v3: - new patch using memcpy() for moving data around drivers/i2c/i2c-core-smbus.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index 7b4e2270eeda1..bbafdd3b1b114 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -397,8 +397,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, } i2c_smbus_try_get_dmabuf(&msg[0], command); - for (i = 1; i < msg[0].len; i++) - msg[0].buf[i] = data->block[i - 1]; + memcpy(msg[0].buf + 1, data->block, msg[0].len - 1); } break; case I2C_SMBUS_BLOCK_PROC_CALL: @@ -413,8 +412,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, msg[0].len = data->block[0] + 2; i2c_smbus_try_get_dmabuf(&msg[0], command); - for (i = 1; i < msg[0].len; i++) - msg[0].buf[i] = data->block[i - 1]; + memcpy(msg[0].buf + 1, data->block, msg[0].len - 1); msg[1].flags |= I2C_M_RECV_LEN; msg[1].len = 1; /* block length will be added by @@ -436,8 +434,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, msg[0].len = data->block[0] + 1; i2c_smbus_try_get_dmabuf(&msg[0], command); - for (i = 1; i <= data->block[0]; i++) - msg[0].buf[i] = data->block[i]; + memcpy(msg[0].buf + 1, data->block + 1, data->block[0]); } break; default: @@ -489,13 +486,11 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, data->word = get_unaligned_le16(msgbuf1); break; case I2C_SMBUS_I2C_BLOCK_DATA: - for (i = 0; i < data->block[0]; i++) - data->block[i + 1] = msg[1].buf[i]; + memcpy(data->block + 1, msg[1].buf, data->block[0]); break; case I2C_SMBUS_BLOCK_DATA: case I2C_SMBUS_BLOCK_PROC_CALL: - for (i = 0; i < msg[1].buf[0] + 1; i++) - data->block[i] = msg[1].buf[i]; + memcpy(data->block, msg[1].buf, msg[1].buf[0] + 1); break; }