Re: [Linuxptp-devel] [PATCHv2 2/4] sysoff: Change sysoff_measure() to return ioctl errno.

2022-03-29 Thread Miroslav Lichvar
On Fri, Mar 25, 2022 at 12:24:47AM +, Keller, Jacob E wrote:
> > -Original Message-
> > From: Miroslav Lichvar 
> > Sent: Thursday, March 24, 2022 6:20 AM
> > To: linuxptp-devel@lists.sourceforge.net
> > Subject: [Linuxptp-devel] [PATCHv2 2/4] sysoff: Change sysoff_measure() to
> > return ioctl errno.
> > 
> > Return -errno instead of SYSOFF_RUN_TIME_MISSING from the sysoff
> > measurement functions to allow the callers to check for specific errors.
> > 
> 
> This is changing from returning the type to returning an error code. I would 
> have expected equivalent changes to the other applications that use this..

SYSOFF_RUN_TIME_MISSING has a negative value. The existing callers of
sysoff_measure() already check for "< 0" or ">= 0". It should work
as it is.

-- 
Miroslav Lichvar



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


Re: [Linuxptp-devel] [PATCHv2 2/4] sysoff: Change sysoff_measure() to return ioctl errno.

2022-03-24 Thread Keller, Jacob E



> -Original Message-
> From: Miroslav Lichvar 
> Sent: Thursday, March 24, 2022 6:20 AM
> To: linuxptp-devel@lists.sourceforge.net
> Subject: [Linuxptp-devel] [PATCHv2 2/4] sysoff: Change sysoff_measure() to
> return ioctl errno.
> 
> Return -errno instead of SYSOFF_RUN_TIME_MISSING from the sysoff
> measurement functions to allow the callers to check for specific errors.
> 

This is changing from returning the type to returning an error code. I would 
have expected equivalent changes to the other applications that use this..

> Signed-off-by: Miroslav Lichvar 
> ---
>  sysoff.c | 15 ---
>  sysoff.h |  2 +-
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/sysoff.c b/sysoff.c
> index 31b792d..0678df6 100644
> --- a/sysoff.c
> +++ b/sysoff.c
> @@ -17,6 +17,7 @@
>   * with this program; if not, write to the Free Software Foundation, Inc.,
>   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>   */
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -38,11 +39,11 @@ static int sysoff_precise(int fd, int64_t *result, 
> uint64_t
> *ts)
>   memset(, 0, sizeof(pso));
>   if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, )) {
>   pr_debug("ioctl PTP_SYS_OFFSET_PRECISE: %m");
> - return SYSOFF_RUN_TIME_MISSING;
> + return -errno;
>   }
>   *result = pctns(_realtime) - pctns();
>   *ts = pctns(_realtime);
> - return SYSOFF_PRECISE;
> + return 0;
>  }
> 
>  static int64_t sysoff_estimate(struct ptp_clock_time *pct, int extended,
> @@ -98,10 +99,10 @@ static int sysoff_extended(int fd, int n_samples,
>   pso.n_samples = n_samples;
>   if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, )) {
>   pr_debug("ioctl PTP_SYS_OFFSET_EXTENDED: %m");
> - return SYSOFF_RUN_TIME_MISSING;
> + return -errno;
>   }
>   *result = sysoff_estimate([0][0], 1, n_samples, ts, delay);
> - return SYSOFF_EXTENDED;
> + return 0;
>  }
> 
>  static int sysoff_basic(int fd, int n_samples,
> @@ -112,10 +113,10 @@ static int sysoff_basic(int fd, int n_samples,
>   pso.n_samples = n_samples;
>   if (ioctl(fd, PTP_SYS_OFFSET, )) {
>   pr_debug("ioctl PTP_SYS_OFFSET: %m");
> - return SYSOFF_RUN_TIME_MISSING;
> + return -errno;
>   }
>   *result = sysoff_estimate(pso.ts, 0, n_samples, ts, delay);
> - return SYSOFF_BASIC;
> + return 0;
>  }
> 
>  int sysoff_measure(int fd, int method, int n_samples,
> @@ -130,7 +131,7 @@ int sysoff_measure(int fd, int method, int n_samples,
>   case SYSOFF_BASIC:
>   return sysoff_basic(fd, n_samples, result, ts, delay);
>   }
> - return SYSOFF_RUN_TIME_MISSING;
> + return -EOPNOTSUPP;
>  }
> 
>  int sysoff_probe(int fd, int n_samples)
> diff --git a/sysoff.h b/sysoff.h
> index e4de919..ed338fd 100644
> --- a/sysoff.h
> +++ b/sysoff.h
> @@ -44,7 +44,7 @@ int sysoff_probe(int fd, int n_samples);
>   * @param result The estimated offset in nanoseconds.
>   * @param ts The system time corresponding to the 'result'.
>   * @param delay  The delay in reading of the clock in nanoseconds.
> - * @return  One of the SYSOFF_ enumeration values.
> + * @return  Zero on success, negative otherwise.
>   */
>  int sysoff_measure(int fd, int method, int n_samples,
>  int64_t *result, uint64_t *ts, int64_t *delay);
> --
> 2.35.1
> 
> 
> 
> ___
> Linuxptp-devel mailing list
> Linuxptp-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


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