[PATCH v2] can: m_can: use us_to_ktime() in m_can_set_coalesce()

From: Xichao Zhao
Date: Mon Aug 25 2025 - 22:51:57 EST


Replace the if-else statement with a ternary operator to
set cdev->irq_timer_wait. Use us_to_ktime() instead of
ns_to_ktime() with NSEC_PER_USEC multiplication. Simplify
the assignment of cdev->irq_timer_wait by combining
conditional checks into a single line.

Signed-off-by: Xichao Zhao <zhao.xichao@xxxxxxxx>
---
v2: Simplify code. Modify title and content.
---
drivers/net/can/m_can/m_can.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index fe74dbd2c966..d4621346e76a 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -2211,13 +2211,9 @@ static int m_can_set_coalesce(struct net_device *dev,
cdev->tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
cdev->tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
cdev->tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
-
- if (cdev->rx_coalesce_usecs_irq)
- cdev->irq_timer_wait =
- ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC);
- else
- cdev->irq_timer_wait =
- ns_to_ktime(cdev->tx_coalesce_usecs_irq * NSEC_PER_USEC);
+ cdev->irq_timer_wait = us_to_ktime(cdev->rx_coalesce_usecs_irq ?
+ cdev->rx_coalesce_usecs_irq :
+ cdev->tx_coalesce_usecs_irq);

return 0;
}
--
2.34.1