From patchwork Tue Mar 24 13:10:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 228868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78214C43331 for ; Tue, 24 Mar 2020 13:18:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 52501208CA for ; Tue, 24 Mar 2020 13:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585055897; bh=fgCakXjwGY+rUhPIQxjVi1O2wIJkX+bF8EbPDUz0qfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0Q1yitqQVFUohXe8015P4i3BWnODT5jyh4mbw1JC1MiFQ6gEzFkP9f4Ca7c5rSM15 RxOxZrd10YHJ48QpLYhz8nbKxUqz0UYicQGtrVFvWqKPaQ4TCdKtUZoILeAmuOl/Yj NPiP/M65TQFCpTBUwFXveLVXIGBawJQ1RM7yMuZs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728690AbgCXNSQ (ORCPT ); Tue, 24 Mar 2020 09:18:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:38342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728701AbgCXNSP (ORCPT ); Tue, 24 Mar 2020 09:18:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DAE6D208CA; Tue, 24 Mar 2020 13:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585055894; bh=fgCakXjwGY+rUhPIQxjVi1O2wIJkX+bF8EbPDUz0qfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vLfvnR1GURgpfapItce9trVLHOv+8ql6cbbdVAapUtr/qzMDMEef3iMDFtxMoohiA zSMKObCbDWgZU69dvF99JloTF4U2Va8zrgmD0+4+NhFKHM9rEJGUzGLrHjOaAJG3Ye yBsrdKjt8pHV/Qzo9K7kXupF5ueISreCJSqWWXUQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephan Gerhold , Linus Waleij , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.4 060/102] iio: magnetometer: ak8974: Fix negative raw values in sysfs Date: Tue, 24 Mar 2020 14:10:52 +0100 Message-Id: <20200324130812.757689015@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200324130806.544601211@linuxfoundation.org> References: <20200324130806.544601211@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Stephan Gerhold commit b500c086e4110829a308c23e83a7cdc65b26228a upstream. 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. Fixes: 7c94a8b2ee8c ("iio: magn: add a driver for AK8974") Signed-off-by: Stephan Gerhold Reviewed-by: Linus Waleij Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/magnetometer/ak8974.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/iio/magnetometer/ak8974.c +++ b/drivers/iio/magnetometer/ak8974.c @@ -564,7 +564,7 @@ static int ak8974_read_raw(struct iio_de * 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; }