From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9122C4CED1 for ; Thu, 3 Oct 2019 16:44:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE7392054F for ; Thu, 3 Oct 2019 16:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570121073; bh=fKDOifOsBYF0DMQPzAQ/DZmDI8+D34sivsnDb+H7i50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=z6NHgXuv4jObj/RF+YqmJWJko69sdKFJokT/z09HK0uVA2WR+3bPR5Epe/8qxFu29 zgDHR2rRLe08IZr2RLfdVso1OMfT7lSKe8YcUxSxtTu8jEbhXYOxngil0nv8Jhwq2f r38aUwN7QHgCsrv93Dx7Dw/P/6WkI9ddA1/6yxlI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405383AbfJCQoc (ORCPT ); Thu, 3 Oct 2019 12:44:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:56580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392744AbfJCQoa (ORCPT ); Thu, 3 Oct 2019 12:44:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 951092054F; Thu, 3 Oct 2019 16:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570121069; bh=fKDOifOsBYF0DMQPzAQ/DZmDI8+D34sivsnDb+H7i50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXB5jI/cF9NJmkxBno2dJEldYkwQYZLGntn6RuaV4dNEL9pCIQoXs2MDKJR95+0hm z7qTK++bs04qsrhf0Ne++x4kyZ4z5dl75lhIAyjoFjhFBXcVSfXmPDXV7h7g7PwExa 0XCxwXiV3UixRaBQT99zXsV3K0QG6j8I0RSiqXL4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wolfram Sang , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.3 107/344] media: i2c: tda1997x: prevent potential NULL pointer access Date: Thu, 3 Oct 2019 17:51:12 +0200 Message-Id: <20191003154550.774976696@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154540.062170222@linuxfoundation.org> References: <20191003154540.062170222@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wolfram Sang [ Upstream commit 2f822f1da08ac5c93e351e79d22920f08fa51baf ] i2c_new_dummy() can fail returning a NULL pointer. This is not checked and the returned pointer is blindly used. Convert to devm_i2c_new_dummy_client() which returns an ERR_PTR and also add a validity check. Using devm_* here also fixes a leak because the dummy client was not released in the probe error path. Signed-off-by: Wolfram Sang Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/i2c/tda1997x.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c index a62ede0966361..5e68182001ecc 100644 --- a/drivers/media/i2c/tda1997x.c +++ b/drivers/media/i2c/tda1997x.c @@ -2691,7 +2691,13 @@ static int tda1997x_probe(struct i2c_client *client, } ret = 0x34 + ((io_read(sd, REG_SLAVE_ADDR)>>4) & 0x03); - state->client_cec = i2c_new_dummy(client->adapter, ret); + state->client_cec = devm_i2c_new_dummy_device(&client->dev, + client->adapter, ret); + if (IS_ERR(state->client_cec)) { + ret = PTR_ERR(state->client_cec); + goto err_free_mutex; + } + v4l_info(client, "CEC slave address 0x%02x\n", ret); ret = tda1997x_core_init(sd); @@ -2798,7 +2804,6 @@ static int tda1997x_remove(struct i2c_client *client) media_entity_cleanup(&sd->entity); v4l2_ctrl_handler_free(&state->hdl); regulator_bulk_disable(TDA1997X_NUM_SUPPLIES, state->supplies); - i2c_unregister_device(state->client_cec); cancel_delayed_work(&state->delayed_work_enable_hpd); mutex_destroy(&state->page_lock); mutex_destroy(&state->lock); -- 2.20.1