Skip to content

Commit

Permalink
media: cec-notifier: debounce callback setting invalid phys addr
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwiboo committed Jan 2, 2019
1 parent b92f23b commit 9a248d0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion drivers/media/cec/cec-notifier.c
Expand Up @@ -11,6 +11,7 @@
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/kref.h>
#include <linux/workqueue.h>

#include <media/cec.h>
#include <media/cec-notifier.h>
Expand All @@ -26,11 +27,23 @@ struct cec_notifier {
void (*callback)(struct cec_adapter *adap, u16 pa);

u16 phys_addr;
struct delayed_work work;
};

static LIST_HEAD(cec_notifiers);
static DEFINE_MUTEX(cec_notifiers_lock);

static void cec_notifier_delayed_work(struct work_struct *work)
{
struct cec_notifier *n =
container_of(to_delayed_work(work), struct cec_notifier, work);

mutex_lock(&n->lock);
if (n->callback)
n->callback(n->cec_adap, n->phys_addr);
mutex_unlock(&n->lock);
}

struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
{
struct cec_notifier *n;
Expand All @@ -51,6 +64,7 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
if (conn)
n->conn = kstrdup(conn, GFP_KERNEL);
n->phys_addr = CEC_PHYS_ADDR_INVALID;
INIT_DELAYED_WORK(&n->work, cec_notifier_delayed_work);
mutex_init(&n->lock);
kref_init(&n->kref);
list_add_tail(&n->head, &cec_notifiers);
Expand Down Expand Up @@ -83,9 +97,12 @@ void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
if (n == NULL)
return;

cancel_delayed_work_sync(&n->work);
mutex_lock(&n->lock);
n->phys_addr = pa;
if (n->callback)
if (pa == CEC_PHYS_ADDR_INVALID)
schedule_delayed_work(&n->work, msecs_to_jiffies(1100));
else if (n->callback)
n->callback(n->cec_adap, n->phys_addr);
mutex_unlock(&n->lock);
}
Expand Down

0 comments on commit 9a248d0

Please sign in to comment.