Skip to content

Commit

Permalink
sysoff: Change sysoff_measure() to return errno.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Jul 24, 2022
1 parent c9ae9ad commit 7824b13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions sysoff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sysoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 7824b13

Please sign in to comment.