From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id DA4EA1C039A for ; Tue, 8 May 2018 09:46:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D6F6E84581 for ; Tue, 8 May 2018 09:46:01 +0000 (UTC) Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r1_UNiWA7lF4 for ; Tue, 8 May 2018 09:46:01 +0000 (UTC) Received: from esa6.microchip.iphmx.com (esa6.microchip.iphmx.com [216.71.154.253]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 3845584921 for ; Tue, 8 May 2018 09:46:01 +0000 (UTC) From: Christian Gromm Subject: [PATCH 07/28] staging: most: i2c: shorten lifetime of IRQ handler Date: Tue, 8 May 2018 11:44:55 +0200 Message-ID: <1525772716-15742-8-git-send-email-christian.gromm@microchip.com> In-Reply-To: <1525772716-15742-1-git-send-email-christian.gromm@microchip.com> References: <1525772716-15742-1-git-send-email-christian.gromm@microchip.com> MIME-Version: 1.0 List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" To: gregkh@linuxfoundation.org Cc: Christian Gromm , driverdev-devel@linuxdriverproject.org Currently the IRQ handler used for the rx channel lives between the functions i2c_probe and i2c_remove. This patch shortens the lifetime and keeps the handler alive only between the functions configure_channel and poison_channel. Signed-off-by: Christian Gromm --- drivers/staging/most/i2c/i2c.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/staging/most/i2c/i2c.c b/drivers/staging/most/i2c/i2c.c index 8ec660b..b382f09 100644 --- a/drivers/staging/most/i2c/i2c.c +++ b/drivers/staging/most/i2c/i2c.c @@ -56,6 +56,8 @@ struct hdm_i2c { #define to_hdm(iface) container_of(iface, struct hdm_i2c, most_iface) +static irqreturn_t most_irq_handler(int, void *); + /** * configure_channel - called from MOST core to configure a channel * @iface: interface the channel belongs to @@ -71,6 +73,7 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx, struct most_channel_config *channel_config) { + int ret; struct hdm_i2c *dev = to_hdm(most_iface); BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS); @@ -86,7 +89,21 @@ static int configure_channel(struct most_interface *most_iface, return -EPERM; } + if (channel_config->direction == MOST_CH_RX) { + dev->polling_mode = polling_req || dev->client->irq <= 0; + if (!dev->polling_mode) { + pr_info("Requesting IRQ: %d\n", dev->client->irq); + ret = request_irq(dev->client->irq, most_irq_handler, 0, + dev->client->name, dev); + if (ret) { + pr_info("IRQ request failed: %d, falling back to polling\n", + ret); + dev->polling_mode = true; + } + } + } if ((channel_config->direction == MOST_CH_RX) && (dev->polling_mode)) { + pr_info("Using polling at rate: %d times/sec\n", scan_rate); schedule_delayed_work(&dev->rx.dwork, msecs_to_jiffies(MSEC_PER_SEC / 4)); } @@ -160,6 +177,10 @@ static int poison_channel(struct most_interface *most_iface, dev->is_open[ch_idx] = false; if (ch_idx == CH_RX) { + if (!dev->polling_mode) + free_irq(dev->client->irq, dev); + cancel_delayed_work_sync(&dev->rx.dwork); + mutex_lock(&dev->rx.list_mutex); while (!list_empty(&dev->rx.list)) { mbo = list_first_mbo(&dev->rx.list); @@ -347,21 +368,6 @@ static int i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) return ret; } - dev->polling_mode = polling_req || client->irq <= 0; - if (!dev->polling_mode) { - pr_info("Requesting IRQ: %d\n", client->irq); - ret = request_irq(client->irq, most_irq_handler, 0, - client->name, dev); - if (ret) { - pr_info("IRQ request failed: %d, falling back to polling\n", - ret); - dev->polling_mode = true; - } - } - - if (dev->polling_mode) - pr_info("Using polling at rate: %d times/sec\n", scan_rate); - return 0; } @@ -377,11 +383,7 @@ static int i2c_remove(struct i2c_client *client) { struct hdm_i2c *dev = i2c_get_clientdata(client); - if (!dev->polling_mode) - free_irq(client->irq, dev); - most_deregister_interface(&dev->most_iface); - cancel_delayed_work_sync(&dev->rx.dwork); kfree(dev); return 0; -- 2.7.4 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel