Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1634308ybc; Wed, 13 Nov 2019 01:49:36 -0800 (PST) X-Google-Smtp-Source: APXvYqz6F9H/Emx39fWmbyOvnz9Kz1ik9QLpjTgRLTqRvraSSr/mAhRtCdymNwgvy+V6wJepwfHl X-Received: by 2002:a05:6402:142c:: with SMTP id c12mr2501599edx.96.1573638576844; Wed, 13 Nov 2019 01:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573638576; cv=none; d=google.com; s=arc-20160816; b=ZlxRKxnOfQkGTiY1uzXd0qKdtH1RIJ23p4ASCPZh3dQTu8T+Ea3uZoUjKSG1aVUuCA Cf6hXtgP4q7rbCWseotZUk3sjhDniiVckNMu/Aobk1R7lRswg9cSt0i17c7MxHkuINY0 1W3wp3IilhNw2FrNr08hBJbtZMNBOsFhn0eUEtdzclfjH0YXdpNpK0JcB7T8PmQJJHEK 32TeEdvzR/YrllQK9iIh3yaFqT1Ps+F2ffTs9KV//XlfsoGcph1KAzH+c2oN0F4+fTgD F1d/sbIaBsfUP/hccWlhJPc7/RiA2TW7G6s070DahVhmU4JkuWRqVmrZJB+182Ujpgdb BitA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=psPjEeoCWhTDofZDcELS/oPRNvufTW67VXJPr3z1PAw=; b=Hspqx2W2jE9M52D0Dm/gWq66503svzFrsjL/bB7KGhIjrLYh+Z5Uw4dRHoKtJfvFol 3PRhah1ASiWMB59YgrrqeC0k+DO2yHOa8x02T+w6joZ29WR9Jv5hJXCxpnmmmIBCflX6 m4/8CpQ92yg7Xw8rBnAca+X0gMQYfPtbPOy4OUqCwc2CYuCWzPJaZ50rlUFFKvtXigpZ 47qJDj8FDjFt+Rg/hs3tRJaMQZeBpEbb8ls4zMMDHQ75hxvIyHqT4ASj6daATVVkvsh9 rADfTqCYLsrqO78NTEkelnf5bgf49uPOD0MmuMau2cr/cvnU4y/Zugs39U9OjXxB2PiL ScuA== ARC-Authentication-Results: i=1; mx.google.com; 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 cc20si898504edb.201.2019.11.13.01.49.12; Wed, 13 Nov 2019 01:49: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; 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 S1727656AbfKMJrp (ORCPT + 99 others); Wed, 13 Nov 2019 04:47:45 -0500 Received: from hostingweb31-40.netsons.net ([89.40.174.40]:52155 "EHLO hostingweb31-40.netsons.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbfKMJrp (ORCPT ); Wed, 13 Nov 2019 04:47:45 -0500 Received: from [109.168.11.45] (port=55108 helo=[192.168.101.73]) by hostingweb31.netsons.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1iUpFW-001uD5-H9; Wed, 13 Nov 2019 10:47:42 +0100 Subject: Re: [PATCH v3 2/3] i2c: smbus: use get/put_unaligned_le16 when working with word data To: Dmitry Torokhov , Wolfram Sang Cc: linux-iio@vger.kernel.orgi, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org References: <20191112203132.163306-1-dmitry.torokhov@gmail.com> <20191112203132.163306-3-dmitry.torokhov@gmail.com> From: Luca Ceresoli Message-ID: <099e8f9c-354a-8756-a79b-e66c72d36aa7@lucaceresoli.net> Date: Wed, 13 Nov 2019 10:47:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191112203132.163306-3-dmitry.torokhov@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dmitry, On 12/11/19 21:31, Dmitry Torokhov wrote: > 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 > > --- > > 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); Well, msgbuf1 cannot be unaligned, so it looks like you just need to convert little endian to host endian. Perhaps __le16_to_cpu(msgbuf1) is better (and equally or more efficient). > @@ -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; > } I've been pondering on this one, because 'i' is always an even number. But, depending on the caller, 'values' could be unaligned, thus put_unaligned_le16() is OK here. -- Luca