From patchwork Fri Feb 14 11:03:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 11382103 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A82E109A for ; Fri, 14 Feb 2020 11:07:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B9E9624670 for ; Fri, 14 Feb 2020 11:07:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gerhold.net header.i=@gerhold.net header.b="pXj0TI6c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729007AbgBNLHj (ORCPT ); Fri, 14 Feb 2020 06:07:39 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.53]:29979 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728982AbgBNLHj (ORCPT ); Fri, 14 Feb 2020 06:07:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1581678457; s=strato-dkim-0002; d=gerhold.net; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=YyDFw5TguckXzOIfpbwtA2u8J5qqnlddwqEV2aVIVII=; b=pXj0TI6c/JHfP90Jtqe0BESLqhKoyQO3oicet4w16l92yZntRKja5V5OMK7cZfpdZc 8RDXDxVsBhEvrKZoQA5Yjw37AtYWW7t4t/LBi6Y7EZK9xLwcC0Xx0KH/rnFajfgqUttG uI867Kfvp/DOvbkft/Lb8ExewOh9xOTBctPTQ3+TQYMt52wRkswus6nUy4vXHFxhfnPN inK3y9gO24mrwZtnpaPHmD8kKtd4eGGGO8SWdBUHyOL/bIFLe6KNVit1agnHpemqoSLK MakWYLP8RGMq9Y7FuI1yJ3N97FrLQjLMd6oz86wP/0RKGQCI1IaERpeHxvPZpvtcmyPZ Rc6g== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXQrEOHTIXucnvtxFRYw==" X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain by smtp.strato.de (RZmta 46.1.12 AUTH) with ESMTPSA id a01fe9w1EB4bPG0 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Fri, 14 Feb 2020 12:04:37 +0100 (CET) From: Stephan Gerhold To: Jonathan Cameron Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, Nick Reitemeyer , Stephan Gerhold , Linus Walleij Subject: [PATCH] iio: magnetometer: ak8974: Fix negative raw values in sysfs Date: Fri, 14 Feb 2020 12:03:24 +0100 Message-Id: <20200214110324.70972-1-stephan@gerhold.net> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org At the moment, reading from in_magn_*_raw in sysfs tends to return large values around 65000, even though the output of ak8974 is actually limited to ±32768. This happens because the value is never converted to the signed 16-bit integer variant. Add an explicit cast to s16 to fix this. Cc: Linus Walleij Fixes: 7c94a8b2ee8c ("iio: magn: add a driver for AK8974") Signed-off-by: Stephan Gerhold Reviewed-by: Linus Waleij --- drivers/iio/magnetometer/ak8974.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c index fc7e910f8e8b..d32996702110 100644 --- a/drivers/iio/magnetometer/ak8974.c +++ b/drivers/iio/magnetometer/ak8974.c @@ -564,7 +564,7 @@ static int ak8974_read_raw(struct iio_dev *indio_dev, * We read all axes and discard all but one, for optimized * reading, use the triggered buffer. */ - *val = le16_to_cpu(hw_values[chan->address]); + *val = (s16)le16_to_cpu(hw_values[chan->address]); ret = IIO_VAL_INT; }