On Mon, Apr 24, 2023 at 12:21:57PM -0700, Jacob Keller wrote:
> The power profile configuration options added in commit 7059a05a3fb2
> ("Introduce the power profile.") specify their maximum range as INT_MAX.
> The values are stored as UInteger32 values and the default value is
> 0xFFFFFFFF. On most platforms, a signed integer cannot hold 0xFFFFFFFF, and
> on these platforms ptp4l is unable to read the default configuration file:
> 
>   $ ./ptp4l -f configs/default.cfg -i eno0
>   0xFFFFFFFF is an out of range value for option 
> power_profile.2011.grandmasterTimeInaccuracy at line 44
>   failed to parse configuration file configs/default.cfg

Jacob,

Thanks for finding this.  I'd like to fix it in a simpler way.
Do you agree?

Thanks,
Richard

---
>From 5cfba921f9bf1f97028c5f999c399e9bb554cfd7 Mon Sep 17 00:00:00 2001
From: Richard Cochran <richardcoch...@gmail.com>
Date: Sun, 30 Apr 2023 13:32:06 -0700
Subject: [PATCH] power profile: Fix regression in the default configuration
 file.

The recently added power profile introduced a regression when reading
the default configuration file:

  $ ./ptp4l -f configs/default.cfg -m -q
  0xFFFFFFFF is an out of range value for option 
power_profile.2011.grandmasterTimeInaccuracy at line 44
  failed to parse configuration file configs/default.cfg

Root cause is the fact that the value 0xffffffff exceeds the range of
the signed, four byte integer used in the configuration logic.

Considering that the power profile's "Inaccuracy" field uses
0xffffffff as a special value meaning "unknown", expand the range
of these options to include -1 as that special value.

Fixes: 7059a05a3fb2182e851217c8872cf47126ec4c4c ("Introduce the power profile.")
Reported-by: Jacob Keller <jacob.e.kel...@intel.com>
Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 config.c            | 6 +++---
 configs/default.cfg | 6 +++---
 ptp4l.8             | 7 +++----
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index cb4421f..b104f1b 100644
--- a/config.c
+++ b/config.c
@@ -309,9 +309,9 @@ struct config_item config_tab[] = {
        GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
        GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
        PORT_ITEM_ENU("power_profile.version", IEEE_C37_238_VERSION_NONE, 
ieee_c37_238_enu),
-       PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0xFFFFFFFF, 0, INT_MAX),
-       PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
INT_MAX),
-       PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0xFFFFFFFF, 0, 
INT_MAX),
+       PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0xFFFFFFFF, -1, INT_MAX),
+       PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0xFFFFFFFF, 
-1, INT_MAX),
+       PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0xFFFFFFFF, -1, 
INT_MAX),
        PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0xFFFF),
        GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
        GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
diff --git a/configs/default.cfg b/configs/default.cfg
index a21ec66..00429b9 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -41,9 +41,9 @@ BMCA                    ptp
 inhibit_announce        0
 inhibit_delay_req       0
 ignore_source_id        0
-power_profile.2011.grandmasterTimeInaccuracy   0xFFFFFFFF
-power_profile.2011.networkTimeInaccuracy       0
-power_profile.2017.totalTimeInaccuracy         0xFFFFFFFF
+power_profile.2011.grandmasterTimeInaccuracy   -1
+power_profile.2011.networkTimeInaccuracy       -1
+power_profile.2017.totalTimeInaccuracy         -1
 power_profile.grandmasterID                    0
 power_profile.version                          none
 #
diff --git a/ptp4l.8 b/ptp4l.8
index bb678c9..09ff108 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -365,22 +365,21 @@ the interface, or the device specified by the \fB-p\fP 
option.
 Specifies the time inaccuracy of the GM in nanoseconds.  Relevant only
 when power_profile.version is 2011.  This value may be changed
 dynamically using the POWER_PROFILE_SETTINGS_NP management message.
-The default is 0xFFFFFFFF.
+The default is -1 meaning unknown inaccuracy.
 
 .TP
 .B power_profile.2011.networkTimeInaccuracy
 Specifies the time inaccuracy of the network in nanoseconds.  Relevant
 only when power_profile.version is 2011.  This value may be changed
 dynamically using the POWER_PROFILE_SETTINGS_NP management message.
-The default is 0xFFFFFFFF.
+The default is -1 meaning unknown inaccuracy.
 
 .TP
 .B power_profile.2017.totalTimeInaccuracy
 Specifies the sum of the GM, network, and local node inaccuracies in
 nanoseconds.  Relevant only when power_profile.version is 2017.  This
 value may be changed dynamically using the POWER_PROFILE_SETTINGS_NP
-management message.  The default is 0xFFFFFFFF meaning unknown
-inaccuracy.
+management message.  The default is -1 meaning unknown inaccuracy.
 
 .TP
 .B power_profile.grandmasterID
-- 
2.30.2



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to