Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4643481pxj; Wed, 12 May 2021 09:55:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu5r5B7ghipJf00UNZM0QD/wxhaltTdRq5LgYozzN/VaoRKEc3GH245K6C60724Pzf+MSM X-Received: by 2002:a17:906:f285:: with SMTP id gu5mr39356300ejb.226.1620838531146; Wed, 12 May 2021 09:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620838531; cv=none; d=google.com; s=arc-20160816; b=gRpQER8ImpHF6sdnZSTcaMBkrByBBcbcMVqc77iAj+M4pjZrepx9a4d5OH58jYo/PT YeGbR3rw1m/GbzaLar0rtwxWztLxnnLnNheEr/P58qlYXViv5ADDdvzZP/poubmzmTOV ZjFcYQtLhpbmoI9L3IAAcWxjS/rrgWdy6Q+YVBAITgLjyU1RCjMXmAsuIb5IQjfDhU/G azOKV6SzBbDy+u3/nHBoKgxeo5wrA/3WGqgmynzj7/faF1mMp8UOKV2lc9sfg7cAXrCX FwPSTZk5/Pxjk/fM4Yr5P79M4ggm7MGCmchSZVo9pqxbrAK8Hp0gCI+DpoLGDKFJw/Th MeVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XgAAcARWP8HlMxNMOCcjeuLhWPCL1PxmoM4KW8ig5zY=; b=aN8dbxaAQOVXNEtQauRkkvjYUuCLaHJ+grUTE08jbIq9X/ScxaT5PdiKh97smJ2Zes 71Uv8LkMfwT0BkB6LYWglfxuBLLwnQTpehCSp/xOSNbGZgM3sHb+EgrkiqQ8K3tTBaD3 21Um+Fos3E04AaPcaZ3eauIgVSAtIFQ+vxq8eROhLLuM9nE74JyTiL1IvGD+ew446yca E8gFDdEdKOgsi6w20W5VV6oRG81CXcMOg/Gj17mp7JZfF2dBkMMQ1255o7UDm0i8kMAc yuiQ5d48BlD49+wSUQfff31tNWXlHl9t+q2o1grQs3Je2TzaAjbhAItUwo17iIDhW3o/ X4/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YuaOtGtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si558484ejj.270.2021.05.12.09.54.50; Wed, 12 May 2021 09:55:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YuaOtGtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234030AbhELQxp (ORCPT + 99 others); Wed, 12 May 2021 12:53:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:35232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234631AbhELPx2 (ORCPT ); Wed, 12 May 2021 11:53:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92EDB61A30; Wed, 12 May 2021 15:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833229; bh=QV7btfncQy9QQprHhRopxGlYBVqVLNPEZ2QdZWFugK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YuaOtGtrcGjcp9n2rS/cNQuW8m3kPvUWmcaZqN88z+AeWqXNfY/WLEdw7dnZH1wXS xTFt3oODDvko/HUV79qiSX12arurkVPDG62mzc+82aaMKml3rXb8z6mTC9tl7WXF0u fEQILGLfhV3mKZPK9eHVUjfZh4n2V7gz2zBygzWs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Jean-Baptiste Maneyrol , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.11 034/601] iio: inv_mpu6050: Fully validate gyro and accel scale writes Date: Wed, 12 May 2021 16:41:51 +0200 Message-Id: <20210512144828.948770684@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lars-Peter Clausen commit e09fe9135399807b8397798a53160e055dc6c29f upstream. When setting the gyro or accelerometer scale the inv_mpu6050 driver ignores the integer part of the value. As a result e.g. all of 0.13309, 1.13309, 12345.13309, ... are accepted as a valid gyro scale and 0.13309 is the scale that gets set in all those cases. Make sure to check that the integer part of the scale value is 0 and reject it otherwise. Fixes: 09a642b78523 ("Invensense MPU6050 Device Driver.") Signed-off-by: Lars-Peter Clausen Acked-by: Jean-Baptiste Maneyrol Link: https://lore.kernel.org/r/20210405114441.24167-1-lars@metafoo.de Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -723,12 +723,16 @@ inv_mpu6050_read_raw(struct iio_dev *ind } } -static int inv_mpu6050_write_gyro_scale(struct inv_mpu6050_state *st, int val) +static int inv_mpu6050_write_gyro_scale(struct inv_mpu6050_state *st, int val, + int val2) { int result, i; + if (val != 0) + return -EINVAL; + for (i = 0; i < ARRAY_SIZE(gyro_scale_6050); ++i) { - if (gyro_scale_6050[i] == val) { + if (gyro_scale_6050[i] == val2) { result = inv_mpu6050_set_gyro_fsr(st, i); if (result) return result; @@ -759,13 +763,17 @@ static int inv_write_raw_get_fmt(struct return -EINVAL; } -static int inv_mpu6050_write_accel_scale(struct inv_mpu6050_state *st, int val) +static int inv_mpu6050_write_accel_scale(struct inv_mpu6050_state *st, int val, + int val2) { int result, i; u8 d; + if (val != 0) + return -EINVAL; + for (i = 0; i < ARRAY_SIZE(accel_scale); ++i) { - if (accel_scale[i] == val) { + if (accel_scale[i] == val2) { d = (i << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); result = regmap_write(st->map, st->reg->accl_config, d); if (result) @@ -806,10 +814,10 @@ static int inv_mpu6050_write_raw(struct case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ANGL_VEL: - result = inv_mpu6050_write_gyro_scale(st, val2); + result = inv_mpu6050_write_gyro_scale(st, val, val2); break; case IIO_ACCEL: - result = inv_mpu6050_write_accel_scale(st, val2); + result = inv_mpu6050_write_accel_scale(st, val, val2); break; default: result = -EINVAL;