Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5116013pxv; Tue, 20 Jul 2021 20:12:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws0OWnirkdB2WlsOiTTE4YRnxFyEMuIDHR00mh+NpvI+HaTI2W1eQqJI6uaxT+pN09ZXwY X-Received: by 2002:a05:6e02:1d89:: with SMTP id h9mr9729424ila.46.1626837167567; Tue, 20 Jul 2021 20:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626837167; cv=none; d=google.com; s=arc-20160816; b=S4wBRphNI5ZkcDA5t98I/Tf01UD1DYgQpye+5p6vSKtQCGni4WDztjrMYul1KMSTub rQt3iJWbq6jJc3FPiSzT/oRVokI3smCFxYct+0usdhsE+nF6XyhBDbOhyhqhQawAlu18 fzQrJB1ZPszso7z5SpzNm8Cb2Yqi469VceQ7rMBl+5znrQDCwe8G7mC9lnyiqWMpnGUN 2lhy698Ip1fWCnx5pEORJu0cfcClXjcuEdgED4hMKyS83FICXQqnrstp7FVJ6xZdUmUy wkaudb620/VjjFO63lTZso4z2s4qONm+GhbskuBRTfPpFSjaZKzmbktSUCJ9TqalVqdB KfVQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aLIjEv3Y3XGxT5C/sRBa0wIugXh2Hwubx4IA7LHkqcs=; b=z1wM3hUNEIpVk8xwzLbw+5W/+VSPPozRhhcUwAb97EKkpRdVbukxrFCF9pNWM5hGG8 HSS9dHt8MxUCOUQOv3z2wWUeSAna8zJQ0y3dC19nZqRkcrosuqSEkEqqEOmuKbBPO5Bv 1DXkvcOdlIcsDm1hzF68fxAf3PRfWvO9MulmNWlC8tcVxZLpN9tsrPh38FbJQGZr5sHX 6etxO72bPCNjXfc8ADAgB9WzHrK21GNwhPA4mAh5mcTPSmK06NOiHZgphH4JZgAh4pay H5D/4/N76stNHQwCHT86j9cBDmiohcMb2VzbawrGuUbmMTurvsMYmR92zeqkAclwSfb9 h/Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LQE4Y14d; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s1si24421448jar.29.2021.07.20.20.12.36; Tue, 20 Jul 2021 20:12:47 -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=@gmail.com header.s=20161025 header.b=LQE4Y14d; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231912AbhGUC05 (ORCPT + 99 others); Tue, 20 Jul 2021 22:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbhGUC0Y (ORCPT ); Tue, 20 Jul 2021 22:26:24 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A6B7C061762; Tue, 20 Jul 2021 20:07:01 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id o31so306795qvo.1; Tue, 20 Jul 2021 20:07:01 -0700 (PDT) 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=aLIjEv3Y3XGxT5C/sRBa0wIugXh2Hwubx4IA7LHkqcs=; b=LQE4Y14dktjeNg5+WJ5Yv8IXF2bJwzDDhOIJtWOvBucLM0aeie/s+V5AxnrmAS0nsd S+x/I2YCVMSMQhR6/FEhNZAuP1lkxZbLuW4OEjoLDZAKWmR6i9Rg9C/gjQTcBeRvha5J yCV+l2EBsZMiKa6h2dL/zoXcDDRtHE1GSoWNtjAAC/HSovnjtRlNNEmqh73PIeNkDRJ3 3IVOQp4TexIsOIfp3xvnC1P6NeF3MsLyMB0ZytxqhV3wws+7jqewbpPV/lAM1/9N8Gwq liP0U//BZZOYHbzgn2AvVNv3aQ9F80fbdF53D/7onL0KEfe0CRzmA8j0QykM6R6rIzUl pQBQ== 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=aLIjEv3Y3XGxT5C/sRBa0wIugXh2Hwubx4IA7LHkqcs=; b=lBc54INnC1ACarARTTpTk6xZ+QBYGEUQ0kzZZjLsIr+U2YowlS9Ol9CEY3aQaoXbb7 /yam4pABvTFICLW2AqfRvMS64uW10vRakk4cpFtiom2kmMGvgbCy6/NogSZQIhmiozhW Bs+jfQOWjJkoQMp74kPd3UMlXLBb/mIJkMOezCudu+NxPoyOWhDEmq5SrmEAEgIaqBNp ODN3MIPi/1CPLlfcRsDBWvQIkUj0mF4ZS0AC6AUNs0jtTX//6y3SHZqiOUibGfrrIIGx sgmMoZtXxTdN2DjRpwpybOE7H3DSejGsUtLPvzR1mFQYsm4Y2M9Eg0gsqEUBaxJ0JF7s kBpA== X-Gm-Message-State: AOAM532IMsBqSBQWfLB7JosFw0xzQZ6V5XkcjCkno9Cu6FcfHGWGkn8x soh3FFT+lqzVrSZLcRkF9GI= X-Received: by 2002:a05:6214:1941:: with SMTP id q1mr33142166qvk.35.1626836820699; Tue, 20 Jul 2021 20:07:00 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id g76sm10561024qke.127.2021.07.20.20.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 20:07:00 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v6 01/13] iio: inkern: apply consumer scale on IIO_VAL_INT cases Date: Tue, 20 Jul 2021 23:06:01 -0400 Message-Id: <20210721030613.3105327-2-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210721030613.3105327-1-liambeguin@gmail.com> References: <20210721030613.3105327-1-liambeguin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liam Beguin When a consumer calls iio_read_channel_processed() and the channel has an integer scale, the scale channel scale is applied and the processed value is returned as expected. On the other hand, if the consumer calls iio_convert_raw_to_processed() the scaling factor requested by the consumer is not applied. This for example causes the consumer to process mV when expecting uV. Make sure to always apply the scaling factor requested by the consumer. Fixes: 48e44ce0f881 ("iio:inkern: Add function to read the processed value") Signed-off-by: Liam Beguin --- drivers/iio/inkern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 391a3380a1d1..b752fe5818e7 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -599,7 +599,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, switch (scale_type) { case IIO_VAL_INT: - *processed = raw64 * scale_val; + *processed = raw64 * scale_val * scale; break; case IIO_VAL_INT_PLUS_MICRO: if (scale_val2 < 0) -- 2.30.1.489.g328c10930387