summaryrefslogtreecommitdiff
path: root/sys/dev/ic/pcf8584.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2006-06-14 04:13:38 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2006-06-14 04:13:38 +0000
commit53d22c3f2796b434e3a7a587a4f2666858c2944e (patch)
tree4393c04c095900ece23478dda71a2bbe177acf58 /sys/dev/ic/pcf8584.c
parent6ea6e03762ee36a24db0bc69b56ba34203ee5b89 (diff)
no more infinite loops; tested by dlg
Diffstat (limited to 'sys/dev/ic/pcf8584.c')
-rw-r--r--sys/dev/ic/pcf8584.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/sys/dev/ic/pcf8584.c b/sys/dev/ic/pcf8584.c
index b23ec11a33e..6a1b2b6a872 100644
--- a/sys/dev/ic/pcf8584.c
+++ b/sys/dev/ic/pcf8584.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcf8584.c,v 1.3 2006/06/14 01:15:17 deraadt Exp $ */
+/* $OpenBSD: pcf8584.c,v 1.4 2006/06/14 04:13:37 deraadt Exp $ */
/*
* Copyright (c) 2006 David Gwynne <dlg@openbsd.org>
@@ -198,16 +198,25 @@ pcfiic_xmit(struct pcfiic_softc *sc, u_int8_t addr, const u_int8_t *buf,
int i;
int err = 0;
volatile u_int8_t r;
+ int tries = 100;
- while ((pcfiic_read(sc, PCF_S1) & PCF_STAT_nBB) == 0)
- ;
+ while ((pcfiic_read(sc, PCF_S1) & PCF_STAT_nBB) == 0) {
+ if (--tries == 0)
+ return (1);
+ DELAY(1);
+ }
pcfiic_write(sc, PCF_S0, addr << 1);
pcfiic_write(sc, PCF_S1, PCF_CTRL_START);
for (i = 0; i <= len; i++) {
- while ((r = pcfiic_read(sc, PCF_S1)) & PCF_STAT_PIN)
- ;
+ while ((r = pcfiic_read(sc, PCF_S1)) & PCF_STAT_PIN) {
+ if (--tries == 0) {
+ err = 1;
+ break;
+ }
+ DELAY(1);
+ }
if (r & PCF_STAT_LRB) {
err = 1;