95 lines
3.1 KiB
Diff
95 lines
3.1 KiB
Diff
From 6428c2628c013c408ec09355ad37eb12fa6bb20f Mon Sep 17 00:00:00 2001
|
|
From: Miroslav Lichvar <mlichvar@redhat.com>
|
|
Date: Wed, 18 May 2022 11:33:35 +0200
|
|
Subject: [PATCH 7/54] sysoff: Change sysoff_measure() to return errno.
|
|
|
|
Return -errno from failed ioctl instead of the SYSOFF_* enum from the
|
|
measurement functions to allow the callers to check for specific errors.
|
|
|
|
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
|
|
[commit 7824b13db9533ddebe37cf444d7aaa5d235575d3 upstream]
|
|
Signed-off-by: Douglas Henrique Koerich <douglashenrique.koerich@windriver.com>
|
|
Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
|
|
---
|
|
sysoff.c | 15 ++++++++-------
|
|
sysoff.h | 2 +-
|
|
2 files changed, 9 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/sysoff.c b/sysoff.c
|
|
index 2743859..5d3b907 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)) {
|
|
perror("ioctl PTP_SYS_OFFSET");
|
|
- 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..5480f8f 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 error code otherwise.
|
|
*/
|
|
int sysoff_measure(int fd, int method, int n_samples,
|
|
int64_t *result, uint64_t *ts, int64_t *delay);
|
|
--
|
|
2.29.2
|
|
|