From patchwork Tue Nov 26 23:40:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 13886440 Received: from sonic306-21.consmr.mail.ir2.yahoo.com (sonic306-21.consmr.mail.ir2.yahoo.com [77.238.176.207]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26DBB322A for ; Wed, 27 Nov 2024 00:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.238.176.207 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732665662; cv=none; b=it3NVUm51zGSbFcWNVoUIQiWt5OhJypjD207md9QRrUhPXKUoCStTygcGJFDeVNEDw/0uqft7fzjQ7HSNGyFNWqWP/f/6Xq0kHHY+FJvsJMXI2YZZgHit6mfbzsdR6awlCcG/J5k/r09V/7dykhBDcJAkUShEQeSXMv/g75wFkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732665662; c=relaxed/simple; bh=wSnTftQjXX6IVevyMrORMn78ByIlh5J0F8vJt1MQnXk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:References; b=UroVwahQBygWeiQOfLkO56TzZwI0cimb4xyU/jkh6b21dcOCaZH/cBnNQmtYpkKsAsml5FkOVmicDad6i1ymhRGcipR7GYsasOdcTSB0OAEVSTb9LmgwmaWVGJT2elbbggrJbXfbl7i6on7HSbwXMrG7dd5eHm4/RGIeFm3fNOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=rocketmail.com; spf=pass smtp.mailfrom=rocketmail.com; dkim=pass (2048-bit key) header.d=rocketmail.com header.i=@rocketmail.com header.b=ETUKRSIe; arc=none smtp.client-ip=77.238.176.207 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=rocketmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rocketmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rocketmail.com header.i=@rocketmail.com header.b="ETUKRSIe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1732665658; bh=MgL+Y0R2nrnBm7+Isag/O8JP2FWkBIMIsTL0WZZiGH0=; h=From:To:Cc:Subject:Date:References:From:Subject:Reply-To; b=ETUKRSIeupNEVKjktPxYwY9EaMcEDSMNGMXKydJzTDQOQMbtRH68J2raVMjpSh99LBz8IPwqYczXMGNIF4jCU8wpeRuCO1IwaxaMnqVV8KDLRvcr+95v9RqYteg6s3CLqlybKC/90miL60cGlz7oS/5eYADtDBHjTxW8HwcEBMuz+WcMBnnM+BuQIICBxqECLHccEhbhoySiFsXe3dUpS3mUtwhJMTLImhg3SvFUry/k5oMBKEMGDHN4VTGOvYQLtzyTlXDnxzA0KiUpc0eaFxwzJlFRxHoqK72kGezvoM4VVfvJRt1bN2/qQcXuLE+Er0chyuGKmM7FSonzgC8qdg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1732665658; bh=P8frwMjJHijWeYSd8SvffR9oIrKOskb5WgXm/+dJ3s/=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=EKUg7TWguw3SKOvpcrxbW3ds0uanPDf7N9V/yvY4BRdwciO1MEJ18q9oBuLAsXBgZtMwUKsT6FRlupm9DhDTWUio+CHOSLBTOU1ndX7fSGGzyrbu/xpmhn1AQlRX//k1GNjAXVl5xoyvUhZanjUWuC6VxkeOk4yNrGYwX1b8AYRa+snymoyhYGMOtdIzNSnakMoWjRQUIgUhIL5Gx7eOGqHekzWt777XPasrQcIl30Y10xV4tvCsremA9tITB7eNNfiuvhHlriZDmyogIv9oe8NR+TMWV5fRj+HMG5EINgZ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aRkmOEIvjLm5gbwCaR981m6hy1iHJn Pey6gumWXbzG7e5YVWziw9XR5.MCf5OFQByW.QlOZmsT7JfkLQJuT4VLqk_uJl9jcUSt2iPzHFkr angyWaHh5Wfr3qozEXz9Zehn9rAdzT1YPzywF62TsHgrl0ENeXNxnc5OlhOPqKrfNTYNmbzj.FdQ oK4XguY8PxzCtNnctAseOkxDK_CTDaBW1MgNrLHYVuB4pk.3Kg8ixtHiE9fpjTCfeTe5eypKcz7p DChlbRRJdFGCrnUh3Y4xUDu.XfvoQhQDCmWkctFRjVQ-- X-Sonic-MF: X-Sonic-ID: f08bebbc-9d09-4fe1-97ea-51ff3b275371 Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Wed, 27 Nov 2024 00:00:58 +0000 Received: by hermes--production-ir2-c694d79d9-qp6kn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID d91172f74165254868bee18e8bab607a; Tue, 26 Nov 2024 23:40:38 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron , Lars-Peter Clausen Cc: David Laight , Linus Walleij , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jakob Hauser , kernel test robot Subject: [PATCH] iio: magnetometer: yas530: Use signed integer type for clamp limits Date: Wed, 27 Nov 2024 00:40:21 +0100 Message-Id: <20241126234021.19749-1-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20241126234021.19749-1-jahau.ref@rocketmail.com> In the function yas537_measure() there is a clamp_val() with limits of -BIT(13) and BIT(13) - 1. The input clamp value h[] is of type s32. The BIT() is of type unsigned long integer due to its define in include/vdso/bits.h. The lower limit -BIT(13) is recognized as -8192 but expressed as an unsigned long integer. The size of an unsigned long integer differs between 32-bit and 64-bit architectures. Converting this to type s32 may lead to undesired behavior. Declaring a signed integer with a value of BIT(13) allows to use it more specifically as a negative value on the lower clamp limit. While at it, replace all BIT(13) in the function yas537_measure() by the signed integer. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202411230458.dhZwh3TT-lkp@intel.com/ Fixes: 65f79b501030 ("iio: magnetometer: yas530: Add YAS537 variant") Cc: David Laight Signed-off-by: Jakob Hauser --- The patch is based on torvalds/linux v6.12. The calculation lines h[0], h[1] and h[2] exceed the limit of 80 characters per line. In terms of readability I would prefer to keep it that way. --- drivers/iio/magnetometer/yamaha-yas530.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 65011a8598d3..938b35536e0d 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -372,6 +372,7 @@ static int yas537_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y u8 data[8]; u16 xy1y2[3]; s32 h[3], s[3]; + int half_range = BIT(13); int i, ret; mutex_lock(&yas5xx->lock); @@ -406,13 +407,13 @@ static int yas537_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y /* The second version of YAS537 needs to include calibration coefficients */ if (yas5xx->version == YAS537_VERSION_1) { for (i = 0; i < 3; i++) - s[i] = xy1y2[i] - BIT(13); - h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / BIT(13); - h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / BIT(13); - h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / BIT(13); + s[i] = xy1y2[i] - half_range; + h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / half_range; + h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / half_range; + h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / half_range; for (i = 0; i < 3; i++) { - clamp_val(h[i], -BIT(13), BIT(13) - 1); - xy1y2[i] = h[i] + BIT(13); + clamp_val(h[i], -half_range, half_range - 1); + xy1y2[i] = h[i] + half_range; } }