From 23be8eb25e0fc0e9cc1274c0dafa4f9c03526f36 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Thu, 11 Dec 2014 18:50:33 +0000 Subject: Handle UPSes with broken report descriptors. As reported by David Higgs some UPSes might send fewer bytes than requested. When such thing happens, do like apcupsd and adjust the size of the given descriptor. Based on a diff provided by David Higgs, thanks! --- sys/dev/usb/upd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'sys/dev/usb') diff --git a/sys/dev/usb/upd.c b/sys/dev/usb/upd.c index cc6a3adf13e..e63cc462117 100644 --- a/sys/dev/usb/upd.c +++ b/sys/dev/usb/upd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: upd.c,v 1.11 2014/12/11 18:39:27 mpi Exp $ */ +/* $OpenBSD: upd.c,v 1.12 2014/12/11 18:50:32 mpi Exp $ */ /* * Copyright (c) 2014 Andre de Oliveira @@ -274,11 +274,15 @@ upd_refresh(void *arg) actlen = uhidev_get_report(sc->sc_hdev.sc_parent, UHID_FEATURE_REPORT, repid, buf, report->size); - if (actlen != report->size) { + if (actlen == -1) { DPRINTF(("upd: failed to get report id=%02x\n", repid)); continue; } + /* Deal with buggy firmwares. */ + if (actlen < report->size) + report->size = actlen; + upd_update_sensors(sc, buf, report->size, repid); } } -- cgit v1.2.3