From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796356305; b=w2H85NjmmOEqzF2LiAmtrEGG6TAF+RxojpuahXJGb3yrL86fTwJLxAkedyRMwBLfXcQN quNI/isthGupZIc7/Gnys0abslp3RaTqSqaA/TmhCK13JVJfAgaciZx7HnQgOi36DEwCT lzwhvBZVpfvoEvIvEGlTRBUxDEfyi+MoykgPYEuGHAKzhnX8AlTXCuPcXr6LXbgf9Am6f 5UpChDQNy8a/Eew92LkU/1W6l75WeXXfJEve6Dr3AVnE9mqoWNHWPn3Y4w6yl6HFRAQcc 9rgHw/espvbwfEcL5yook8wCdsRNkLgtIcZIED4U9j07gO1rqktZ/Qz2fLzyM+zc27Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356305; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=CgGSGU6ktg1S+8n8P81DT52FyF9z9VB32qhSRhF7N1k=; b=ZPaxcdL7fqeqLs/GsEbx7ZH1ITLhOs4H82Je4iSeNxe14wgpMOtvtLbEPNAny5HU31S+ 0GeZ0LUWU7dzQTuJ25cEf0jXueEPloJR1trWNRZQ9SzIDCRweWUKZTp42LSIlD+KnjSBy TDrgGU88TyzD6nehpJMoeG3cmZaY0EPiKyzvqz8hSpEpVUaWtS3LPkNL81tVTB1eYE4gF iEfrkACM+PqSTVXEEZCQfCDZUoGP1GwSAbtegjiDtsXB/MrfpEBxcQagaA1NM4lOQwi5n ohyXl6ooHEuA71a8xO31UowhQsTCydeqCiZ/5sVMXMX5Q8RoPw0EH3DHmMnqZXmAVpg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JWTteMxa; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9B21606A33B; Fri, 4 Dec 2026 03:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JWTteMxa Received: by smtp.kernel.org (Postfix) with ESMTPSA id B82D41F00933; Fri, 4 Dec 2026 03:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796356305; bh=CgGSGU6ktg1S+8n8P81DT52FyF9z9VB32qhSRhF7N1k=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=JWTteMxaR0/9+A17T3o3Dhk1182f02aWyKcoDqfbiYEOTf96PjeOPxo+bzd/tGUn4 MMU+jzg8BeWfmWYuX2S31OaWvgxabtt4O+K5lCIYwZ9VgpvP7sP0EM2JYWHhafROxw jRGsmOIsuudLnjGMXWdfdkqvNuPvY4SJLbzC4ZVktKZU4MxZ8aUKynkcQdKq6YHBKq c21PuyAUMEYYOPxZF/acp6wxS624aAjWRVBsDkRnyx8Uph/I+etmFxyGVZPyZCw/+f dXH5X0WkFMuKRXlnTv3mEXiCqG9bV6TiGrpIpNK2A65tty2uK87IJeseo4Eh/ZW1bI yIHOKyrkS7ZwA== Subject: Re: [PATCH can-next v4 3/6] can: bittiming: can_calc_bittiming(): harden bitrate error calculation on unsigned operands From: netdev-bot+sashiko@kernel.org To: mkl@pengutronix.de Cc: mailhol@kernel.org, socketcan@hartkopp.net, wg@grandegger.com, davem@davemloft.net, kernel@pengutronix.de, linux-can@vger.kernel.org, 25031212351@stu.xidian.edu.cn, stable@vger.kernel.org, byu@xidian.edu.cn, wencheng@xidian.edu.cn, kuba@kernel.org Date: Fri, 04 Dec 2026 03:51:44 +0000 Message-ID: <179635630432.3142.3704619545620624823@kernel.org> In-Reply-To: <20261202-bittiming-fix-conversion-v4-3-fae7aaaf3191@pengutronix.de> References: <20261202-bittiming-fix-conversion-v4-3-fae7aaaf3191@pengutronix.de> X-sashiko-severity: Low Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin. Low priority / nit picks for your consideration: - [Low] The commit message describes a bug that the old code did not have. -- can: bittiming: can_calc_bittiming(): harden bitrate error calculation on unsigned operands This commit replaces abs(bt->bitrate - bitrate) with abs_diff(bt->bitrate, bitrate) in can_calc_bittiming(). The commit message says the old expression turned a wrapped unsigned difference into a small positive value, which would mis-score bitrate candidates. > Both operands are unsigned int, the subtraction may wrap instead of > becoming negative, abs() resolves an unsigned int argument to its int > branch. A wrapped difference is therefore reinterpreted as a small positive > value instead of the large error it actually represents. [Severity: Low] Is this description accurate? The kernel's abs() converts an unsigned int to int before it takes the absolute value: include/linux/math.h: #define __abs_choose_expr(x, type, other) __builtin_choose_expr( \ __builtin_types_compatible_p(typeof(x), signed type) || \ __builtin_types_compatible_p(typeof(x), unsigned type), \ ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other) Say the computed bitrate is larger than bt->bitrate by d. The subtraction wraps to 2^32 - d, the cast to int gives -d, and abs() returns d. That is the real bitrate error, not a hidden large one. The old result could only be wrong if the true difference were 2^31 or more. In can_calc_bittiming(), this check skips every candidate where tsegall * bt->bitrate overflows: if (check_mul_overflow(tsegall, bt->bitrate, &div)) continue; Any constants with tseg1_min + tseg2_min >= 1 give tsegall >= 2, and every in-tree driver table meets that. So every candidate that gets evaluated has bt->bitrate below 2^31, and bitrate = priv->clock.freq / div is at most UINT_MAX / 2. The only exception is tseg1_min == tseg2_min == 0, where tsegall can be 1. With those constants the unsigned loop condition tseg >= 0 is always true, so the loop does not end properly anyway. The later commit "can: bittiming: register_candev(): reject unusable bit-timing constants" also rejects such constants. So abs_diff() seems to give the same value as the old code on every reachable path. The word "harden" in the subject fits that. Could the body be reworded so it doesn't describe this as a fix for mis-scored bitrate candidates? As written, it could lead stable backporters to treat this cleanup as a functional fix. -- Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-bittiming-fix-conversion-v4-0-fae7aaaf3191%40pengutronix.de