Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1000847ybc; Tue, 12 Nov 2019 12:33:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxdUJInzCYxCulLf+eim2eQGiaPEg7cCShhPZVs7qGvBrxbYAYHwcvotr+WOo3qqNZtkF+z X-Received: by 2002:a05:6402:3042:: with SMTP id bu2mr35161827edb.298.1573590810976; Tue, 12 Nov 2019 12:33:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573590810; cv=none; d=google.com; s=arc-20160816; b=DmWwJmntXObNOOIyD4bZVj15Ja33toSn/CMFacsk2tygPaFup0ObAjadrkoNfDdzc3 wDxivUshUznqQQThPDPXjJtIeVI6eTp0iURkJDl1ZgvbM6oJM4S6G/6xDei05yBOO95x j2Q8zVlPuPanK/zEbRjN66UgWtUn+cE3Irdr3VuLEIjGbwRIWeMGpYKznFkfCb/Sj7Uc oEjZu42RKes9dkMANfC/wHJmpJrn7rEoe7ql8My3nfgugaKo0VhB8hwz+rcpHboO4B/u 1CVo5AwW8q8z0vMxohTCwocz9xPQQj302Yy3Q33qDi+lxrFZycdGIu+WYD8GVBKDYs6z m6bA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6mlu28jucR3FhUlKEOLugpYNISyaantEq1qNa01r0ZE=; b=OIE8yNgDJEoURPW10G6+GkcalapvGX80fmFtkJQz+9u8WGNWf724DLtf4dS1ZGNk0U 5Ihv94DsEsPsV9NfYT7dmKw2NHKcwApBAskD/1SXqAoNTeOZ0OiirJ9MWvKO3KBrpzZe tarkinnO7A0cnlE1Lc7VD54IgAix9dvIL7/szlEeBVnxbh7qQPvv9hSoKgN7DlD0ivjE tCCZRJLkfoT0bcEsG+s1z+rhyKf45OwNi+4aGlO5sHjxegL3UIXZW+gRVC9j7F3dODNn 2VEhQiGFXyiV8NYK79UpWOSDfm6aw+k9yzoOhWRttw8VN0zYPogOnED9JhGEhgCJH4Sh 99Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ax7gbBbq; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d13si832927ejr.23.2019.11.12.12.33.06; Tue, 12 Nov 2019 12:33:30 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ax7gbBbq; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727284AbfKLUbk (ORCPT + 99 others); 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-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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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; } } -- 2.24.0.rc1.363.gb1bccd3e3d-goog