From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D740C432C3 for ; Mon, 18 Nov 2019 07:37:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 582D4206F4 for ; Mon, 18 Nov 2019 07:37:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbfKRHhD (ORCPT ); Mon, 18 Nov 2019 02:37:03 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:52091 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726607AbfKRHhC (ORCPT ); Mon, 18 Nov 2019 02:37:02 -0500 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iWbal-0005qx-Ti; Mon, 18 Nov 2019 08:36:59 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1iWbal-0006MR-7C; Mon, 18 Nov 2019 08:36:59 +0100 Date: Mon, 18 Nov 2019 08:36:59 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Dmitry Torokhov Cc: Wolfram Sang , linux-iio@vger.kernel.orgi, Luca Ceresoli , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/3] i2c: smbus: use get/put_unaligned_le16 when working with word data Message-ID: <20191118073659.7yomkvqthuenqjpu@pengutronix.de> References: <20191112203132.163306-1-dmitry.torokhov@gmail.com> <20191112203132.163306-3-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191112203132.163306-3-dmitry.torokhov@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Dmitry, On Tue, Nov 12, 2019 at 12:31:31PM -0800, 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); You claim this was clearer. For me it is not. With the explicit assignment to msgbuf0[1] and msbbuf0[2] it is immediatly obvious to me what happens. Even though the endianness is explicitly mentioned in put_unaligned_le16, it takes a bit longer for me to understand what it does and which part of data->word ends up in which byte. Concerning the "potentially more performant" part: I wonder if this is backed by numbers and if it is indeed benificial on some platforms if this is a compiler problem. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |