From 3dab0e0518e951e62ebcdceb9f170f304cb9d9b5 Mon Sep 17 00:00:00 2001 From: Narendra Damahe Date: Fri, 17 Sep 2010 13:40:52 -0700 Subject: [USB ADB]: 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 (cherry picked from commit 3a1e33f6715f7133ba9fe26d68342c1ff6106b20) Change-Id: I575f38269c9a4c46a3a59ff7a06c8bda36a0c0d4 Reviewed-on: http://git-master/r/6723 Reviewed-by: Narendra Damahe Tested-by: Narendra Damahe Reviewed-by: Gary King --- drivers/usb/gadget/f_adb.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/f_adb.c b/drivers/usb/gadget/f_adb.c index 301300e04cab..8e2347781be5 100644 --- a/drivers/usb/gadget/f_adb.c +++ b/drivers/usb/gadget/f_adb.c @@ -154,12 +154,14 @@ static void adb_request_free(struct usb_request *req, struct usb_ep *ep) static inline int _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 _unlock(atomic_t *excl) @@ -409,21 +411,43 @@ 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"); - if (_lock(&_adb_dev->open_excl)) + 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 (_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; /* clear the error latch */ _adb_dev->error = 0; - return 0; } 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"); _unlock(&_adb_dev->open_excl); return 0; } -- cgit v1.2.3