The phc_pin_setfunc() call uses PTP_PIN_SETFUNC2, attempting to hew the newer PTP_PIN_SETFUNC2 ioctl. This would break on older kernels which lack this ioctl. However, missing.h then provides a PTP_PIN_SETFUNC2 definition which re-defines the macro to use the original ioctl PTP_PIN_SETFUNC.
This is confusing as it makes the function behavior differ based on whether we compiled against updated header files. This will also make it challenging to later support dynamic checking of PTP_PIN_SETFUNC2 if we ever have a need to enable use of the newer ioctl. For now, these two ioctls behave identically for the purposes of non-reserved fields. Update missing.h to always define PTP_PIN_SETFUNC2 in terms of the actual ioctl value. Avoid using PTP_PIN_SETFUNC2 at all in phc_pin_setfunc(), instead just using the original PTP_PIN_SETFUNC. In the future this can be modified to dynamically check and use PTP_PIN_SETFUNC2 if necessary. However, there is no useful behavior difference today. For this reason continue using the older ioctl to maintain maximum compatibility with the supported kernels. Note that PTP_PIN_SETFUNC2 is kept in missing.h even though we don't yet have a user in the codebase. This is intentional to ensure that we do not accidentally restore the anti-pattern of falling back at compile time instead of run time if we need PTP_PIN_SETFUNC2 in the future. Signed-off-by: Jacob Keller <jacob.e.kel...@intel.com> --- missing.h | 7 ++----- phc.c | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/missing.h b/missing.h index 79a87d425993..9b37dc258c0f 100644 --- a/missing.h +++ b/missing.h @@ -244,11 +244,8 @@ struct ptp_pin_desc { #endif /*!PTP_PIN_SETFUNC*/ -#ifdef PTP_PIN_SETFUNC2 -#define PTP_PIN_SETFUNC_FAILED "PTP_PIN_SETFUNC2 failed: %m" -#else -#define PTP_PIN_SETFUNC_FAILED "PTP_PIN_SETFUNC failed: %m" -#define PTP_PIN_SETFUNC2 PTP_PIN_SETFUNC +#ifndef PTP_PIN_SETFUNC2 +#define PTP_PIN_SETFUNC2 _IOW(PTP_CLK_MAGIC, 16, struct ptp_pin_desc) #endif #ifndef LIST_FOREACH_SAFE diff --git a/phc.c b/phc.c index 37f6b9f6db3c..c121c64f9177 100644 --- a/phc.c +++ b/phc.c @@ -112,10 +112,9 @@ int phc_number_pins(clockid_t clkid) int phc_pin_setfunc(clockid_t clkid, struct ptp_pin_desc *desc) { - int err = ioctl(CLOCKID_TO_FD(clkid), PTP_PIN_SETFUNC2, desc); - if (err) { - fprintf(stderr, PTP_PIN_SETFUNC_FAILED "\n"); - } + int err = ioctl(CLOCKID_TO_FD(clkid), PTP_PIN_SETFUNC, desc); + if (err) + fprintf(stderr, "failed to set pin configuration, error: %m\n"); return err; } -- 2.41.0.1.g9857a21e0017.dirty _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel