Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3564C433FE for ; Mon, 13 Dec 2021 10:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242869AbhLMKZb (ORCPT ); Mon, 13 Dec 2021 05:25:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236799AbhLMJrb (ORCPT ); Mon, 13 Dec 2021 04:47:31 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4108CC079797; Mon, 13 Dec 2021 01:42:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0BC26B80E18; Mon, 13 Dec 2021 09:42:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56C49C00446; Mon, 13 Dec 2021 09:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1639388522; bh=NACCOnpFH/fqVhRjnaKfKiKtOkk/l0MAx+6x3w3GFpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cWECs0kxHcimyvPwkX8X7g1A57DFNdu3KRuIwrXQBR5URTkqPcanJ1obtUD/Tm2zm Nqh9X6ZBP/RbFS24E8RkgviPQMHxy//kJorYAsVrGI/RbuyeSF4mvIORJ7OhDeWphU 1rg2cZ3ygaObmwLvrtSogCqFGNj0jOqPTC7NykoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gwendal Grignou , Eugen Hristev , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.19 66/74] iio: at91-sama5d2: Fix incorrect sign extension Date: Mon, 13 Dec 2021 10:30:37 +0100 Message-Id: <20211213092932.999801985@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211213092930.763200615@linuxfoundation.org> References: <20211213092930.763200615@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gwendal Grignou commit 652e7df485c6884d552085ae2c73efa6cfea3547 upstream. Use scan_type when processing raw data which also fixes that the sign extension was from the wrong bit. Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Fixes: 6794e23fa3fe ("iio: adc: at91-sama5d2_adc: add support for oversampling resolution") Signed-off-by: Gwendal Grignou Reviewed-by: Eugen Hristev Cc: Link: https://lore.kernel.org/r/20211104082413.3681212-9-gwendal@chromium.org Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/at91-sama5d2_adc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -1375,7 +1375,8 @@ static int at91_adc_read_info_raw(struct *val = st->conversion_value; ret = at91_adc_adjust_val_osr(st, val); if (chan->scan_type.sign == 's') - *val = sign_extend32(*val, 11); + *val = sign_extend32(*val, + chan->scan_type.realbits - 1); st->conversion_done = false; }