From patchwork Tue Jun 25 14:44:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 11017159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5440314BB for ; Wed, 26 Jun 2019 08:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4524928694 for ; Wed, 26 Jun 2019 08:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39A4C286BF; Wed, 26 Jun 2019 08:12:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E31C228694 for ; Wed, 26 Jun 2019 08:12:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 914066E2CD; Wed, 26 Jun 2019 08:12:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lb1-smtp-cloud9.xs4all.net (lb1-smtp-cloud9.xs4all.net [194.109.24.22]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5EC876E131 for ; Tue, 25 Jun 2019 14:45:16 +0000 (UTC) Received: from cobaltpc1.rd.cisco.com ([IPv6:2001:420:44c1:2579:b032:593c:25fc:ff9b]) by smtp-cloud9.xs4all.net with ESMTPA id fmh4hQwJSSfvXfmh8hHoyn; Tue, 25 Jun 2019 16:45:14 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [PATCHv9 01/13] cec-notifier: rename variables, check kstrdup and n->conn_name Date: Tue, 25 Jun 2019 16:44:58 +0200 Message-Id: <20190625144510.122214-2-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190625144510.122214-1-hverkuil-cisco@xs4all.nl> References: <20190625144510.122214-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfGotbewLqH47JURfpvjZTkncnARHewLy1oqUHYbwzqPtDPvONf3dtrG/IOF9QxJbcyVMhjJt0KGFoWLRBz8EwpyYk6Keyz/Fctqw4aQqOJHQ/TYw8FAZ q/JNFcyfuc4wW5+tsoG3t6uUODtH0DZ2Xi/TiHi1fivntsucHa1iEnys/uQpPQ/stBXYqgiICCeRH97g+cTXQn7vCCn2JDdbJ3lqx3i2e8CEI9JiHTQ73L8j UhvWGYzzEM2rJ3kbHLDBD0rmnc+jObwYRTPRw2ZWAYoGSJGYECk2wACzZ8jGgK66nAQzyN2IMCEMLGcpjhz1kZmEv44S2SELBDSYSLno5KDCTUJvEcuKVIlm VZZDhHwUBqYb+rYoInNBCGsprC+wmhF2rkQXHvZ7c9mBt8p0HLxl5lQcml6eeFcDcUEYjSDM X-Mailman-Approved-At: Wed, 26 Jun 2019 08:12:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Verkuil , Dariusz Marcinkiewicz , dri-devel@lists.freedesktop.org, Cheng-yi Chiang Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/media/cec/cec-notifier.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c index 9598c7778871..f72b19c351dd 100644 --- a/drivers/media/cec/cec-notifier.c +++ b/drivers/media/cec/cec-notifier.c @@ -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); }