]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: cec-notifier: rename variables, check kstrdup and n->conn_name
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Thu, 20 Jun 2019 08:39:00 +0000 (04:39 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Thu, 27 Jun 2019 11:17:24 +0000 (07:17 -0400)
dev -> hdmi_dev
conn -> conn_name

Check if n->conn_name is not NULL before calling strcmp.
Check the result of kstrdup, and clean up on error.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/cec/cec-notifier.c

index 9598c7778871a433ad7eebd5532c1021b3db6f18..f72b19c351ddad6a4b18c59beb148b5752c2698d 100644 (file)
@@ -21,8 +21,8 @@ struct cec_notifier {
        struct mutex lock;
        struct list_head head;
        struct kref kref;
-       struct device *dev;
-       const char *conn;
+       struct device *hdmi_dev;
+       const char *conn_name;
        struct cec_adapter *cec_adap;
        void (*callback)(struct cec_adapter *adap, u16 pa);
 
@@ -32,14 +32,16 @@ struct cec_notifier {
 static LIST_HEAD(cec_notifiers);
 static DEFINE_MUTEX(cec_notifiers_lock);
 
-struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
+struct cec_notifier *
+cec_notifier_get_conn(struct device *hdmi_dev, const char *conn_name)
 {
        struct cec_notifier *n;
 
        mutex_lock(&cec_notifiers_lock);
        list_for_each_entry(n, &cec_notifiers, head) {
-               if (n->dev == dev &&
-                   (!conn || !strcmp(n->conn, conn))) {
+               if (n->hdmi_dev == hdmi_dev &&
+                   (!conn_name ||
+                    (n->conn_name && !strcmp(n->conn_name, conn_name)))) {
                        kref_get(&n->kref);
                        mutex_unlock(&cec_notifiers_lock);
                        return n;
@@ -48,10 +50,17 @@ struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
        n = kzalloc(sizeof(*n), GFP_KERNEL);
        if (!n)
                goto unlock;
-       n->dev = dev;
-       if (conn)
-               n->conn = kstrdup(conn, GFP_KERNEL);
+       n->hdmi_dev = hdmi_dev;
+       if (conn_name) {
+               n->conn_name = kstrdup(conn_name, GFP_KERNEL);
+               if (!n->conn_name) {
+                       kfree(n);
+                       n = NULL;
+                       goto unlock;
+               }
+       }
        n->phys_addr = CEC_PHYS_ADDR_INVALID;
+
        mutex_init(&n->lock);
        kref_init(&n->kref);
        list_add_tail(&n->head, &cec_notifiers);
@@ -67,7 +76,7 @@ static void cec_notifier_release(struct kref *kref)
                container_of(kref, struct cec_notifier, kref);
 
        list_del(&n->head);
-       kfree(n->conn);
+       kfree(n->conn_name);
        kfree(n);
 }