Commit 428359cb authored by Rui Miguel Silva's avatar Rui Miguel Silva Committed by Mauro Carvalho Chehab

media: staging: greybus: light: fix memory leak in v4l2 register

We are allocating memory for the v4l2 flash configuration structure and
leak it in the normal path. Just use the stack for this as we do not
use it outside of this function.

Also use IS_ERR() instead of IS_ERR_OR_NULL() to check return value from
v4l2_flash_init() for it never returns NULL.

Fixes: 2870b52b ("greybus: lights: add lights implementation")
Reported-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarRui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent b7aaf822
...@@ -534,25 +534,20 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) ...@@ -534,25 +534,20 @@ static int gb_lights_light_v4l2_register(struct gb_light *light)
{ {
struct gb_connection *connection = get_conn_from_light(light); struct gb_connection *connection = get_conn_from_light(light);
struct device *dev = &connection->bundle->dev; struct device *dev = &connection->bundle->dev;
struct v4l2_flash_config *sd_cfg; struct v4l2_flash_config sd_cfg = { {0} };
struct led_classdev_flash *fled; struct led_classdev_flash *fled;
struct led_classdev *iled = NULL; struct led_classdev *iled = NULL;
struct gb_channel *channel_torch, *channel_ind, *channel_flash; struct gb_channel *channel_torch, *channel_ind, *channel_flash;
int ret = 0;
sd_cfg = kcalloc(1, sizeof(*sd_cfg), GFP_KERNEL);
if (!sd_cfg)
return -ENOMEM;
channel_torch = get_channel_from_mode(light, GB_CHANNEL_MODE_TORCH); channel_torch = get_channel_from_mode(light, GB_CHANNEL_MODE_TORCH);
if (channel_torch) if (channel_torch)
__gb_lights_channel_v4l2_config(&channel_torch->intensity_uA, __gb_lights_channel_v4l2_config(&channel_torch->intensity_uA,
&sd_cfg->torch_intensity); &sd_cfg.torch_intensity);
channel_ind = get_channel_from_mode(light, GB_CHANNEL_MODE_INDICATOR); channel_ind = get_channel_from_mode(light, GB_CHANNEL_MODE_INDICATOR);
if (channel_ind) { if (channel_ind) {
__gb_lights_channel_v4l2_config(&channel_ind->intensity_uA, __gb_lights_channel_v4l2_config(&channel_ind->intensity_uA,
&sd_cfg->indicator_intensity); &sd_cfg.indicator_intensity);
iled = &channel_ind->fled.led_cdev; iled = &channel_ind->fled.led_cdev;
} }
...@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) ...@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light)
fled = &channel_flash->fled; fled = &channel_flash->fled;
snprintf(sd_cfg->dev_name, sizeof(sd_cfg->dev_name), "%s", light->name); snprintf(sd_cfg.dev_name, sizeof(sd_cfg.dev_name), "%s", light->name);
/* Set the possible values to faults, in our case all faults */ /* Set the possible values to faults, in our case all faults */
sd_cfg->flash_faults = LED_FAULT_OVER_VOLTAGE | LED_FAULT_TIMEOUT | sd_cfg.flash_faults = LED_FAULT_OVER_VOLTAGE | LED_FAULT_TIMEOUT |
LED_FAULT_OVER_TEMPERATURE | LED_FAULT_SHORT_CIRCUIT | LED_FAULT_OVER_TEMPERATURE | LED_FAULT_SHORT_CIRCUIT |
LED_FAULT_OVER_CURRENT | LED_FAULT_INDICATOR | LED_FAULT_OVER_CURRENT | LED_FAULT_INDICATOR |
LED_FAULT_UNDER_VOLTAGE | LED_FAULT_INPUT_VOLTAGE | LED_FAULT_UNDER_VOLTAGE | LED_FAULT_INPUT_VOLTAGE |
LED_FAULT_LED_OVER_TEMPERATURE; LED_FAULT_LED_OVER_TEMPERATURE;
light->v4l2_flash = v4l2_flash_init(dev, NULL, fled, iled, light->v4l2_flash = v4l2_flash_init(dev, NULL, fled, iled,
&v4l2_flash_ops, sd_cfg); &v4l2_flash_ops, &sd_cfg);
if (IS_ERR_OR_NULL(light->v4l2_flash)) { if (IS_ERR(light->v4l2_flash))
ret = PTR_ERR(light->v4l2_flash); return PTR_ERR(light->v4l2_flash);
goto out_free;
}
return ret; return 0;
out_free:
kfree(sd_cfg);
return ret;
} }
static void gb_lights_light_v4l2_unregister(struct gb_light *light) static void gb_lights_light_v4l2_unregister(struct gb_light *light)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment