Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1724575pxb; Fri, 20 Aug 2021 12:20:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2VeMXji7WgKw1Vgf2meOJH+v76S8su7pwDOPb7BT2dIeU2rK3GbEngk0v2iftREBxC/VD X-Received: by 2002:a05:6402:3099:: with SMTP id de25mr23854951edb.36.1629487203394; Fri, 20 Aug 2021 12:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629487203; cv=none; d=google.com; s=arc-20160816; b=W3jqDjaJe09ypi8WFXjY9tS/S5aAaBuq+SyuCy0x2eZHTE/GmLw2RPYp/oAF6Mjd+C zU6+Ydp5FP3U++6jd+fLNZeYi6WpAom2Lohh1nQHFVMd2mgvqf8+gx1y004BW4Q81Sch Ie75Q/OpompPtMzo6YhSpl3gLJuNdyoss3Q/dxDM1iMBKEtWfn7g9ALUsG75J8LbF2VS 4LQZkXR3HYYtEhhIxsfUOnDkyM9VhadB6qFBIbnSuTKq7bQMtBoN5ehIbgDIRsA1bGMh FbHLjjBNfUYm4R3HdhekzK7tDZragz4Asla6QfTSJe2d/ehOgeTfvlzxBPJab3Ua/ujB Yokg== 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=yb6bnKhOc9+gxx5x6SczajCd0sry7xBboXJ9PwvGMsI=; b=mWFvtP2RJ+ICxj6lf3S6Bnk4hJckRY9L9Fzq0euwEWP0cGBBGlUM/5KeZoI4zeMTeB A/BPTSgsmmtSkNyDK6AVK63ac8j5xsqRhMSEXenP5iewkNgQ9Vpj6+FhwaE1UDVif8oh xeiLq7lWLzxEEwkpMqHUheSDvVDB2eng962+OmbKlyVFSrS+MRKBAz5qBXG8A9cD3WXt eFKQ8nyqKTIAW6TjFPs0x1vr2Fw3nOrCvhUVBo4LFxMNu71B1nusDR+QVmY34KMZbAS1 sGe8KLFZOhDoadHBIA01Ps106RV64VZFKrDWpoE43hM6D6wpyce3kmGAz7KLPW/8xM+7 mu+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sR8bZqMr; 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 y19si7297838edv.6.2021.08.20.12.19.36; Fri, 20 Aug 2021 12:20:03 -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=sR8bZqMr; 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 S238061AbhHTTSk (ORCPT + 99 others); Fri, 20 Aug 2021 15:18:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236654AbhHTTSd (ORCPT ); Fri, 20 Aug 2021 15:18:33 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41113C061575; Fri, 20 Aug 2021 12:17:55 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id jv8so6083103qvb.3; Fri, 20 Aug 2021 12:17:55 -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=yb6bnKhOc9+gxx5x6SczajCd0sry7xBboXJ9PwvGMsI=; b=sR8bZqMrBNE+TiH5qENySn5XAG7Uaam+WvV2837eME4b5k9UjUOE9Bi/etvlpn1dKW e5EonlIKrFYGv1DS/aeq8TXG4r+ISBswKLsnO+7TRM+Yi1hwuhBTtbjH3rvxZOIj6M8V wVC7ljRx4TzFr3v1DtqZ0GZXnDELCIy3iuShIzdpm/s8aKVd1fO8XCoLFEUejR4ZbU7Z sP3ecnFl94GXozoO7tb3KLl9mK2yHbIYrhqfntx8hCxfrP6Y6Wwow1ls6OcxL+7BVJzg +mbagkmtNVMbjrDtFoDwOwFpGfHvuGtBB4h/dKag4kNLHRsztHTFHNqzlToTOObbfOo3 FtYw== 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=yb6bnKhOc9+gxx5x6SczajCd0sry7xBboXJ9PwvGMsI=; b=YQAxF0o7FAhx/eyRcpI8sAyDJxsOVsp57Lyt4LZ1gmHmo6pJC6Crijt71vpvdounE5 fd73VHUOR5UVUG6j/pFMtzabowtRYtZ+zQljtjPWzUC7fdBAmYQvV5yynEySlGDgjL5b KCJHBEkxrPtvnTGjuysHx1Z9wBxDs56Q6EvBvv04KyO71uba7p6qYkNjF+y4YR3Rk+jZ 7t6eUvcaM8qH6YL6A8sawV2++Jbn8HfFE+HpU1dcPt2bbfy6KQMzLJCs+pulLmWTrTby oAe/CJJzo5WdSpP4Us9tj8wx+a9PESnccn02tA60YAkFs6OgptSRn6HwBb9u13S9SApl MwMQ== X-Gm-Message-State: AOAM5338b4U4jV46DqqfwpWrV12uVp6onMDJcR7W2v5/gNTelOBnT5eC +qHydkZAM2pObmPc3z9dYeI= X-Received: by 2002:ad4:438e:: with SMTP id s14mr21716393qvr.26.1629487074532; Fri, 20 Aug 2021 12:17:54 -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.53 (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 02/14] iio: inkern: apply consumer scale when no channel scale is available Date: Fri, 20 Aug 2021 15:17:02 -0400 Message-Id: <20210820191714.69898-3-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 no channel scale is available, it's assumed that the scale is one and the raw 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: adc8ec5ff183 ("iio: inkern: pass through raw values if no scaling") Signed-off-by: Liam Beguin --- drivers/iio/inkern.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index b752fe5818e7..b69027690ed5 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -590,10 +590,10 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, IIO_CHAN_INFO_SCALE); if (scale_type < 0) { /* - * Just pass raw values as processed if no scaling is - * available. + * If no channel scaling is available apply consumer scale to + * raw value and return. */ - *processed = raw; + *processed = raw * scale; return 0; } -- 2.32.0.452.g940fe202adcb