media: cec-notifier: rename variables, check kstrdup and n->conn_name
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>
This commit is contained in:
parent
86d617d6c7
commit
3d51dc03a4
|
@ -21,8 +21,8 @@ struct cec_notifier {
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
struct list_head head;
|
struct list_head head;
|
||||||
struct kref kref;
|
struct kref kref;
|
||||||
struct device *dev;
|
struct device *hdmi_dev;
|
||||||
const char *conn;
|
const char *conn_name;
|
||||||
struct cec_adapter *cec_adap;
|
struct cec_adapter *cec_adap;
|
||||||
void (*callback)(struct cec_adapter *adap, u16 pa);
|
void (*callback)(struct cec_adapter *adap, u16 pa);
|
||||||
|
|
||||||
|
@ -32,14 +32,16 @@ struct cec_notifier {
|
||||||
static LIST_HEAD(cec_notifiers);
|
static LIST_HEAD(cec_notifiers);
|
||||||
static DEFINE_MUTEX(cec_notifiers_lock);
|
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;
|
struct cec_notifier *n;
|
||||||
|
|
||||||
mutex_lock(&cec_notifiers_lock);
|
mutex_lock(&cec_notifiers_lock);
|
||||||
list_for_each_entry(n, &cec_notifiers, head) {
|
list_for_each_entry(n, &cec_notifiers, head) {
|
||||||
if (n->dev == dev &&
|
if (n->hdmi_dev == hdmi_dev &&
|
||||||
(!conn || !strcmp(n->conn, conn))) {
|
(!conn_name ||
|
||||||
|
(n->conn_name && !strcmp(n->conn_name, conn_name)))) {
|
||||||
kref_get(&n->kref);
|
kref_get(&n->kref);
|
||||||
mutex_unlock(&cec_notifiers_lock);
|
mutex_unlock(&cec_notifiers_lock);
|
||||||
return n;
|
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);
|
n = kzalloc(sizeof(*n), GFP_KERNEL);
|
||||||
if (!n)
|
if (!n)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
n->dev = dev;
|
n->hdmi_dev = hdmi_dev;
|
||||||
if (conn)
|
if (conn_name) {
|
||||||
n->conn = kstrdup(conn, GFP_KERNEL);
|
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;
|
n->phys_addr = CEC_PHYS_ADDR_INVALID;
|
||||||
|
|
||||||
mutex_init(&n->lock);
|
mutex_init(&n->lock);
|
||||||
kref_init(&n->kref);
|
kref_init(&n->kref);
|
||||||
list_add_tail(&n->head, &cec_notifiers);
|
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);
|
container_of(kref, struct cec_notifier, kref);
|
||||||
|
|
||||||
list_del(&n->head);
|
list_del(&n->head);
|
||||||
kfree(n->conn);
|
kfree(n->conn_name);
|
||||||
kfree(n);
|
kfree(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue