Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4581677pxj; Wed, 12 May 2021 08:37:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzug36ENAmoLa3GaHsBavX+E41KqpxnlKCNFJBlx9xweL2gwG7E0/GDBSs61UHYjIAkbjvU X-Received: by 2002:aca:428b:: with SMTP id p133mr26115296oia.22.1620833871898; Wed, 12 May 2021 08:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620833871; cv=none; d=google.com; s=arc-20160816; b=Bz+mYSsVJcd50tx9MOB5MrlCNVHxmJMACGiM+TaWAttzrWNdUpe2OE2exbaXbcJSGp 3InhNYNLsiaR7mbDwAsqph6UKAVTEgCd9/n9IGuHfG0TPiep2bfSgdo00G8gqxI0Ygmz A5DHTUBXpFQnHrFTi3WtHcoG2TS90ZTBAG8lCnZgQ1uj6mtVRnq+/1yrkcGJwhmCXyxY cjiCjHbZNGaS7PRCORm5RiZlRm7fNP7+A6piEqUSgF1WxM1IdrJSwYgEdF/ILjrKPfkp aJUl8tSBG+kVZxf0a5NjdGe3A39XMvHckaD1aXnJQD13C7Iv/baLDsm7EAafjWY61S0W niPQ== 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=tFZtLPTcEUWGx2akzeoBBY+Gga7M4QqV7zXSyEsNw/bYfvnZrMel3fZKI7me6sexmj 0mS8p0uS0xabminIKZkJsGxvwDSYMZ2HMsBciA3HIGoDTAiNANnC3RcnCx7wOwF3C5WP xSasCypYWWT0gIHrb/jt9WGJZGtU7EKVIQgQBOdiYBJM2aYzIq1wcuMei8TbcarWSeqe PnhTI0LV6gcdI6yScNfWbKg0j7ioKIUxCWx7o4Peb8OgBmj78JP/CMUSUFqvuca/VUWy CNo+EbYg2AYVD7emvxNgOeHs+YIe2yDhE3daPThwgdVrB3xNwVGKgHOAz6yx8zUeiUHG rCrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C1Ki4oNn; 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 b128si264439oif.208.2021.05.12.08.37.38; Wed, 12 May 2021 08:37:51 -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=C1Ki4oNn; 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 S234281AbhELPdQ (ORCPT + 99 others); Wed, 12 May 2021 11:33:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:47290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbhELPPv (ORCPT ); Wed, 12 May 2021 11:15:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 263EC6147F; Wed, 12 May 2021 15:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620831920; bh=QV7btfncQy9QQprHhRopxGlYBVqVLNPEZ2QdZWFugK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1Ki4oNno5hea2I3/FiQ3oELjn4LJ0lE8/eYcvtQlRWiIYEvQz9N9YRfxfcHjLjIp yOIoGK4xJGNfppao3BOt8JNT3jOylwRfM8M5EZBaqbrUf/Rl1LYqE/ypMfpmh9AFY7 FOhRxYIoUsuHjbIIx4MrbfciB2CZkwUsRJT/Qrvc= 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.10 034/530] iio: inv_mpu6050: Fully validate gyro and accel scale writes Date: Wed, 12 May 2021 16:42:24 +0200 Message-Id: <20210512144820.859630482@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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;