module-avb: check return value of read when clearing ptp_fd input buffer

This commit is contained in:
Nils Tonnaett 2026-01-16 21:25:04 -08:00 committed by hackerman-kl
parent c8f2edd94e
commit f360af0889

View file

@ -77,13 +77,18 @@ static bool update_ts_refclk(struct gptp *gptp) {
// Read if something is left in the socket // Read if something is left in the socket
int avail; int avail;
uint8_t tmp; uint8_t tmp;
ssize_t ret;
if (ioctl(gptp->ptp_fd, FIONREAD, &avail) == -1) { if (ioctl(gptp->ptp_fd, FIONREAD, &avail) == -1) {
pw_log_warn("Failed to get number of byes in ptp_fd input buffer: %m"); pw_log_warn("Failed to get number of byes in ptp_fd input buffer: %m");
return false; return false;
} }
pw_log_debug("Flushing stale data: %u bytes", avail); pw_log_debug("Clearing stale data: %u bytes", avail);
while (avail-- && read(gptp->ptp_fd, &tmp, 1)); while (avail-- && (ret = read(gptp->ptp_fd, &tmp, 1)) > 0);
if (ret == -1) {
pw_log_warn("Failed to clear ptp_fd input buffer: %m");
return false;
}
struct ptp_management_msg req; struct ptp_management_msg req;
spa_zero(req); spa_zero(req);
@ -117,7 +122,7 @@ static bool update_ts_refclk(struct gptp *gptp) {
} }
uint8_t buf[sizeof(struct ptp_management_msg) + sizeof(struct ptp_parent_data_set)]; uint8_t buf[sizeof(struct ptp_management_msg) + sizeof(struct ptp_parent_data_set)];
ssize_t ret = read(gptp->ptp_fd, &buf, sizeof(buf)); ret = read(gptp->ptp_fd, &buf, sizeof(buf));
if (ret == -1) { if (ret == -1) {
pw_log_warn("Failed to receive PTP management response: %m"); pw_log_warn("Failed to receive PTP management response: %m");
return false; return false;