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 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue