> -----Original Message-----
> From: Miroslav Lichvar <mlich...@redhat.com>
> 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 <mlich...@redhat.com>
> ---
>  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 <errno.h>
>  #include <stdio.h>
>  #include <string.h>
>  #include <sys/ioctl.h>
> @@ -38,11 +39,11 @@ static int sysoff_precise(int fd, int64_t *result, 
> uint64_t
> *ts)
>       memset(&pso, 0, sizeof(pso));
>       if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, &pso)) {
>               pr_debug("ioctl PTP_SYS_OFFSET_PRECISE: %m");
> -             return SYSOFF_RUN_TIME_MISSING;
> +             return -errno;
>       }
>       *result = pctns(&pso.sys_realtime) - pctns(&pso.device);
>       *ts = pctns(&pso.sys_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, &pso)) {
>               pr_debug("ioctl PTP_SYS_OFFSET_EXTENDED: %m");
> -             return SYSOFF_RUN_TIME_MISSING;
> +             return -errno;
>       }
>       *result = sysoff_estimate(&pso.ts[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, &pso)) {
>               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

Reply via email to