From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 D734D3ED5A5; Tue, 31 Mar 2026 09:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774949415; cv=none; b=c9wSwvvDWLoL7U9/vxOhJkR/QIxcC/1NASt+7FL4YhcdDEMVd6A+kq9GkDQ8Am6pOTpJHAnyTKqUaoMj+yYvnojAB9F1IsVkxILBoJ7tgS5D1rbmO8mOEoZDSWrdDTxvVlRfMiP/jp7I677mb4ygMDKlhPtqY84eSK/5LOM74X8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774949415; c=relaxed/simple; bh=UEz/OQmSllDsOy58O8YQZbqPNXDtYx/bKKEhUktDTYg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tVq6b1Ucflbj/PqVINga4n4DGY4pSumbs8maRX+MOxexRztDIjh0joPRw4lEceTk83LzEn/6saOgHoPEMew3yNndv1yzaoZCw9KeCgqfXNU/JkwEpMfBzV4tSYkoh0wG1/4J4HAFb7dk2V1neAs3JeVT8+Ew6PXic5NcNp4S/08= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SncsGh0w; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SncsGh0w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774949414; x=1806485414; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=UEz/OQmSllDsOy58O8YQZbqPNXDtYx/bKKEhUktDTYg=; b=SncsGh0wWd0XHR8tbgJkHoTnFptKPkjPy8BkHhzbXAIPFI4D6B6lMQyM +XU7+rT1JvS5X6+I4BydG2fRAwScZkQinuCFo8iHrryOL6lSEPJitpXic 6VblCHX9nCZVfcMGwDJVVC89WbF3GoSQXL5UzryiBz7tQX+8ZJyNNTkD+ JK7RBLEpWZVP5W4BrUkECyGmqcyyYw6Rx0qC9VVO4D9e18SVvVMRqe4cN FqLXwCAlzdjPAXj2XnNma22pTEHmSqMRGo0HgW1HpKxO4Wgqbxi1naB0D wtc1MfL/ufH9jXvHryIhmO+KaRt5bxS0uw/3B0jox3bzG2GRzyzlovLan w==; X-CSE-ConnectionGUID: jxefE6LbR+O9SVzE5KsdzQ== X-CSE-MsgGUID: y9l9LswTRrKtRxT0cGyDww== X-IronPort-AV: E=McAfee;i="6800,10657,11744"; a="79853660" X-IronPort-AV: E=Sophos;i="6.23,151,1770624000"; d="scan'208";a="79853660" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2026 02:30:13 -0700 X-CSE-ConnectionGUID: AomyzBWqRryNz1403a34Kw== X-CSE-MsgGUID: Qp6cuHuLSqurunGs+wgbXA== X-ExtLoop1: 1 Received: from rvuia-mobl.ger.corp.intel.com (HELO localhost) ([10.245.245.209]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2026 02:30:11 -0700 Date: Tue, 31 Mar 2026 12:30:08 +0300 From: Andy Shevchenko To: Romain Gantois Cc: Jonathan Cameron , David Lechner , Nuno =?iso-8859-1?Q?S=E1?= , Andy Shevchenko , Hans de Goede , Thomas Petazzoni , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] iio: inkern: Avoid risky abs() usage in iio_multiply_value() Message-ID: References: <20260331-iio-multiply-abs-usage-v1-1-2ae8063e80e4@bootlin.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Tue, Mar 31, 2026 at 12:29:28PM +0300, Andy Shevchenko wrote: > On Tue, Mar 31, 2026 at 10:49:59AM +0200, Romain Gantois wrote: > > 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. ... > > - *result = multiplier * abs(val); > > - *result += div_s64(multiplier * abs(val2), denominator); > > + *result = multiplier * abs((s64)val); > > + *result += div_s64(multiplier * abs((s64)val2), denominator); > > Right, but here we get val and val2 from either static values from the driver > (when it is SCALE channel), or when channel has PROCESSED support. > In the latter one it might theoretically be possible to go till the INT_MIN, > but practically I don't know how, except for the broken driver code in the > first place. With that being said, I think it's better to validate somewhere > the multipliers (when it's SCALE or PROCESSED channel). I also noted that > for the _PROCESSED some drivers keep a garbage in val2. That probably needs > to be addressed as well (exempli gratia: bmi270_read_raw() does that). And start from the test cases actually. -- With Best Regards, Andy Shevchenko