From nobody Wed Apr 1 12:32:17 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83E343EAC75; Tue, 31 Mar 2026 08:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774947055; cv=none; b=Jj2VCKWdZSO+jk+4A6kIBs6vZrSBdwy902cBghLH35ZQzfOOYS3Zy511N44ypCUz+Z/jN7707biMU+pIpPGxk/4y2GAgh/MkPT0rxTOJAlai5KYiwR6tETmVex2qcgJbAX/eYwtwt+GWLpx9vB8m2HOOXf2Wvd0f55JVHNiBos0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774947055; c=relaxed/simple; bh=hEvrg1VgBxZ83vGHPoZyelEcdFEP9n7WwNRrQgglhPg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=hAHich0UAinY7TSvNyNIlqMZIgyUBW/egfn/v6v5eIH8IU1SoiLyWk8drjJJuxe/r/2lE00cWo/WBEr1s+axwCsA5TVBhuO9ZV6qEztcAR8qEBADPy3HJcGtNUbebFMhAmF8cdPJUQNmO0QeLYuzlDAUb00B3nqfUfOnqQQtwg4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=WE75VddU; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="WE75VddU" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 84B08C5994C; Tue, 31 Mar 2026 08:51:14 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D959B6029D; Tue, 31 Mar 2026 08:50:43 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 92E3E1045049D; Tue, 31 Mar 2026 10:50:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1774947043; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding; bh=g/R8nvIUjydE7o/OpG+ZQm7VsFlI0MLtO6nqskaGhjw=; b=WE75VddU4+vhxp15YnMHtJ2uohhTNkS/uJuJ76AXJ1k5PpOrGIi54sSPAbaUzPe5SwBCIK eO4tnHn2oS21KAeqStzhj1KFrSTStm/ycAxeWY175dELF6WkTucMNwKqEnEMPYqvrBBHyj h6M7c0rAiXExdJqwEppam+bz+5957gqa0Jw13xCoaXBYSqPbWc6nt+FctYx8WOLNemRg4G WQz+1avByt+94QSyKvnsUFnGGw82Cbk1dwgaFkYPcly8nB/gM447KS5gMw9d0iQuv0Nhui ySOgyUV5NvrYVVqBeESo5+cWojhvD9APFsmjAG7/OIVvYpvL3bkwo1XS20LHuw== From: Romain Gantois Date: Tue, 31 Mar 2026 10:49:59 +0200 Subject: [PATCH] iio: inkern: Avoid risky abs() usage in iio_multiply_value() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260331-iio-multiply-abs-usage-v1-1-2ae8063e80e4@bootlin.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/x2MSQqAMAwAvyI5G2graPEr4qHVqAE3GhWl+HeLx 4GZiSAUmATqLEKgi4W3NYHOM+gmt46E3CcGo0ypikIj84bLOR+8zw86L3iKS5apSqOtctarDlK 8Bxr4/sdN+74fwwiP5WgAAAA= X-Change-ID: 20260331-iio-multiply-abs-usage-2762180a8b0c To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Hans de Goede Cc: Thomas Petazzoni , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Romain Gantois X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 iio_multiply_value() passes integers val and val2 directly to abs(). This is problematic because if a signed argument to abs is the lowest value for its type, then the result is undefined due to overflow. Cast val and val2 to s64 before passing them to abs() to avoid this issue. Fixes: 0f85406bf830 ("iio: consumers: Fix handling of negative channel scal= e in iio_convert_raw_to_processed()") Cc: stable@vger.kernel.org Signed-off-by: Romain Gantois --- drivers/iio/inkern.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 0df0ab3de2709..59e8c01457f72 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -618,8 +618,8 @@ int iio_multiply_value(int *result, s64 multiplier, denominator =3D NANO; break; } - *result =3D multiplier * abs(val); - *result +=3D div_s64(multiplier * abs(val2), denominator); + *result =3D multiplier * abs((s64)val); + *result +=3D div_s64(multiplier * abs((s64)val2), denominator); if (val < 0 || val2 < 0) *result *=3D -1; return IIO_VAL_INT; --- base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f change-id: 20260331-iio-multiply-abs-usage-2762180a8b0c Best regards, --=20 Romain Gantois