From patchwork Tue Jan 15 12:55:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 1977861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 877B2DF2E5 for ; Tue, 15 Jan 2013 13:08:56 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tv69c-0000Ji-5F; Tue, 15 Jan 2013 13:02:12 +0000 Received: from mail-wi0-f178.google.com ([209.85.212.178]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tv64M-0006cO-Pb for linux-arm-kernel@lists.infradead.org; Tue, 15 Jan 2013 12:56:49 +0000 Received: by mail-wi0-f178.google.com with SMTP id hn3so61299wib.11 for ; Tue, 15 Jan 2013 04:56:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=VTU8EwbQ1tldpumKgdheKiAHrzVC9yrMSmgJMsYxYRE=; b=pd45x/mYUWclyslSn6JAEWNO1Xheqa8dPtRXyHyZ0z2GuAfnCoXYiDk6w0uLgmY4sB O1Iuaf8iJxLSpWSGyZxVRck0HFu9RjXL5959JHP+DbaJxMqt2UQrcpOcQ/jy4oH05M/S jWbf+IvbKOYA5W75Bwtn77sAguOTvImh2eN99mXn787ThwxkA6cFynV4qd/hrN2rLe0b OHIAdG8/fljPQ3Ap2RhbeZSPVhyDghHYUd8nguiJzU9D8TzFknjDlPFL0rwS7t5HPlma BNsLif04cYtuw2jeC9Iag/2GPkmuRiwbzCFg2ddfrHO3ei24yDbRi87tzZZbi4e/jCso zxkQ== X-Received: by 10.180.78.66 with SMTP id z2mr3550197wiw.23.1358254605417; Tue, 15 Jan 2013 04:56:45 -0800 (PST) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id eo10sm3672833wib.9.2013.01.15.04.56.43 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jan 2013 04:56:44 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/26] mfd: ab8500-debugfs: Keep count of IRQs in debugfs Date: Tue, 15 Jan 2013 12:55:51 +0000 Message-Id: <1358254566-12419-12-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1358254566-12419-1-git-send-email-lee.jones@linaro.org> References: <1358254566-12419-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQlnZTXC1xGeN7ivt0M+7WTzUNplv+SZROD7lBpobv1drSQtpcNi9DaYa3UG3AqLI2xqapmG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130115_075647_225949_0BD47AAD X-CRM114-Status: GOOD ( 18.76 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.178 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Mattias Wallin , Lee Jones , linus.walleij@stericsson.com, arnd@arndb.de, sameo@linux.intel.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Mattias Wallin This patch adds a counter to the sysfs file dynamically created by debugfs. It also fixes an array index error. Signed-off-by: Lee Jones Signed-off-by: Mattias Wallin Reviewed-by: Mattias NILSSON --- drivers/mfd/ab8500-debugfs.c | 77 +++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c index b3ddc23..03eacf1 100644 --- a/drivers/mfd/ab8500-debugfs.c +++ b/drivers/mfd/ab8500-debugfs.c @@ -23,6 +23,10 @@ static u32 debug_address; static int irq_first; static int irq_last; +static u32 irq_count[AB8500_NR_IRQS]; + +static struct device_attribute *dev_attr[AB8500_NR_IRQS]; +static char *event_name[AB8500_NR_IRQS]; /** * struct ab8500_reg_range @@ -364,12 +368,15 @@ static irqreturn_t ab8500_debug_handler(int irq, void *data) { char buf[16]; struct kobject *kobj = (struct kobject *)data; + unsigned int irq_abb = irq - irq_first; + if (irq_abb < AB8500_NR_IRQS) + irq_count[irq_abb]++; /* * This makes it possible to use poll for events (POLLPRI | POLLERR) - * from userspace on sysfs file named irq- + * from userspace on sysfs file named */ - sprintf(buf, "irq-%d", irq); + sprintf(buf, "%d", irq); sysfs_notify(kobj, NULL, buf); return IRQ_HANDLED; @@ -555,19 +562,26 @@ static int ab8500_subscribe_unsubscribe_open(struct inode *inode, } /* - * This function is used for all interrupts and will always print - * the same string. It is however this file sysfs_notify called on. - * Userspace should read this file and then poll. When an event occur + * Userspace should use poll() on this file. When an event occur * the blocking poll will be released. */ static ssize_t show_irq(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "irq\n"); -} + unsigned long name; + unsigned int irq_index; + int err; -static struct device_attribute *dev_attr[AB8500_NR_IRQS]; -static char *event_name[AB8500_NR_IRQS]; + err = strict_strtoul(attr->attr.name, 0, &name); + if (err) + return err; + + irq_index = name - irq_first; + if (irq_index >= AB8500_NR_IRQS) + return -EINVAL; + else + return sprintf(buf, "%u\n", irq_count[irq_index]); +} static ssize_t ab8500_subscribe_write(struct file *file, const char __user *user_buf, @@ -578,6 +592,7 @@ static ssize_t ab8500_subscribe_write(struct file *file, int buf_size; unsigned long user_val; int err; + unsigned int irq_index; /* Get userspace string and assure termination */ buf_size = min(count, (sizeof(buf)-1)); @@ -597,19 +612,23 @@ static ssize_t ab8500_subscribe_write(struct file *file, return -EINVAL; } + irq_index = user_val - irq_first; + if (irq_index >= AB8500_NR_IRQS) + return -EINVAL; + /* - * This will create a sysfs file named irq- which userspace can + * This will create a sysfs file named which userspace can * use to select or poll and get the AB8500 events */ - dev_attr[user_val] = kmalloc(sizeof(struct device_attribute), - GFP_KERNEL); - event_name[user_val] = kmalloc(buf_size, GFP_KERNEL); - sprintf(event_name[user_val], "irq-%lu", user_val); - dev_attr[user_val]->show = show_irq; - dev_attr[user_val]->store = NULL; - dev_attr[user_val]->attr.name = event_name[user_val]; - dev_attr[user_val]->attr.mode = S_IRUGO; - err = sysfs_create_file(&dev->kobj, &dev_attr[user_val]->attr); + dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), + GFP_KERNEL); + event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); + sprintf(event_name[irq_index], "%lu", user_val); + dev_attr[irq_index]->show = show_irq; + dev_attr[irq_index]->store = NULL; + dev_attr[irq_index]->attr.name = event_name[irq_index]; + dev_attr[irq_index]->attr.mode = S_IRUGO; + err = sysfs_create_file(&dev->kobj, &dev_attr[irq_index]->attr); if (err < 0) { printk(KERN_ERR "sysfs_create_file failed %d\n", err); return err; @@ -621,6 +640,7 @@ static ssize_t ab8500_subscribe_write(struct file *file, if (err < 0) { printk(KERN_ERR "request_threaded_irq failed %d, %lu\n", err, user_val); + sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); return err; } @@ -636,6 +656,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file, int buf_size; unsigned long user_val; int err; + unsigned int irq_index; /* Get userspace string and assure termination */ buf_size = min(count, (sizeof(buf)-1)); @@ -655,12 +676,20 @@ static ssize_t ab8500_unsubscribe_write(struct file *file, return -EINVAL; } - free_irq(user_val, &dev->kobj); - kfree(event_name[user_val]); - kfree(dev_attr[user_val]); + irq_index = user_val - irq_first; + if (irq_index >= AB8500_NR_IRQS) + return -EINVAL; + + /* Set irq count to 0 when unsubscribe */ + irq_count[irq_index] = 0; + + if (dev_attr[irq_index]) + sysfs_remove_file(&dev->kobj, &dev_attr[irq_index]->attr); - if (dev_attr[user_val]) - sysfs_remove_file(&dev->kobj, &dev_attr[user_val]->attr); + + free_irq(user_val, &dev->kobj); + kfree(event_name[irq_index]); + kfree(dev_attr[irq_index]); return buf_size; }