From patchwork Mon Jun 24 16:03:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 11014837 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 9FE3C14BB for ; Tue, 25 Jun 2019 07:27:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AEF41FE8B for ; Tue, 25 Jun 2019 07:27:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F47028AD9; Tue, 25 Jun 2019 07:27:56 +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 33C261FE8B for ; Tue, 25 Jun 2019 07:27:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BB97989FA9; Tue, 25 Jun 2019 07:27:32 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 428 seconds by postgrey-1.36 at gabe; Mon, 24 Jun 2019 16:10:46 UTC Received: from lb2-smtp-cloud7.xs4all.net (lb2-smtp-cloud7.xs4all.net [194.109.24.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id 70AB089CDE for ; Mon, 24 Jun 2019 16:10:46 +0000 (UTC) Received: from tschai.fritz.box ([46.9.252.75]) by smtp-cloud7.xs4all.net with ESMTPA id fRRKhHRxHF85OfRRQhZaa6; Mon, 24 Jun 2019 18:03:36 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [PATCHv8 01/13] cec-notifier: rename variable, check kstrdup Date: Mon, 24 Jun 2019 18:03:18 +0200 Message-Id: <20190624160330.38048-2-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624160330.38048-1-hverkuil-cisco@xs4all.nl> References: <20190624160330.38048-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfM5cfxY3qb1mJIOEfAgwxyzmneGu3DOIaGPtL1rXLfi9ZKPJS+IAvic+bCsU2HYwU9mQ1Jj1vHvFgU1ggcDsS/Y2kgf9iITUsRBXY3PD2phToQDCc7VC D9qy5VUksdVPfDlhsMqkQ4ta3+MCDxaWUKQ6XF5uM0Pgj8Uzc7q7Z4+g7+bpnB84Bzr3ImR4/G2lpXfhExjbQs/zQ97F56agQHKYWaPCoJmGfuiZ99gNPSLK xMJH1wmKXksLI0BBia8s4T9UWN9fi3EdUobR/y8KiTA3A0PzNCZXkjLgBIpfyRqz/hqiWNfSRoqggyZF2UVHrUoIBaIJIgyVr8uN0djZrO4= X-Mailman-Approved-At: Tue, 25 Jun 2019 07:27:07 +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 Also check the result of kstrdup, and clean up on error. Signed-off-by: Hans Verkuil --- drivers/media/cec/cec-notifier.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c index 9598c7778871..ce10dfd400bb 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,15 @@ 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 || !strcmp(n->conn_name, conn_name))) { kref_get(&n->kref); mutex_unlock(&cec_notifiers_lock); return n; @@ -48,10 +49,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 +75,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); }