[PATCH] can: m_can: use us_to_ktime() where appropriate

Xichao Zhao posted 1 patch 1 month, 1 week ago
drivers/net/can/m_can/m_can.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] can: m_can: use us_to_ktime() where appropriate
Posted by Xichao Zhao 1 month, 1 week ago
The tx_coalesce_usecs_irq are more suitable for using the
us_to_ktime(). This can make the code more concise and
enhance readability.

Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
---
 drivers/net/can/m_can/m_can.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index fe74dbd2c966..32a57fbcce69 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -2214,10 +2214,10 @@ static int m_can_set_coalesce(struct net_device *dev,
 
 	if (cdev->rx_coalesce_usecs_irq)
 		cdev->irq_timer_wait =
-			ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC);
+			us_to_ktime(cdev->rx_coalesce_usecs_irq);
 	else
 		cdev->irq_timer_wait =
-			ns_to_ktime(cdev->tx_coalesce_usecs_irq * NSEC_PER_USEC);
+			us_to_ktime(cdev->tx_coalesce_usecs_irq);
 
 	return 0;
 }
-- 
2.34.1
Re: [PATCH] can: m_can: use us_to_ktime() where appropriate
Posted by Marc Kleine-Budde 1 month, 1 week ago
On 25.08.2025 17:09:04, Xichao Zhao wrote:
> The tx_coalesce_usecs_irq are more suitable for using the
> us_to_ktime(). This can make the code more concise and
> enhance readability.

Applied to linux-can-next.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |
Re: [PATCH] can: m_can: use us_to_ktime() where appropriate
Posted by Markus Elfring 1 month, 1 week ago
> The tx_coalesce_usecs_irq are more suitable for using the
> us_to_ktime(). This can make the code more concise and
> enhance readability.

Wording suggestion:
  The data structure members “rx_coalesce_usecs_irq” and
  “tx_coalesce_usecs_irq” are more suitable for using us_to_ktime()
  instead of calling ns_to_ktime().
  Thus make the code more concise and enhance readability.


Should the information “where appropriate” be replaced by the hint
“in m_can_set_coalesce()” for the summary phrase?


…
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -2214,10 +2214,10 @@ static int m_can_set_coalesce(struct net_device *dev,
>  
>  	if (cdev->rx_coalesce_usecs_irq)
>  		cdev->irq_timer_wait =
> -			ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC);
> +			us_to_ktime(cdev->rx_coalesce_usecs_irq);
>  	else
>  		cdev->irq_timer_wait =
> -			ns_to_ktime(cdev->tx_coalesce_usecs_irq * NSEC_PER_USEC);
> +			us_to_ktime(cdev->tx_coalesce_usecs_irq);
…

How do you think about to apply the following source code variant instead?

	cdev->irq_timer_wait = us_to_ktime(cdev->rx_coalesce_usecs_irq
					   ? cdev->rx_coalesce_usecs_irq
					   : cdev->tx_coalesce_usecs_irq);


Regards,
Markus
Re: [PATCH] can: m_can: use us_to_ktime() where appropriate
Posted by 赵西超 1 month, 1 week ago
> [You don't often get email from markus.elfring@web.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
>> The tx_coalesce_usecs_irq are more suitable for using the
>> us_to_ktime(). This can make the code more concise and
>> enhance readability.
> Wording suggestion:
>    The data structure members “rx_coalesce_usecs_irq” and
>    “tx_coalesce_usecs_irq” are more suitable for using us_to_ktime()
>    instead of calling ns_to_ktime().
>    Thus make the code more concise and enhance readability.
>
>
> Should the information “where appropriate” be replaced by the hint
> “in m_can_set_coalesce()” for the summary phrase?
>
>
> …
>> +++ b/drivers/net/can/m_can/m_can.c
>> @@ -2214,10 +2214,10 @@ static int m_can_set_coalesce(struct net_device *dev,
>>
>>        if (cdev->rx_coalesce_usecs_irq)
>>                cdev->irq_timer_wait =
>> -                     ns_to_ktime(cdev->rx_coalesce_usecs_irq * NSEC_PER_USEC);
>> +                     us_to_ktime(cdev->rx_coalesce_usecs_irq);
>>        else
>>                cdev->irq_timer_wait =
>> -                     ns_to_ktime(cdev->tx_coalesce_usecs_irq * NSEC_PER_USEC);
>> +                     us_to_ktime(cdev->tx_coalesce_usecs_irq);
> …
>
> How do you think about to apply the following source code variant instead?
>
>          cdev->irq_timer_wait = us_to_ktime(cdev->rx_coalesce_usecs_irq
>                                             ? cdev->rx_coalesce_usecs_irq
>                                             : cdev->tx_coalesce_usecs_irq);
>
>
> Regards,
> Markus

Thank you for your suggestions. I have incorporated them and sent the 
second version of the patch.


Regards,

Xichao Zhao

Re: [PATCH] can: m_can: use us_to_ktime() where appropriate
Posted by Vincent Mailhol 1 month, 1 week ago
Hi Xichao,

Thanks for the patch!

On 25/08/2025 at 18:09, Xichao Zhao wrote:
> The tx_coalesce_usecs_irq are more suitable for using the
> us_to_ktime(). This can make the code more concise and
> enhance readability.
> 
> Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>

Reviewed-by: Vincent Mailhol <mailhol@kernel.org>


Yours sincerely,
Vincent Mailhol