From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752792AbcE2P1X (ORCPT ); Sun, 29 May 2016 11:27:23 -0400 Received: from saturn.retrosnub.co.uk ([178.18.118.26]:33191 "EHLO saturn.retrosnub.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752694AbcE2P1V (ORCPT ); Sun, 29 May 2016 11:27:21 -0400 Subject: Re: [PATCH v2 2/7] iio: inv_mpu6050: Initial regcache support To: Crestez Dan Leonard , Peter Rosin , Matt Ranostay References: <61c0fb3d-207a-c126-b80c-f1342fda5878@intel.com> Cc: "linux-iio@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Daniel Baluta , Ge Gao , linux-i2c@vger.kernel.org, Wolfram Sang , "devicetree@vger.kernel.org" , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala From: Jonathan Cameron Message-ID: <92d40b29-5c44-7307-0f25-93ee66c055ae@kernel.org> Date: Sun, 29 May 2016 16:27:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <61c0fb3d-207a-c126-b80c-f1342fda5878@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/05/16 12:01, Crestez Dan Leonard wrote: > On 05/20/2016 09:39 AM, Peter Rosin wrote: >> On 2016-05-20 04:34, Matt Ranostay wrote: >>> On Wed, May 18, 2016 at 8:00 AM, Crestez Dan Leonard >>> wrote: >>>> Signed-off-by: Crestez Dan Leonard >>>> --- >>>> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 47 ++++++++++++++++++++++++++++++ >>>> drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 5 ---- >>>> drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 1 + >>>> drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 5 ---- >>>> 4 files changed, 48 insertions(+), 10 deletions(-) >>>> >>>> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c >>>> index b269b37..5918c23 100644 >>>> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c >>>> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c >>>> @@ -116,6 +116,53 @@ static const struct inv_mpu6050_hw hw_info[] = { >>>> }, >>>> }; >>>> >>>> +static bool inv_mpu6050_volatile_reg(struct device *dev, unsigned int reg) >>>> +{ >>>> + if (reg >= INV_MPU6050_REG_RAW_ACCEL && reg < INV_MPU6050_REG_RAW_ACCEL + 6) >>>> + return true; >>>> + if (reg >= INV_MPU6050_REG_RAW_GYRO && reg < INV_MPU6050_REG_RAW_GYRO + 6) >>>> + return true; >>> >>> I think you want to put parenthesis around the addition operations... >> >> Maybe. >> >>> the condition check probably don't evaluate to what you are expecting. >> >> Looks sane to me since + has highest precedence, then < and >=, and && comes >> in last... >> >> ...but even so, I think I would use an ellipsis in the switch statement >> instead, like so: >> >> static bool inv_mpu6050_volatile_reg(struct device *dev, unsigned int reg) >> { >> switch (reg) { >> case INV_MPU6050_REG_RAW_ACCEL ... INV_MPU6050_REG_RAW_ACCEL + 5: >> case INV_MPU6050_REG_RAW_GYRO ... INV_MPU6050_REG_RAW_GYRO + 5: >> case INV_MPU6050_REG_TEMPERATURE: >> case INV_MPU6050_REG_TEMPERATURE + 1: >> case INV_MPU6050_REG_USER_CTRL: >> case INV_MPU6050_REG_PWR_MGMT_1: >> case INV_MPU6050_REG_FIFO_COUNT_H: >> case INV_MPU6050_REG_FIFO_COUNT_H + 1: >> case INV_MPU6050_REG_FIFO_R_W: >> return true; >> default: >> return false; >> } >> } > > Neat, I didn't know about this extension. It does look nicer in this > function. Be careful to use this sparingly as it does make review harder in some cases as we have to care which registers happen to numerically fall in the range. It's good for some cases though such as multiple bytes of the same 'real register'. Jonathan >