From patchwork Mon Jul 22 17:26:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 57642 X-Patchwork-Delegate: sean@mess.org Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hpc64-0006nM-Nc; Mon, 22 Jul 2019 17:27:37 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731654AbfGVR1e (ORCPT + 1 other); Mon, 22 Jul 2019 13:27:34 -0400 Received: from sauhun.de ([88.99.104.3]:42428 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731492AbfGVR0e (ORCPT ); Mon, 22 Jul 2019 13:26:34 -0400 Received: from localhost (p54B33E22.dip0.t-ipconnect.de [84.179.62.34]) by pokefinder.org (Postfix) with ESMTPSA id 6D30C4A149A; Mon, 22 Jul 2019 19:26:33 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] media: ir-kbd-i2c: prevent potential NULL pointer access Date: Mon, 22 Jul 2019 19:26:31 +0200 Message-Id: <20190722172632.4402-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722172632.4402-1-wsa+renesas@sang-engineering.com> References: <20190722172632.4402-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org i2c_new_dummy() can fail returning a NULL pointer. The code does not bail out in this case and the returned pointer is blindly used. Convert to devm_i2c_new_dummy_device() which returns an ERR_PTR and also bail out when failing the validity check. Signed-off-by: Wolfram Sang --- drivers/media/i2c/ir-kbd-i2c.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c index 876d7587a1da..f46717052efc 100644 --- a/drivers/media/i2c/ir-kbd-i2c.c +++ b/drivers/media/i2c/ir-kbd-i2c.c @@ -885,9 +885,12 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) INIT_DELAYED_WORK(&ir->work, ir_work); if (probe_tx) { - ir->tx_c = i2c_new_dummy(client->adapter, 0x70); - if (!ir->tx_c) { + ir->tx_c = devm_i2c_new_dummy_device(&client->dev, + client->adapter, 0x70); + if (IS_ERR(ir->tx_c)) { dev_err(&client->dev, "failed to setup tx i2c address"); + err = PTR_ERR(ir->tx_c); + goto err_out_free; } else if (!zilog_init(ir)) { ir->carrier = 38000; ir->duty_cycle = 40; @@ -904,9 +907,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) return 0; err_out_free: - if (ir->tx_c) - i2c_unregister_device(ir->tx_c); - /* Only frees rc if it were allocated internally */ rc_free_device(rc); return err; @@ -919,9 +919,6 @@ static int ir_remove(struct i2c_client *client) /* kill outstanding polls */ cancel_delayed_work_sync(&ir->work); - if (ir->tx_c) - i2c_unregister_device(ir->tx_c); - /* unregister device */ rc_unregister_device(ir->rc); From patchwork Mon Jul 22 17:26:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 57640 X-Patchwork-Delegate: sean@mess.org Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hpc60-0006m8-FF; Mon, 22 Jul 2019 17:27:32 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731511AbfGVR0f (ORCPT + 1 other); Mon, 22 Jul 2019 13:26:35 -0400 Received: from sauhun.de ([88.99.104.3]:42398 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731494AbfGVR0f (ORCPT ); Mon, 22 Jul 2019 13:26:35 -0400 Received: from localhost (p54B33E22.dip0.t-ipconnect.de [84.179.62.34]) by pokefinder.org (Postfix) with ESMTPSA id F2EFA4A148F; Mon, 22 Jul 2019 19:26:33 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] media: ir-kbd-i2c: remove outdated comments Date: Mon, 22 Jul 2019 19:26:32 +0200 Message-Id: <20190722172632.4402-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722172632.4402-1-wsa+renesas@sang-engineering.com> References: <20190722172632.4402-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The "free memory" comment is obsolete since 2013 and the other ones explain the obvious. Just remove the comments. Signed-off-by: Wolfram Sang --- drivers/media/i2c/ir-kbd-i2c.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c index f46717052efc..30fde0e025c9 100644 --- a/drivers/media/i2c/ir-kbd-i2c.c +++ b/drivers/media/i2c/ir-kbd-i2c.c @@ -916,13 +916,9 @@ static int ir_remove(struct i2c_client *client) { struct IR_i2c *ir = i2c_get_clientdata(client); - /* kill outstanding polls */ cancel_delayed_work_sync(&ir->work); - - /* unregister device */ rc_unregister_device(ir->rc); - /* free memory */ return 0; }