Skip to content
Permalink
Browse files

media: cec-notifier: debounce callback setting invalid phys addr

  • Loading branch information...
Kwiboo committed Jan 2, 2019
1 parent b92f23b commit 9a248d0ac4902cfe1c8c62325f9194616b03cc9d
Showing with 18 additions and 1 deletion.
  1. +18 −1 drivers/media/cec/cec-notifier.c
@@ -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>
@@ -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;
@@ -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);
@@ -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);
}

0 comments on commit 9a248d0

Please sign in to comment.
You can’t perform that action at this time.