From dfe37d54ac9bd327267c618ee53694084fa8548b Mon Sep 17 00:00:00 2001 From: Gary King Date: Tue, 7 Sep 2010 09:07:47 -0700 Subject: HACK: rate control adb prints limit the number of times adb_open and adb_release may be printed in a short period of time, to prevent adb death spirals when exiting suspend. Original-Change-Id: I231bdc0bb497758174ec12a69c8d17d5dc95d4db Rebase-Id: R56e66e16e212dee5fd95ebb392955e06018e16bd --- drivers/usb/gadget/f_adb.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_adb.c b/drivers/usb/gadget/f_adb.c index fe4455e50d10..8ed7b0123194 100644 --- a/drivers/usb/gadget/f_adb.c +++ b/drivers/usb/gadget/f_adb.c @@ -147,12 +147,16 @@ static void adb_request_free(struct usb_request *req, struct usb_ep *ep) static inline int adb_lock(atomic_t *excl) { + int ret = -1; + + preempt_disable(); if (atomic_inc_return(excl) == 1) { - return 0; - } else { + ret = 0; + } else atomic_dec(excl); - return -1; - } + + preempt_enable(); + return ret; } static inline void adb_unlock(atomic_t *excl) @@ -406,12 +410,28 @@ static ssize_t adb_write(struct file *fp, const char __user *buf, static int adb_open(struct inode *ip, struct file *fp) { - printk(KERN_INFO "adb_open\n"); + static unsigned long last_print; + static unsigned long count = 0; + if (!_adb_dev) return -ENODEV; + if (++count == 1) + last_print = jiffies; + else { + if (!time_before(jiffies, last_print + HZ/2)) + count = 0; + last_print = jiffies; + } + if (adb_lock(&_adb_dev->open_excl)) + cpu_relax(); return -EBUSY; + } + + if (count < 5) + printk(KERN_INFO "adb_open(%s)\n", current->comm); + fp->private_data = _adb_dev; @@ -423,7 +443,19 @@ static int adb_open(struct inode *ip, struct file *fp) static int adb_release(struct inode *ip, struct file *fp) { - printk(KERN_INFO "adb_release\n"); + static unsigned long last_print; + static unsigned long count = 0; + + if (++count == 1) + last_print = jiffies; + else { + if (!time_before(jiffies, last_print + HZ/2)) + count = 0; + last_print = jiffies; + } + + if (count < 5) + printk(KERN_INFO "adb_release\n"); adb_unlock(&_adb_dev->open_excl); return 0; } -- cgit v1.2.3