Skip to content

Commit 309ea22

Browse files
eunovmgregkh
authored andcommitted
media: atomisp: Fix error handling in probe
[ Upstream commit e16f5e3 ] There were several issues with handling errors in lm3554_probe(): - Probe did not set the error code when v4l2_ctrl_handler_init() failed. - It intermixed gotos for handling errors of v4l2_ctrl_handler_init() and media_entity_pads_init(). - It did not set the error code for failures of v4l2_ctrl_new_custom(). - Probe did not free resources in case of failures of atomisp_register_i2c_module(). The patch fixes all these issues. Found by Linux Driver Verification project (linuxtesting.org). Link: https://lore.kernel.org/linux-media/20210810162943.19852-1-novikov@ispras.ru Signed-off-by: Evgeny Novikov <novikov@ispras.ru> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f4c652b commit 309ea22

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

‎drivers/staging/media/atomisp/i2c/atomisp-lm3554.c‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,6 @@ static int lm3554_probe(struct i2c_client *client)
836836
int err = 0;
837837
struct lm3554 *flash;
838838
unsigned int i;
839-
int ret;
840839

841840
flash = kzalloc(sizeof(*flash), GFP_KERNEL);
842841
if (!flash)
@@ -845,20 +844,20 @@ static int lm3554_probe(struct i2c_client *client)
845844
flash->pdata = lm3554_platform_data_func(client);
846845
if (IS_ERR(flash->pdata)) {
847846
err = PTR_ERR(flash->pdata);
848-
goto fail1;
847+
goto free_flash;
849848
}
850849

851850
v4l2_i2c_subdev_init(&flash->sd, client, &lm3554_ops);
852851
flash->sd.internal_ops = &lm3554_internal_ops;
853852
flash->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
854853
flash->mode = ATOMISP_FLASH_MODE_OFF;
855854
flash->timeout = LM3554_MAX_TIMEOUT / LM3554_TIMEOUT_STEPSIZE - 1;
856-
ret =
855+
err =
857856
v4l2_ctrl_handler_init(&flash->ctrl_handler,
858857
ARRAY_SIZE(lm3554_controls));
859-
if (ret) {
858+
if (err) {
860859
dev_err(&client->dev, "error initialize a ctrl_handler.\n");
861-
goto fail3;
860+
goto unregister_subdev;
862861
}
863862

864863
for (i = 0; i < ARRAY_SIZE(lm3554_controls); i++)
@@ -867,14 +866,15 @@ static int lm3554_probe(struct i2c_client *client)
867866

868867
if (flash->ctrl_handler.error) {
869868
dev_err(&client->dev, "ctrl_handler error.\n");
870-
goto fail3;
869+
err = flash->ctrl_handler.error;
870+
goto free_handler;
871871
}
872872

873873
flash->sd.ctrl_handler = &flash->ctrl_handler;
874874
err = media_entity_pads_init(&flash->sd.entity, 0, NULL);
875875
if (err) {
876876
dev_err(&client->dev, "error initialize a media entity.\n");
877-
goto fail2;
877+
goto free_handler;
878878
}
879879

880880
flash->sd.entity.function = MEDIA_ENT_F_FLASH;
@@ -885,16 +885,27 @@ static int lm3554_probe(struct i2c_client *client)
885885

886886
err = lm3554_gpio_init(client);
887887
if (err) {
888-
dev_err(&client->dev, "gpio request/direction_output fail");
889-
goto fail3;
888+
dev_err(&client->dev, "gpio request/direction_output fail.\n");
889+
goto cleanup_media;
890+
}
891+
892+
err = atomisp_register_i2c_module(&flash->sd, NULL, LED_FLASH);
893+
if (err) {
894+
dev_err(&client->dev, "fail to register atomisp i2c module.\n");
895+
goto uninit_gpio;
890896
}
891-
return atomisp_register_i2c_module(&flash->sd, NULL, LED_FLASH);
892-
fail3:
897+
898+
return 0;
899+
900+
uninit_gpio:
901+
lm3554_gpio_uninit(client);
902+
cleanup_media:
893903
media_entity_cleanup(&flash->sd.entity);
904+
free_handler:
894905
v4l2_ctrl_handler_free(&flash->ctrl_handler);
895-
fail2:
906+
unregister_subdev:
896907
v4l2_device_unregister_subdev(&flash->sd);
897-
fail1:
908+
free_flash:
898909
kfree(flash);
899910

900911
return err;

0 commit comments

Comments
 (0)