diff mbox series

[net-next] net: lan743x: Use NSEC_PER_SEC macro

Message ID 20240902071841.3519866-1-ruanjinjie@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: lan743x: Use NSEC_PER_SEC macro | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-02--12-00 (tests: 714)

Commit Message

Jinjie Ruan Sept. 2, 2024, 7:18 a.m. UTC
1000000000L is number of ns per second, use NSEC_PER_SEC macro to replace
it to make it more readable.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/net/ethernet/microchip/lan743x_ptp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pavan Chebbi Sept. 2, 2024, 9 a.m. UTC | #1
On Mon, Sep 2, 2024 at 12:41 PM Jinjie Ruan <ruanjinjie@huawei.com> wrote:
>
> 1000000000L is number of ns per second, use NSEC_PER_SEC macro to replace
> it to make it more readable.
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/net/ethernet/microchip/lan743x_ptp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
> index dcea6652d56d..9c2ec293c163 100644
> --- a/drivers/net/ethernet/microchip/lan743x_ptp.c
> +++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
> @@ -409,7 +409,7 @@ static int lan743x_ptpci_settime64(struct ptp_clock_info *ptpci,
>                                    ts->tv_sec);
>                         return -ERANGE;
>                 }
> -               if (ts->tv_nsec >= 1000000000L ||
> +               if (ts->tv_nsec >= NSEC_PER_SEC ||
>                     ts->tv_nsec < 0) {
>                         netif_warn(adapter, drv, adapter->netdev,
>                                    "ts->tv_nsec out of range, %ld\n",
> --
> 2.34.1

Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Andrew Lunn Sept. 2, 2024, 4:26 p.m. UTC | #2
On Mon, Sep 02, 2024 at 03:18:41PM +0800, Jinjie Ruan wrote:
> 1000000000L is number of ns per second, use NSEC_PER_SEC macro to replace
> it to make it more readable.
> 
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/net/ethernet/microchip/lan743x_ptp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
> index dcea6652d56d..9c2ec293c163 100644
> --- a/drivers/net/ethernet/microchip/lan743x_ptp.c
> +++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
> @@ -409,7 +409,7 @@ static int lan743x_ptpci_settime64(struct ptp_clock_info *ptpci,
>  				   ts->tv_sec);
>  			return -ERANGE;
>  		}
> -		if (ts->tv_nsec >= 1000000000L ||
> +		if (ts->tv_nsec >= NSEC_PER_SEC ||
>  		    ts->tv_nsec < 0) {
>  			netif_warn(adapter, drv, adapter->netdev,
>  				   "ts->tv_nsec out of range, %ld\n",

https://elixir.bootlin.com/linux/v6.10.7/source/include/linux/time64.h#L92

/*
 * Returns true if the timespec64 is norm, false if denorm:
 */
static inline bool timespec64_valid(const struct timespec64 *ts)
{
        /* Dates before 1970 are bogus */
        if (ts->tv_sec < 0)
                return false;
        /* Can't have more nanoseconds then a second */
        if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
                return false;
        return true;
}

And the next question is, why is the driver checking this? It would
make more sense that the PTP core checked this before calling
ptp->info->settime64()

	Andrew
Jinjie Ruan Sept. 4, 2024, 6:33 a.m. UTC | #3
On 2024/9/3 0:26, Andrew Lunn wrote:
> On Mon, Sep 02, 2024 at 03:18:41PM +0800, Jinjie Ruan wrote:
>> 1000000000L is number of ns per second, use NSEC_PER_SEC macro to replace
>> it to make it more readable.
>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>>  drivers/net/ethernet/microchip/lan743x_ptp.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
>> index dcea6652d56d..9c2ec293c163 100644
>> --- a/drivers/net/ethernet/microchip/lan743x_ptp.c
>> +++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
>> @@ -409,7 +409,7 @@ static int lan743x_ptpci_settime64(struct ptp_clock_info *ptpci,
>>  				   ts->tv_sec);
>>  			return -ERANGE;
>>  		}
>> -		if (ts->tv_nsec >= 1000000000L ||
>> +		if (ts->tv_nsec >= NSEC_PER_SEC ||
>>  		    ts->tv_nsec < 0) {
>>  			netif_warn(adapter, drv, adapter->netdev,
>>  				   "ts->tv_nsec out of range, %ld\n",
> 
> https://elixir.bootlin.com/linux/v6.10.7/source/include/linux/time64.h#L92
> 
> /*
>  * Returns true if the timespec64 is norm, false if denorm:
>  */
> static inline bool timespec64_valid(const struct timespec64 *ts)
> {
>         /* Dates before 1970 are bogus */
>         if (ts->tv_sec < 0)
>                 return false;
>         /* Can't have more nanoseconds then a second */
>         if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
>                 return false;
>         return true;
> }
> 
> And the next question is, why is the driver checking this? It would
> make more sense that the PTP core checked this before calling
> ptp->info->settime64()

There are 2 places call ptp->info->settime64(), it may make more sense
to check timespec64_valid() here and remove these check internal like
lan743x_ptp.c?

drivers/net/phy/micrel.c:4721:          ptp->settime64(ptp, &ts);
drivers/ptp/ptp_clock.c:103:    return  ptp->info->settime64(ptp->info, tp);

> 
> 	Andrew
Andrew Lunn Sept. 4, 2024, 12:16 p.m. UTC | #4
> > And the next question is, why is the driver checking this? It would
> > make more sense that the PTP core checked this before calling
> > ptp->info->settime64()
> 
> There are 2 places call ptp->info->settime64(), it may make more sense
> to check timespec64_valid() here and remove these check internal like
> lan743x_ptp.c?
> 
> drivers/net/phy/micrel.c:4721:          ptp->settime64(ptp, &ts);
> drivers/ptp/ptp_clock.c:103:    return  ptp->info->settime64(ptp->info, tp);

Yes, please extend the core.

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
index dcea6652d56d..9c2ec293c163 100644
--- a/drivers/net/ethernet/microchip/lan743x_ptp.c
+++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
@@ -409,7 +409,7 @@  static int lan743x_ptpci_settime64(struct ptp_clock_info *ptpci,
 				   ts->tv_sec);
 			return -ERANGE;
 		}
-		if (ts->tv_nsec >= 1000000000L ||
+		if (ts->tv_nsec >= NSEC_PER_SEC ||
 		    ts->tv_nsec < 0) {
 			netif_warn(adapter, drv, adapter->netdev,
 				   "ts->tv_nsec out of range, %ld\n",