Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp175890pxv; Wed, 30 Jun 2021 18:02:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyN1R2Ifa41P97Z9ROo4an7c1Hqt6kDNM2WNBOswXtnlYut6CGuMRZrhbsnrIuAR4vmAU/O X-Received: by 2002:a05:6e02:bed:: with SMTP id d13mr26350969ilu.259.1625101357435; Wed, 30 Jun 2021 18:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625101357; cv=none; d=google.com; s=arc-20160816; b=FUoL26vYv+D5mPIpp9y30F1p0K2ooP/3oUGZlLInwA5pOcxpQpLlZVXJSnilNoOpMH 1sMZKDOfWNTrDZX0enFtJJeQMZk0b4BdVCkGHc/DHrNibSoQJEkj9aEjjuzBewlKUQka 46GGlMxhbp9uNGQpXPA9efDAIP1a/bM3pWYvm27SL6vHvtQldt9Th2kKhSEX9XQgNXua uFh65mqs6va1EV/gCwBxCQdDy8FYEU10ugeEIQ1bvhNoTOaaKQGj52kop1R1MdQp4C5T qM6Y21QG/r58Gb12+SnK9k1MxXZwPAaVGRqP1vmP+iBHpk39kJx9JRDDhAvib0rZSmXD Ea5w== 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=A2fa7/Drb5sXP307sl/K40N+qGxwjHrlv8kHhST8hiVZTKhS7cUWZDSHen28tRf1uM rR78ZZoAYFs1XhB4E7CPVnZAz8ObUecXWeQTYtLqORzWPLFbMKJ/qobpZJ8rKN9wF8WY DZDTbtJ0Ax8lllFYu7/gefquKgOQFyPv8F5WrL2kJtdOgQvompGLBoyo/c9f3XAT3CKa /f2KwjmmwFv5ccA7JokreAPl5LnfU8touFkLE/zIadxW2y+PN9FTUVzaojzEzG4nTzfw 4bKFCGHVKq1qiXq1Iyg7YDJ8RLxIzjJ7pD+YdTCdmF9LfrNdi4aliMOgHH1QltrW9aAN +IZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=abeBQ7HD; 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 x9si26478434jaf.48.2021.06.30.18.01.53; Wed, 30 Jun 2021 18:02:37 -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=abeBQ7HD; 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 S238274AbhGABDT (ORCPT + 99 others); Wed, 30 Jun 2021 21:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232066AbhGABDS (ORCPT ); Wed, 30 Jun 2021 21:03:18 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19268C061756; Wed, 30 Jun 2021 18:00:48 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id dj3so2127771qvb.11; Wed, 30 Jun 2021 18:00:47 -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=abeBQ7HDze70AzrZWLTyi/x0HPTwfGhKphNcgOT8r7VAkeLghAo2c5uxwnmmWMLZAY AGd2TI8mW6gja4AjQeqnzq5pDS8fVVUvHXfLvGtTB1MvlNpSKrfLyWdB2FLAbcVQNJ5f ZWyJhcRBaqOWrU6DxLVPOc58Tud1NCer9EjcWTzwnxFGZPrVi4GJhNZSIsYJ2ZQwtVdd 3RDXjKz7oD0nd2iMjWrjuhpxdm7Jhtcab2a40eSzUF1DtqRVVoL1yEI3Xilb4VxfLZ7f uAXvN5RNVJxQ4T3XxQRrjwc6AKY02TmQQ0eojkVwEr0hpmoUgRk9H4q5kIHkvE6/FzRD XyaQ== 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=eumO9YpWvc0qGdP2Vv20ukSKPbYb1zViaecDIEnZItwqdTvDIOB/kVhfkg+nfzgYrF jbisWcr8b+KE3ls7CRMKLqMTCK8ASgQPl63mEn6QeuM5UtCKMBgdNZM2MUqXNaeSHULZ 5bJaiyv/Lh+ga6wdjwfc4Iq+RLpjlclkt0ew/tfzuxbXy2S5tEzAQHZyPCFHEsu6+2wm ugWxGnWSQHXhIM1uvYuo0DhvSbLW7e9od2DWkAaZkcllbYxQFP1v//f2knD/1yhNxXuN 5gwROEKdgDdLVSc2Tw++4pQYe5SETtFtv9kQQ1w6Z/gjnRceithbtLBKij9SC7Zj2Q2s KBQw== X-Gm-Message-State: AOAM533yLVVKqrCK2C7l3SL/ZwlGGoiItW6dpC8qnphDnHpvopGa787D +zje0kdg5Qq1LYzJeieSerk= X-Received: by 2002:a0c:9e49:: with SMTP id z9mr39578031qve.52.1625101247172; Wed, 30 Jun 2021 18:00:47 -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 l127sm14087782qkc.64.2021.06.30.18.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 18:00:46 -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 v3 01/10] iio: inkern: apply consumer scale on IIO_VAL_INT cases Date: Wed, 30 Jun 2021 21:00:25 -0400 Message-Id: <20210701010034.303088-2-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210701010034.303088-1-liambeguin@gmail.com> References: <20210701010034.303088-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