Commit 0ecbf7fc authored by Christian Gromm's avatar Christian Gromm Committed by Greg Kroah-Hartman

staging: most: i2c: shorten lifetime of IRQ handler

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: default avatarChristian Gromm <christian.gromm@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ed856eb5
...@@ -56,6 +56,8 @@ struct hdm_i2c { ...@@ -56,6 +56,8 @@ struct hdm_i2c {
#define to_hdm(iface) container_of(iface, struct hdm_i2c, most_iface) #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 * configure_channel - called from MOST core to configure a channel
* @iface: interface the channel belongs to * @iface: interface the channel belongs to
...@@ -71,6 +73,7 @@ static int configure_channel(struct most_interface *most_iface, ...@@ -71,6 +73,7 @@ static int configure_channel(struct most_interface *most_iface,
int ch_idx, int ch_idx,
struct most_channel_config *channel_config) struct most_channel_config *channel_config)
{ {
int ret;
struct hdm_i2c *dev = to_hdm(most_iface); struct hdm_i2c *dev = to_hdm(most_iface);
BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS); BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
...@@ -86,7 +89,21 @@ static int configure_channel(struct most_interface *most_iface, ...@@ -86,7 +89,21 @@ static int configure_channel(struct most_interface *most_iface,
return -EPERM; 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)) { 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, schedule_delayed_work(&dev->rx.dwork,
msecs_to_jiffies(MSEC_PER_SEC / 4)); msecs_to_jiffies(MSEC_PER_SEC / 4));
} }
...@@ -160,6 +177,10 @@ static int poison_channel(struct most_interface *most_iface, ...@@ -160,6 +177,10 @@ static int poison_channel(struct most_interface *most_iface,
dev->is_open[ch_idx] = false; dev->is_open[ch_idx] = false;
if (ch_idx == CH_RX) { 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); mutex_lock(&dev->rx.list_mutex);
while (!list_empty(&dev->rx.list)) { while (!list_empty(&dev->rx.list)) {
mbo = list_first_mbo(&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) ...@@ -347,21 +368,6 @@ static int i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
return ret; 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; return 0;
} }
...@@ -377,11 +383,7 @@ static int i2c_remove(struct i2c_client *client) ...@@ -377,11 +383,7 @@ static int i2c_remove(struct i2c_client *client)
{ {
struct hdm_i2c *dev = i2c_get_clientdata(client); struct hdm_i2c *dev = i2c_get_clientdata(client);
if (!dev->polling_mode)
free_irq(client->irq, dev);
most_deregister_interface(&dev->most_iface); most_deregister_interface(&dev->most_iface);
cancel_delayed_work_sync(&dev->rx.dwork);
kfree(dev); kfree(dev);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment