]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
media: i2c: tda1997x: prevent potential NULL pointer access
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Fri, 9 Aug 2019 16:52:15 +0000 (13:52 -0300)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Tue, 13 Aug 2019 14:46:32 +0000 (11:46 -0300)
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 <wsa+renesas@sang-engineering.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/i2c/tda1997x.c

index a62ede0966361a879e33db7c3f1e1ad5d207d4c0..5e68182001ecc8bd0ef703716b2ac231c4ababd6 100644 (file)
@@ -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);