Re: [Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-05-11 Thread Miroslav Lichvar
On Wed, May 10, 2023 at 06:57:26PM -0700, Richard Cochran wrote:
> On Sun, Apr 30, 2023 at 01:50:34PM -0700, Richard Cochran wrote:
> > Thanks for finding this.  I'd like to fix it in a simpler way.
> 
> FWIW I am going ahead with my patch.
> 
> @Miroslav it changes the default value for one field, and so the test
> suite would need the following change.

The test is now updated. Thanks.

-- 
Miroslav Lichvar



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


Re: [Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-05-10 Thread Richard Cochran
On Sun, Apr 30, 2023 at 01:50:34PM -0700, Richard Cochran wrote:
> Thanks for finding this.  I'd like to fix it in a simpler way.

FWIW I am going ahead with my patch.

@Miroslav it changes the default value for one field, and so the test
suite would need the following change.

Thanks,
Richard

---
diff --git a/20-pmc b/20-pmc
index e585897..3d1ef27 100755
--- a/20-pmc
+++ b/20-pmc
@@ -337,13 +337,13 @@ requests_replies=(
version   0
grandmasterID 0x
grandmasterTimeInaccuracy 4294967295
-   networkTimeInaccuracy 0
+   networkTimeInaccuracy 4294967295
totalTimeInaccuracy   4294967295
123456.fffe.780102-2 seq 0 RESPONSE MANAGEMENT 
POWER_PROFILE_SETTINGS_NP 
version   0
grandmasterID 0x
grandmasterTimeInaccuracy 4294967295
-   networkTimeInaccuracy 0
+   networkTimeInaccuracy 4294967295
totalTimeInaccuracy   4294967295"
 )
 


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


Re: [Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-04-30 Thread Richard Cochran
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
> 0x. On most platforms, a signed integer cannot hold 0x, and
> on these platforms ptp4l is unable to read the default configuration file:
> 
>   $ ./ptp4l -f configs/default.cfg -i eno0
>   0x 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 
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
  0x 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 0x exceeds the range of
the signed, four byte integer used in the configuration logic.

Considering that the power profile's "Inaccuracy" field uses
0x 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 
Signed-off-by: Richard Cochran 
---
 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", 
0x, 0, INT_MAX),
-   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
INT_MAX),
-   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
INT_MAX),
+   PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0x, -1, INT_MAX),
+   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0x, 
-1, INT_MAX),
+   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, -1, 
INT_MAX),
PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
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 @@ BMCAptp
 inhibit_announce0
 inhibit_delay_req   0
 ignore_source_id0
-power_profile.2011.grandmasterTimeInaccuracy   0x
-power_profile.2011.networkTimeInaccuracy   0
-power_profile.2017.totalTimeInaccuracy 0x
+power_profile.2011.grandmasterTimeInaccuracy   -1
+power_profile.2011.networkTimeInaccuracy   -1
+power_profile.2017.totalTimeInaccuracy -1
 power_profile.grandmasterID0
 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 0x.
+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 0x.
+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 0x meaning unknown
-inaccuracy.
+management message.  The default is -1 meaning unknown inaccuracy.
 
 .TP
 .B power_profile.grandmasterID
-- 
2.30.2



___
Linuxptp-

[Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-04-24 Thread Jacob Keller
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
0x. On most platforms, a signed integer cannot hold 0x, and
on these platforms ptp4l is unable to read the default configuration file:

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

Fix this by modifying the configuration code to store the integer values
internally as long longs, which are required by the C standard, and all
platforms that Linux supports, to be at least 64bits long.

To avoid casting issues, also introduce config_get_uint to obtain these
UInteger32 values from the configuration code properly as unsigned values.

Signed-off-by: Jacob Keller 
---
 config.c | 40 +++-
 config.h |  3 +++
 port.c   |  6 +++---
 util.c   | 15 +++
 util.h   | 16 
 5 files changed, 68 insertions(+), 12 deletions(-)

diff --git a/config.c b/config.c
index cb4421f572c7..b3ba4e8bb7aa 100644
--- a/config.c
+++ b/config.c
@@ -62,7 +62,7 @@ struct config_enum {
 };
 
 typedef union {
-   int i;
+   long long i;
double d;
char *s;
 } any_t;
@@ -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", 
0x, 0, INT_MAX),
-   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
INT_MAX),
-   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
INT_MAX),
+   PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0x, 0, UINT32_MAX),
+   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
UINT32_MAX),
+   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
UINT32_MAX),
PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
@@ -559,8 +559,8 @@ static enum parser_result parse_item(struct config *cfg,
enum parser_result r;
struct config_item *cgi, *dst;
struct config_enum *cte;
+   long long val;
double df;
-   int val;
 
r = parse_fault_interval(cfg, section, option, value);
if (r != NOT_PARSED)
@@ -576,7 +576,7 @@ static enum parser_result parse_item(struct config *cfg,
 
switch (cgi->type) {
case CFG_TYPE_INT:
-   r = get_ranged_int(value, &val, cgi->min.i, cgi->max.i);
+   r = get_ranged_ll(value, &val, cgi->min.i, cgi->max.i);
break;
case CFG_TYPE_DOUBLE:
r = get_ranged_double(value, &df, cgi->min.d, cgi->max.d);
@@ -1021,10 +1021,32 @@ int config_get_int(struct config *cfg, const char 
*section, const char *option)
case CFG_TYPE_ENUM:
break;
}
-   pr_debug("config item %s.%s is %d", section, option, ci->val.i);
+   pr_debug("config item %s.%s is %lld", section, option, ci->val.i);
return ci->val.i;
 }
 
+unsigned int
+config_get_uint(struct config *cfg, const char *section, const char *option)
+{
+   struct config_item *ci = config_find_item(cfg, section, option);
+
+   if (!ci) {
+   pr_err("bug: config option %s missing!", option);
+   exit(-1);
+   }
+   switch (ci->type) {
+   case CFG_TYPE_DOUBLE:
+   case CFG_TYPE_STRING:
+   pr_err("bug: config option %s type mismatch!", option);
+   exit(-1);
+   case CFG_TYPE_INT:
+   case CFG_TYPE_ENUM:
+   break;
+   }
+   pr_debug("config item %s.%s is %lld", section, option, ci->val.i);
+   return (unsigned int)ci->val.i;
+}
+
 char *config_get_string(struct config *cfg, const char *section,
const char *option)
 {
@@ -1141,7 +1163,7 @@ int config_set_section_int(struct config *cfg, const char 
*section,
if (!section) {
cgi->flags |= CFG_ITEM_LOCKED;
cgi->val.i = val;
-   pr_debug("locked item global.%s as %d", option, cgi->val.i);
+   pr_debug("locked item global.%s as %lld", option, cgi->val.i);
return 0;
}
/* Create or update this port specific item. */
@@ -1153,7 +1175,7 @@ int config_set_section_int(struct config *cfg, const char 
*section,
}
}
dst->val.i = val;
-   pr_debug("section item %s.%s now %d", section, option, dst->val.i);
+   pr_debug("section

Re: [Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-04-13 Thread Jacob Keller



On 3/29/2023 1:42 PM, Erez wrote:
> On Wed, 29 Mar 2023 at 20:36, 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 in UInteger32 values, and the default 0x is
>> outside the range of a 32-bit integer. Because of this, on platforms which
>> have 32-bit integers, ptp4l is unable to read the default configuration:
>>
> 
> Just thinking.
> Why not move to unsigned 64 bits?
> It can solve future limitations.
> I would also change the int to signed 64,
>  but I can understand it may require too many changes in the code.
> 
> Erez
> 

I have no idea of the values being stored need to be 32bit or not.
However, I think we can migrate our internal "config value storage" to a
signed 64bit to allow us to keep track of all the possible unsigned
32bit values. We could make CFG_TYPE_INT be a s64 and then just have the
range check limit to 32bits without needing to add an extra unsigned
type. (unless we ever want to have a full 64bit unsigned value..)

That's probably better than this patch.

Thanks,
Jake

>>
>>   0x is an out of range value for option
>> power_profile.2011.grandmasterTimeInaccuracy at line 44
>>   failed to parse configuration file configs/default.cfg
> 
> 
>> These values are unsigned and stored as fixed width values of 32 bits.
>> Correct the configuration specification to allow the true maximum of an
>> unsigned 32 bit integer.
>>
>> Signed-off-by: Jacob Keller 
>> ---
>> I'm not sure if there is a simpler or better way to fix this. We could just
>> update the range of CFG_TYPE_INT to be long (or long long) instead, which
>> would give it a range big enough to cover all our current values...
>>
>>  config.c | 54 +++---
>>  config.h |  3 +++
>>  port.c   |  6 +++---
>>  3 files changed, 57 insertions(+), 6 deletions(-)
>>
>> diff --git a/config.c b/config.c
>> index cb4421f572c7..baf8352538ea 100644
>> --- a/config.c
>> +++ b/config.c
>> @@ -51,6 +51,7 @@ enum config_section {
>>
>>  enum config_type {
>> CFG_TYPE_INT,
>> +   CFG_TYPE_UINT,
>> CFG_TYPE_DOUBLE,
>> CFG_TYPE_ENUM,
>> CFG_TYPE_STRING,
>> @@ -63,6 +64,7 @@ struct config_enum {
>>
>>  typedef union {
>> int i;
>> +   unsigned int u;
>> double d;
>> char *s;
>>  } any_t;
>> @@ -109,6 +111,14 @@ struct config_item {
>> .min.i  = _min, \
>> .max.i  = _max, \
>>  }
>> +#define CONFIG_ITEM_UINT(_label, _port, _default, _min, _max) {\
>> +   .label  = _label,   \
>> +   .type   = CFG_TYPE_UINT,\
>> +   .flags  = _port ? CFG_ITEM_PORT : 0,\
>> +   .val.u  = _default, \
>> +   .min.u  = _min, \
>> +   .max.u  = _max, \
>> +}
>>  #define CONFIG_ITEM_STRING(_label, _port, _default) {  \
>> .label  = _label,   \
>> .type   = CFG_TYPE_STRING,  \
>> @@ -125,6 +135,9 @@ struct config_item {
>>  #define GLOB_ITEM_INT(label, _default, min, max) \
>> CONFIG_ITEM_INT(label, 0, _default, min, max)
>>
>> +#define GLOB_ITEM_UINT(label, _default, min, max) \
>> +   CONFIG_ITEM_UINT(label, 0, _default, min, max)
>> +
>>  #define GLOB_ITEM_STR(label, _default) \
>> CONFIG_ITEM_STRING(label, 0, _default)
>>
>> @@ -137,6 +150,9 @@ struct config_item {
>>  #define PORT_ITEM_INT(label, _default, min, max) \
>> CONFIG_ITEM_INT(label, 1, _default, min, max)
>>
>> +#define PORT_ITEM_UINT(label, _default, min, max) \
>> +   CONFIG_ITEM_UINT(label, 1, _default, min, max)
>> +
>>  #define PORT_ITEM_STR(label, _default) \
>> CONFIG_ITEM_STRING(label, 1, _default)
>>
>> @@ -309,9 +325,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",
>> 0x, 0, INT_MAX),
>> -   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0,
>> INT_MAX),
>> -   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy",
>> 0x, 0, INT_MAX),
>> +   PORT_ITEM_UINT("power_profile.2011.grandmasterTimeInaccuracy",
>> 0x, 0, UINT32_MAX),
>> +   PORT_ITEM_UINT("power_profile.2011.networkTimeInaccuracy", 0, 0,
>> UINT32_MAX),
>> +   PORT_ITEM_UINT("power_profile.2017.totalTimeInaccuracy",
>> 0x, 0, UINT32_MAX),
>> PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
>> GLOB_ITEM_INT("priority1", 

Re: [Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-03-29 Thread Erez
On Wed, 29 Mar 2023 at 20:36, 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 in UInteger32 values, and the default 0x is
> outside the range of a 32-bit integer. Because of this, on platforms which
> have 32-bit integers, ptp4l is unable to read the default configuration:
>

Just thinking.
Why not move to unsigned 64 bits?
It can solve future limitations.
I would also change the int to signed 64,
 but I can understand it may require too many changes in the code.

Erez


>
>   0x is an out of range value for option
> power_profile.2011.grandmasterTimeInaccuracy at line 44
>   failed to parse configuration file configs/default.cfg


> These values are unsigned and stored as fixed width values of 32 bits.
> Correct the configuration specification to allow the true maximum of an
> unsigned 32 bit integer.
>
> Signed-off-by: Jacob Keller 
> ---
> I'm not sure if there is a simpler or better way to fix this. We could just
> update the range of CFG_TYPE_INT to be long (or long long) instead, which
> would give it a range big enough to cover all our current values...
>
>  config.c | 54 +++---
>  config.h |  3 +++
>  port.c   |  6 +++---
>  3 files changed, 57 insertions(+), 6 deletions(-)
>
> diff --git a/config.c b/config.c
> index cb4421f572c7..baf8352538ea 100644
> --- a/config.c
> +++ b/config.c
> @@ -51,6 +51,7 @@ enum config_section {
>
>  enum config_type {
> CFG_TYPE_INT,
> +   CFG_TYPE_UINT,
> CFG_TYPE_DOUBLE,
> CFG_TYPE_ENUM,
> CFG_TYPE_STRING,
> @@ -63,6 +64,7 @@ struct config_enum {
>
>  typedef union {
> int i;
> +   unsigned int u;
> double d;
> char *s;
>  } any_t;
> @@ -109,6 +111,14 @@ struct config_item {
> .min.i  = _min, \
> .max.i  = _max, \
>  }
> +#define CONFIG_ITEM_UINT(_label, _port, _default, _min, _max) {\
> +   .label  = _label,   \
> +   .type   = CFG_TYPE_UINT,\
> +   .flags  = _port ? CFG_ITEM_PORT : 0,\
> +   .val.u  = _default, \
> +   .min.u  = _min, \
> +   .max.u  = _max, \
> +}
>  #define CONFIG_ITEM_STRING(_label, _port, _default) {  \
> .label  = _label,   \
> .type   = CFG_TYPE_STRING,  \
> @@ -125,6 +135,9 @@ struct config_item {
>  #define GLOB_ITEM_INT(label, _default, min, max) \
> CONFIG_ITEM_INT(label, 0, _default, min, max)
>
> +#define GLOB_ITEM_UINT(label, _default, min, max) \
> +   CONFIG_ITEM_UINT(label, 0, _default, min, max)
> +
>  #define GLOB_ITEM_STR(label, _default) \
> CONFIG_ITEM_STRING(label, 0, _default)
>
> @@ -137,6 +150,9 @@ struct config_item {
>  #define PORT_ITEM_INT(label, _default, min, max) \
> CONFIG_ITEM_INT(label, 1, _default, min, max)
>
> +#define PORT_ITEM_UINT(label, _default, min, max) \
> +   CONFIG_ITEM_UINT(label, 1, _default, min, max)
> +
>  #define PORT_ITEM_STR(label, _default) \
> CONFIG_ITEM_STRING(label, 1, _default)
>
> @@ -309,9 +325,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",
> 0x, 0, INT_MAX),
> -   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0,
> INT_MAX),
> -   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy",
> 0x, 0, INT_MAX),
> +   PORT_ITEM_UINT("power_profile.2011.grandmasterTimeInaccuracy",
> 0x, 0, UINT32_MAX),
> +   PORT_ITEM_UINT("power_profile.2011.networkTimeInaccuracy", 0, 0,
> UINT32_MAX),
> +   PORT_ITEM_UINT("power_profile.2017.totalTimeInaccuracy",
> 0x, 0, UINT32_MAX),
> PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
> GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
> GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
> @@ -559,6 +575,7 @@ static enum parser_result parse_item(struct config
> *cfg,
> enum parser_result r;
> struct config_item *cgi, *dst;
> struct config_enum *cte;
> +   unsigned int uval;
> double df;
> int val;
>
> @@ -578,6 +595,9 @@ static enum parser_result parse_item(struct config
> *cfg,
> case CFG_TYPE_INT:
> r = get_ranged_int(value, &val, cgi->min.i, cgi->max.i);
> break;
> +   case CFG_TYPE_UINT:
> +   r = get_ranged_uint(value, &uval, cgi->

[Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-03-29 Thread Jacob Keller
The power profile configuration options added in commit 7059a05a3fb2
("Introduce the power profile.") specify their maximum range as INT_MAX.
The values are stored in UInteger32 values, and the default 0x is
outside the range of a 32-bit integer. Because of this, on platforms which
have 32-bit integers, ptp4l is unable to read the default configuration:

  0x is an out of range value for option 
power_profile.2011.grandmasterTimeInaccuracy at line 44
  failed to parse configuration file configs/default.cfg

These values are unsigned and stored as fixed width values of 32 bits.
Correct the configuration specification to allow the true maximum of an
unsigned 32 bit integer.

Signed-off-by: Jacob Keller 
---
I'm not sure if there is a simpler or better way to fix this. We could just
update the range of CFG_TYPE_INT to be long (or long long) instead, which
would give it a range big enough to cover all our current values...

 config.c | 54 +++---
 config.h |  3 +++
 port.c   |  6 +++---
 3 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/config.c b/config.c
index cb4421f572c7..baf8352538ea 100644
--- a/config.c
+++ b/config.c
@@ -51,6 +51,7 @@ enum config_section {
 
 enum config_type {
CFG_TYPE_INT,
+   CFG_TYPE_UINT,
CFG_TYPE_DOUBLE,
CFG_TYPE_ENUM,
CFG_TYPE_STRING,
@@ -63,6 +64,7 @@ struct config_enum {
 
 typedef union {
int i;
+   unsigned int u;
double d;
char *s;
 } any_t;
@@ -109,6 +111,14 @@ struct config_item {
.min.i  = _min, \
.max.i  = _max, \
 }
+#define CONFIG_ITEM_UINT(_label, _port, _default, _min, _max) {\
+   .label  = _label,   \
+   .type   = CFG_TYPE_UINT,\
+   .flags  = _port ? CFG_ITEM_PORT : 0,\
+   .val.u  = _default, \
+   .min.u  = _min, \
+   .max.u  = _max, \
+}
 #define CONFIG_ITEM_STRING(_label, _port, _default) {  \
.label  = _label,   \
.type   = CFG_TYPE_STRING,  \
@@ -125,6 +135,9 @@ struct config_item {
 #define GLOB_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 0, _default, min, max)
 
+#define GLOB_ITEM_UINT(label, _default, min, max) \
+   CONFIG_ITEM_UINT(label, 0, _default, min, max)
+
 #define GLOB_ITEM_STR(label, _default) \
CONFIG_ITEM_STRING(label, 0, _default)
 
@@ -137,6 +150,9 @@ struct config_item {
 #define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)
 
+#define PORT_ITEM_UINT(label, _default, min, max) \
+   CONFIG_ITEM_UINT(label, 1, _default, min, max)
+
 #define PORT_ITEM_STR(label, _default) \
CONFIG_ITEM_STRING(label, 1, _default)
 
@@ -309,9 +325,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", 
0x, 0, INT_MAX),
-   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
INT_MAX),
-   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
INT_MAX),
+   PORT_ITEM_UINT("power_profile.2011.grandmasterTimeInaccuracy", 
0x, 0, UINT32_MAX),
+   PORT_ITEM_UINT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
UINT32_MAX),
+   PORT_ITEM_UINT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
UINT32_MAX),
PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
@@ -559,6 +575,7 @@ static enum parser_result parse_item(struct config *cfg,
enum parser_result r;
struct config_item *cgi, *dst;
struct config_enum *cte;
+   unsigned int uval;
double df;
int val;
 
@@ -578,6 +595,9 @@ static enum parser_result parse_item(struct config *cfg,
case CFG_TYPE_INT:
r = get_ranged_int(value, &val, cgi->min.i, cgi->max.i);
break;
+   case CFG_TYPE_UINT:
+   r = get_ranged_uint(value, &uval, cgi->min.u, cgi->max.u);
+   break;
case CFG_TYPE_DOUBLE:
r = get_ranged_double(value, &df, cgi->min.d, cgi->max.d);
break;
@@ -623,6 +643,9 @@ static enum parser_result parse_item(struct config *cfg,
case CFG_TYPE_ENUM:
dst->val.i = val;
break;
+   case CFG_TYPE_UINT:
+   dst->val.u = uval;
+   break;
case CFG_TYPE_DOUBLE: