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=1796173660; b=wkXhwBHOjektBSeuoG1IGPKBkzOLpiKC8enJRL0PefVZ/hQiIlssS3QWGyMPZYNenXF9 DTtf98n8Xf1psQRZgH+PpNgByN56o9hYoHv0iEUeT6TPW9FUk5jS5Fz35BfBrYterzAZs 0gfAz/lRlRFZ/YF3ZnSqQmiV86dvF9aNJMNSTtH6ebFMlqhHs+R6Lh1zZOuv9YnMn4C/9 AdshyMZaEEx0/rjZRm0Psjk2xRzfB3pbclmEog7za1C2Fty5kiQCSNGFCIiDhkXqNn6QL Uy+4+Z8qnvM0MP97pm1NXbBvtygRF/+VZ0yeQ/qWvgl9nCf8WzBKA4SDh0JaTGYKnRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796173660; 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=NsHNKzftoAde8QbMEuuvH3TAuTIY81QnaPCNEOwZjI0=; b=l0kl8T+C/1pEkGcw0RV7zAwDQT8hT6sk1J9a43CTiSLBVFz6FHUDrYItcQK1IX7Ek0SP 85CNjSE4nca+Ge379c7q9iyftNT0HnHrs3ecqlNHzWIqokILZRpyJGaQ13TPPmIpJHklu e3Frd7Oo1UrsZ4711dZbzgRImGCtJhUqx3n5s/8k3f5NESk0IQHipSK5ZgvrBsDZvijbJ /t60UZuJqEk2WxWS6OfDilzrgsbh4AMLgFfu5PleTfLFbtX66mte3m+fJ71+3BC9Pe73C EEfkUMj8GhAp46A0wCJR4Yzud73US1TqJKysXMIntHVUg0pzjkF6LhWRuYCHcL0A1EA== 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=hItwxKU5; 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 3C49D606A31A; Wed, 2 Dec 2026 01:07:39 +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=hItwxKU5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C7271F000C1; Wed, 2 Dec 2026 01:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796173659; bh=NsHNKzftoAde8QbMEuuvH3TAuTIY81QnaPCNEOwZjI0=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=hItwxKU5LpgoieJ0z4dkVbq746/5Bhzr5haUZpiD1jLTNvHMJk+25DOjFTcCG9/NE 56NkZIUVe28QzdyZwJ0ND18ATeC7PwWvHobX8oLVf9hZfEGYGOzo0/uyRA7hIzXCnc nKNKmUI3khyHxg4xncsm8haNc0hJFOZ4KqTyEBAk5RtG6Y60V0OvaJbD1m34Z1wS0H M7SEyJsb1YXed8zpPAUCwXxemnURkgTCv4U4C+zNDCarYWedui6xBV9YvEjFZyry3c oSLH1/vb7jSVylV+1ix3jNR/ahQQrYG1NsFIGiyWbSHBIB6AjnZcsgUsBaku9ePT6S SHn2zznYZlkBw== Subject: Re: [PATCH can-next v2 3/4] can: bittiming: can_update_sample_point(): fix sample point 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, ssureshmsd7@gmail.com, 25031212351@stu.xidian.edu.cn, stable@vger.kernel.org, byu@xidian.edu.cn, wencheng@xidian.edu.cn, kuba@kernel.org Date: Wed, 02 Dec 2026 01:07:38 +0000 Message-ID: <179617365866.3142.11965848914227822369@kernel.org> In-Reply-To: <20261130-bittiming-fix-conversion-v2-3-36e8a0275923@pengutronix.de> References: <20261130-bittiming-fix-conversion-v2-3-36e8a0275923@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 claims a bug that does not exist. -- can: bittiming: can_update_sample_point(): fix sample point error calculation on unsigned operands This commit changes the sample point error calculation in can_update_sample_point() from abs(sample_point_reference - sample_point) to abs_diff(sample_point_reference, sample_point). The commit message says the old code turned a wrapped unsigned difference into a small positive value instead of a large error. > Both operands are unsigned int, so the subtraction wraps instead of > becoming negative, and 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] This isn't a bug, but is this description accurate for can_update_sample_point()? For an unsigned int argument, abs() in include/linux/math.h does this: ({ signed type __x = (x); __x < 0 ? -__x : __x; }) So a wrapped result such as 875 - 880 becomes (int)-5, and abs() returns 5. That is the correct magnitude, not a misrepresented error. The magnitude would only come out wrong if the real difference were larger than INT_MAX. > diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c > index 2789b99ab6a83..f081819fd8f90 100644 > --- a/drivers/net/can/dev/calc_bittiming.c > +++ b/drivers/net/can/dev/calc_bittiming.c > @@ -73,7 +73,7 @@ can_update_sample_point(const struct can_bittiming_const *btc, > > sample_point = 1000 * (tseg + CAN_SYNC_SEG - tseg2) / > (tseg + CAN_SYNC_SEG); > - sample_point_error = abs(sample_point_reference - sample_point); > + sample_point_error = abs_diff(sample_point_reference, sample_point); > > if (sample_point <= sample_point_reference && > sample_point_error < best_sample_point_error) { Also, sample_point_error is only used inside this guarded branch. There, sample_point <= sample_point_reference holds, so the unsigned subtraction cannot wrap. When sample_point > sample_point_reference, the value is thrown away. Only best_sample_point_error is written to *sample_point_error_ptr. sample_point_reference is also always below 1000. It comes either from bt->sample_point, which can_validate_bittiming() rejects when it is >= 1000: if (bt->sample_point >= 1000) { or from the constant tables in can_calc_sample_point_nrz() and can_calc_sample_point_pwm(). So in every case where the result is used, the old and new code give the same value. The switch to abs_diff() looks like a correct cleanup that matches the earlier bitrate error change. The rationale from that change does not seem to carry over here. Could the subject and body say this is a consistency cleanup with no functional change, rather than a fix? That would avoid stable or AUTOSEL picking it up as a bug fix. It would also avoid suggesting that sample point selection was broken before. -- Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-bittiming-fix-conversion-v2-0-36e8a0275923%40pengutronix.de