Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1724030pxb; Fri, 20 Aug 2021 12:19:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxFHZGWajVnxL8chEn5c1SwCvhHxuU4IbTgbmTiNT+SC01+O7X9xRDGec18PpePsqnZDJc X-Received: by 2002:a92:cb4b:: with SMTP id f11mr14687125ilq.189.1629487149757; Fri, 20 Aug 2021 12:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629487149; cv=none; d=google.com; s=arc-20160816; b=RUpTV9LSr5vza76vZ2LNEZutg9GADfA4mvfCTENqnQN7GI0eKorUMxrvbx2k9J7YO4 H+VW+OcNKx6b9pt/MyWnnFIk/0aZjPzQAYUd9UKpYdV16sexnQ65eD9owPQYtQSdDr8e 9JFTPMTOBCBnSPfeDx/sEKRVKxz/6/zT1CoI8jzvfcDjceLTeW/W1nVbuDHys0a5hpet DzLzuaSB+6PjKoj7+xWZ6caHZes0pkxX7OviwaHtxcRXg+FPaSHvVwk6K5lU8wm77gtG BHLzyjBBwQXSQ9cFxlxPfZMyCjZezWhWkcDtis7AACNwcxIVyZsJzwPl7c5hDGhizFD1 AlaA== 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=zjI68m1FTfjUdZFdXRsH4SrtzTIRTWjQ+J9nVQl3/gM=; b=CpeCpYFrC+hZTfDTZr32oRh/+34YnSLk5q14Flp97oXM0nmn1qU5VlhHFNXGP7QXhZ tezInjcGCIUPN4AfcB/5Kda5f7+MSMHRY/Nw/BTOnsO+VdqatPAQ/q5amWXPonTonGRN TuOf+tw0O9B5WSsmr6AjdjhmDdecbzpS5RfyQsjvTgHMSfDFnCZB9gjiM5PVz8+T28Uk 1mKgcoM3F8m5jQwtTQEg5GLuC4xegoXWYFrwwu7YP3p/5msu3Ih1cs2CyN76rKtO/BNA CNuOW+eXDQCoXm0vamsplDzDFNswDUHE4GFFvFI3iqSV90nMvu6AZCSzV+nmnrqlynrE zyeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RMxWScVp; 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 w15si8936585iov.42.2021.08.20.12.18.57; Fri, 20 Aug 2021 12:19:09 -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=RMxWScVp; 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 S237183AbhHTTSf (ORCPT + 99 others); Fri, 20 Aug 2021 15:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbhHTTSc (ORCPT ); Fri, 20 Aug 2021 15:18:32 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39370C061756; Fri, 20 Aug 2021 12:17:54 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id c14so6057201qvs.9; Fri, 20 Aug 2021 12:17:54 -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=zjI68m1FTfjUdZFdXRsH4SrtzTIRTWjQ+J9nVQl3/gM=; b=RMxWScVpPE3neU8juyICJt1HGTKsL72aDk8XFEEMY+WIyOOz27regfjg6Q9MpRk7hV +sgdqSjhlG0/xR1bg6/aOIfQvgNLJqUVIJVv3UzcUsHL98JSkys0qyppd2hgNIaXJnYN SaxmH0owmTFWA+fKz+44QkS1gq/f3bIGwMaDRH464HZ89b92MGOU5OWs0N/XFs2nky+D zj5nNXCLICCsSyowm0rKzAUt++ObXwzS3MAXp+6KJBADki5RrSGIjjjGrHW4kMM/rYG2 SDGm566kzOvBInNpyTQ3B7J5ITtw8q+2+E44W79hWdSUBy/UyvxJDCsJ4fUiXoq34OyO F/Tg== 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=zjI68m1FTfjUdZFdXRsH4SrtzTIRTWjQ+J9nVQl3/gM=; b=UAZ8ZW8nTQCKCMwmf2Z/sYkyklxpcBdwYYzJ3AxT3IrXosdnNabMverHerjWiE3EB3 rxe/FQLqwSbjs+W6yKCXNF63fMNGzv/fupGAcsW8S4haUXTReT6npA6d6hwmyq/yy8Fw y4f5lFvh3ei2N38pwx8XYJwhHDshWmNTAGcoMfmA1fbWFhWsPwX5443kbfnz3cXryl1D 2ngKjqcMOM+jcbQjwoEtCo68tKdIf94o855yAJuDoYCNi7Ha6y3t+JFprImxVNM+OFAx savDzafO9+sVyZHvym9ZFaETeZNiTVrSNpXTyJkkuLuZhThBKd4IP/S+rQA9roOXuKoV 5g7w== X-Gm-Message-State: AOAM5336nIe3qz1ILUpTp5imQPlwH9S+3VGOSjrGyLhCEFmjrGqmcrJn 4xq+Nmg88Tn5tRh7VOxozJ4= X-Received: by 2002:a05:6214:d65:: with SMTP id 5mr21856713qvs.11.1629487073450; Fri, 20 Aug 2021 12:17:53 -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 o6sm3603869qkp.111.2021.08.20.12.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 12:17:53 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v8 01/14] iio: inkern: apply consumer scale on IIO_VAL_INT cases Date: Fri, 20 Aug 2021 15:17:01 -0400 Message-Id: <20210820191714.69898-2-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210820191714.69898-1-liambeguin@gmail.com> References: <20210820191714.69898-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.32.0.452.g940fe202adcb