Create sub-device per LED
Subsystems (5)
v2 cover Create sub-device per LED
Hi folks,
The original design decision in the V4L2 flash API allows controlling a two LEDs (an indicator and a flash) through a single sub-device. This covered virtually all flash driver chips back then but this no longer holds as there are many LED driver chips with multiple flash LED outputs. This necessitates creating as many sub-devices as there are flash LEDs.
Additionally the flash LEDs can be associated to different sensors. This is not unconceivable although not very probable.
This patchset splits the indicator and flash LEDs exposed by the V4L2 flash class framework into multiple sub-devices. This way the driver creates the sub-devices individually for each LED which will also facilitate fwnode matching (e.g. will you refer to LED or a LED driver chip with a phandle?).
since v1:
- Drop patch "staging: greybus: light: Don't leak memory for no gain" in favour of Rui's "staging: greybus: light: fix memory leak in v4l2 register".
- Rebase "staging: greybus: light: fix memory leak in v4l2 register" on "media: v4l2-flash: Use led_classdev instead of led_classdev_flash for indicator" already in mediatree.
- Add "v4l2-flash-led-class: Document v4l2_flash_init() references" to the set.
Rui Miguel Silva (1):
staging: greybus: light: fix memory leak in v4l2 register
Sakari Ailus (2):
v4l2-flash-led-class: Create separate sub-devices for indicators
v4l2-flash-led-class: Document v4l2_flash_init() references
drivers/leds/leds-aat1290.c | 4 +- drivers/leds/leds-max77693.c | 4 +- drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++++++++++++++---------- drivers/staging/greybus/light.c | 42 ++++----- include/media/v4l2-flash-led-class.h | 47 +++++++--- 5 files changed, 127 insertions(+), 83 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/3 staging: greybus: light: fix memory leak in v4l2 register
From: Rui Miguel Silva <[email protected]>
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.
--- drivers/staging/greybus/light.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)
drivers/staging/greybus/light.c +9 -20
@@ -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 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 *iled =NULL ;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 );if (channel_torch)__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 );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg->indicator_intensity); + &sd_cfg.indicator_intensity); iled = &channel_ind->fled.led_cdev; }
@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) 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 */ - 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_CURRENT |LED_FAULT_INDICATOR |LED_FAULT_UNDER_VOLTAGE |LED_FAULT_INPUT_VOLTAGE |LED_FAULT_LED_OVER_TEMPERATURE ; light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, sd_cfg); -if (IS_ERR_OR_NULL (light->v4l2_flash)) { - ret =PTR_ERR (light->v4l2_flash); - goto out_free; - } + &v4l2_flash_ops, &sd_cfg); +if (IS_ERR_OR_NULL (light->v4l2_flash)) +return PTR_ERR (light->v4l2_flash); -return ret; - -out_free: -kfree (sd_cfg); -return ret; +return 0 ; }static void gb_lights_light_v4l2_unregister (struct gb_light *light)
Signature · 1 line
2.11.0
Rui Miguel Silva
maintainerRe: [PATCH v2 1/3] staging: greybus: light: fix memory leak in v4l2 register
Hi Sakari,
Quoted 11 lines · Sakari Ailus
From: Rui Miguel Silva <[email protected]>
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.
Fixes 2870b52bae4c ("greybus: lights: add lights implementation")Reported-by Sakari Ailus <[email protected]>Signed-off-by Rui Miguel Silva <[email protected]>Reviewed-by Viresh Kumar <[email protected]>---
This patch is *not* the patch that I have send, here are the code differences from my patch to the one in this series:
< struct led_classdev_flash *iled = NULL;
---
Quoted 1 line
struct
led_classdev*iled = NULL;
51c57
< iled = &channel_ind->fled;
---
Quoted 1 line
iled =
&channel_ind->fled.led_cdev;
89c95
So, this do not apply at all.
Maybe you change something in your side.
---
Cheers,
Rui
Quoted 73 lines
drivers/staging/greybus/light.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)drivers/staging/greybus/light.c +9
-20@@ -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 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 *iled =NULL ;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 );if (channel_torch)__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 );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg->indicator_intensity); + &sd_cfg.indicator_intensity); iled = &channel_ind->fled.led_cdev; }@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) 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 */ - 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_CURRENT |LED_FAULT_INDICATOR |LED_FAULT_UNDER_VOLTAGE |LED_FAULT_INPUT_VOLTAGE |LED_FAULT_LED_OVER_TEMPERATURE ; light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, sd_cfg); -if (IS_ERR_OR_NULL (light->v4l2_flash)) { - ret =PTR_ERR (light->v4l2_flash); - goto out_free; - } + &v4l2_flash_ops, &sd_cfg); +if (IS_ERR_OR_NULL (light->v4l2_flash)) +return PTR_ERR (light->v4l2_flash); -return ret; - -out_free: -kfree (sd_cfg); -return ret; +return 0 ; }static void gb_lights_light_v4l2_unregister (struct gb_light *light)Signature · 1 line
2.11.0
Re: [PATCH v2 1/3] staging: greybus: light: fix memory leak in v4l2 register
Hi Rui,
Quoted 20 lines · Rui Miguel Silva
Hi Sakari,
Quoted 11 lines · Sakari Ailus
From: Rui Miguel Silva <[email protected]>
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.
Fixes 2870b52bae4c ("greybus: lights: add lights implementation")Reported-by Sakari Ailus <[email protected]>Signed-off-by Rui Miguel Silva <[email protected]>Reviewed-by Viresh Kumar <[email protected]>---
This patch is *not* the patch that I have send, here are the code differences from my patch to the one in this series:
< struct
led_classdev_flash*iled = NULL;
---Quoted 1 line
struct
led_classdev*iled = NULL;
Quoted 8 lines
51c57
< iled =&channel_ind->fled;
---Quoted 1 line
iled =
&channel_ind->fled.led_cdev;89c95
So, this do not apply at all.
Maybe you change something in your side.
It's been rebased on linux-next and in particular, patch 85f7ff9702bc ("media: v4l2-flash: Use led_classdev instead of led_classdev_flash for indicator").
Signature · 2 lines
Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Rui Miguel Silva
maintainerRe: [PATCH v2 1/3] staging: greybus: light: fix memory leak in v4l2 register
Hi Sakari,
Quoted 27 lines · Sakari Ailus
Hi Rui,
Quoted 24 lines · Rui Miguel Silva
Hi Sakari,
Quoted 11 lines · Sakari Ailus
From: Rui Miguel Silva <[email protected]>
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.
Fixes 2870b52bae4c ("greybus: lights: add lights implementation")Reported-by Sakari Ailus <[email protected]>Signed-off-by Rui Miguel Silva <[email protected]>Reviewed-by Viresh Kumar <[email protected]>---
This patch is *not* the patch that I have send, here are the code differences from my patch to the one in this series:
< struct
led_classdev_flash*iled = NULL;
---Quoted 1 line
struct
led_classdev*iled = NULL;51c57
< iled =&channel_ind->fled;
---Quoted 1 line
iled =
&channel_ind->fled.led_cdev;
Quoted 8 lines
Quoted 4 lines
89c95
So, this do not apply at all.
Maybe you change something in your side.It's been rebased on linux-next and in particular, patch
85f7ff9702bc("media: v4l2-flash: Useled_classdevinstead ofled_classdev_flashfor indicator").
Yeah, I miss that patch also that touch greybus, thanks for the rebase.
---
Cheers,
Rui
Re: [PATCH v2 1/3] staging: greybus: light: fix memory leak in v4l2 register
In reply to Sakari AilusQuoted 5 lines · Sakari Ailus
From: Rui Miguel Silva <[email protected]>
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.
I'm not sure why this is part of this patch series. This is a greybus bug fix, right? And independent from the other two patches.
Quoted 14 lines
Fixes 2870b52bae4c ("greybus: lights: add lights implementation")Reported-by Sakari Ailus <[email protected]>Signed-off-by Rui Miguel Silva <[email protected]>Reviewed-by Viresh Kumar <[email protected]>--- drivers/staging/greybus/light.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)drivers/staging/greybus/light.c +0
-0
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 537
Quoted 5 lines
drivers/staging/greybus/light.c +1
-1@@ -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 device *dev = &connection->bundle->dev; -struct v4l2_flash_config *sd_cfg; +struct v4l2_flash_config sd_cfg = { {0 } };
Just use '= {};'
Quoted 36 lines
drivers/staging/greybus/light.c +4
-9struct led_classdev_flash *fled;struct led_classdev *iled =NULL ;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 );if (channel_torch)__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 );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg->indicator_intensity); + &sd_cfg.indicator_intensity); iled = &channel_ind->fled.led_cdev; }@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) 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 */ - 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_CURRENT |LED_FAULT_INDICATOR | LED_FAULT_UNDER_VOLTAGE | LED_FAULT_INPUT_VOLTAGE |
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 570
Quoted 10 lines
drivers/staging/greybus/light.c +2
-5LED_FAULT_LED_OVER_TEMPERATURE ; light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, sd_cfg); -if (IS_ERR_OR_NULL (light->v4l2_flash)) { - ret =PTR_ERR (light->v4l2_flash); - goto out_free; - } + &v4l2_flash_ops, &sd_cfg); +if (IS_ERR_OR_NULL (light->v4l2_flash))
Just IS_ERR since v4l2_flash_init() never returns NULL.
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 576
Quoted 12 lines
drivers/staging/greybus/light.c +2
-5+return PTR_ERR (light->v4l2_flash); -return ret; - -out_free: -kfree (sd_cfg); -return ret; +return 0 ; }static void gb_lights_light_v4l2_unregister (struct gb_light *light)
After those two changes:
Regards,
Hans
Re: [PATCH v2 1/3] staging: greybus: light: fix memory leak in v4l2 register
Quoted 9 lines · Hans Verkuil
Quoted 5 lines · Sakari Ailus
From: Rui Miguel Silva <[email protected]>
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.
I'm not sure why this is part of this patch series. This is a greybus bug fix, right? And independent from the other two patches.
Ah, I see. The second patch sits on top of this change. Sorry, I was a bit too quick there.
Hans
Quoted 93 lines
Quoted 15 lines
Fixes 2870b52bae4c ("greybus: lights: add lights implementation")Reported-by Sakari Ailus <[email protected]>Signed-off-by Rui Miguel Silva <[email protected]>Reviewed-by Viresh Kumar <[email protected]>--- drivers/staging/greybus/light.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)drivers/staging/greybus/light.c +0
-0drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 537
Quoted 5 lines
drivers/staging/greybus/light.c +1
-1@@ -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 device *dev = &connection->bundle->dev; -struct v4l2_flash_config *sd_cfg; +struct v4l2_flash_config sd_cfg = { {0 } };Just use '= {};'
Quoted 36 lines
drivers/staging/greybus/light.c +4
-9struct led_classdev_flash *fled;struct led_classdev *iled =NULL ;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 );if (channel_torch)__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 );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg->indicator_intensity); + &sd_cfg.indicator_intensity); iled = &channel_ind->fled.led_cdev; }@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) 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 */ - 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_CURRENT |LED_FAULT_INDICATOR | LED_FAULT_UNDER_VOLTAGE | LED_FAULT_INPUT_VOLTAGE |drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 570
Quoted 10 lines
drivers/staging/greybus/light.c +2
-5LED_FAULT_LED_OVER_TEMPERATURE ; light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, sd_cfg); -if (IS_ERR_OR_NULL (light->v4l2_flash)) { - ret =PTR_ERR (light->v4l2_flash); - goto out_free; - } + &v4l2_flash_ops, &sd_cfg); +if (IS_ERR_OR_NULL (light->v4l2_flash))Just
IS_ERRsincev4l2_flash_init()never returns NULL.drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 576
Quoted 12 lines
drivers/staging/greybus/light.c +2
-5+return PTR_ERR (light->v4l2_flash); -return ret; - -out_free: -kfree (sd_cfg); -return ret; +return 0 ; }static void gb_lights_light_v4l2_unregister (struct gb_light *light)After those two changes:
Acked-by Hans Verkuil <[email protected]>Regards,
Hans
Re: [PATCH v2 1/3] staging: greybus: light: fix memory leak in v4l2 register
In reply to Hans VerkuilHi Hans,
Quoted 8 lines · Hans Verkuil
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 537
Quoted 6 lines
drivers/staging/greybus/light.c +1
-1@@ -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 device *dev = &connection->bundle->dev; -struct v4l2_flash_config *sd_cfg; +struct v4l2_flash_config sd_cfg = { {0 } };Just use '= {};'
This is GCC specific whereas { {0} } is standard C. The latter is thus obviously better IMO.
Quoted 39 lines
Quoted 39 lines
drivers/staging/greybus/light.c +4
-9struct led_classdev_flash *fled;struct led_classdev *iled =NULL ;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 );if (channel_torch)__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 );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg->indicator_intensity); + &sd_cfg.indicator_intensity); iled = &channel_ind->fled.led_cdev; }@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) 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 */ - 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_CURRENT |LED_FAULT_INDICATOR |LED_FAULT_UNDER_VOLTAGE |LED_FAULT_INPUT_VOLTAGE |LED_FAULT_LED_OVER_TEMPERATURE ;
Quoted 10 lines
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 570
Quoted 8 lines
drivers/staging/greybus/light.c +2
-5light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, sd_cfg); -if (IS_ERR_OR_NULL (light->v4l2_flash)) { - ret =PTR_ERR (light->v4l2_flash); - goto out_free; - } + &v4l2_flash_ops, &sd_cfg); +if (IS_ERR_OR_NULL (light->v4l2_flash))Just
IS_ERRsincev4l2_flash_init()never returns NULL.
Will fix.
Quoted 17 lines
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 576
Quoted 13 lines
drivers/staging/greybus/light.c +2
-5+return PTR_ERR (light->v4l2_flash); -return ret; - -out_free: -kfree (sd_cfg); -return ret; +return 0 ; }static void gb_lights_light_v4l2_unregister (struct gb_light *light)After those two changes:
Acked-by Hans Verkuil <[email protected]>
Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
Rui Miguel Silva
maintainerRe: [PATCH v2 1/3] staging: greybus: light: fix memory leak in v4l2 register
Hi,
Quoted 12 lines · Sakari Ailus
Hi Hans,
Quoted 8 lines · Hans Verkuil
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 537
Quoted 6 lines
drivers/staging/greybus/light.c +1
-1@@ -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 device *dev = &connection->bundle->dev; -struct v4l2_flash_config *sd_cfg; +struct v4l2_flash_config sd_cfg = { {0 } };Just use '= {};'
Quoted 2 lines
This is GCC specific whereas { {0} } is standard C. The latter is thus obviously better IMO.
My thought exactly. Let keep it this way, please.
Quoted 51 lines
Quoted 40 lines
Quoted 40 lines
drivers/staging/greybus/light.c +4
-9struct led_classdev_flash *fled;struct led_classdev *iled =NULL ;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 );if (channel_torch)__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 );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg->indicator_intensity); + &sd_cfg.indicator_intensity); iled = &channel_ind->fled.led_cdev; }@@ -561,27 +556,21 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) 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 */ - 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_CURRENT |LED_FAULT_INDICATOR |LED_FAULT_UNDER_VOLTAGE |LED_FAULT_INPUT_VOLTAGE |LED_FAULT_LED_OVER_TEMPERATURE ;Quoted 10 lines
drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 570
Quoted 8 lines
drivers/staging/greybus/light.c +2
-5light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, sd_cfg); -if (IS_ERR_OR_NULL (light->v4l2_flash)) { - ret =PTR_ERR (light->v4l2_flash); - goto out_free; - } + &v4l2_flash_ops, &sd_cfg); +if (IS_ERR_OR_NULL (light->v4l2_flash))Just
IS_ERRsincev4l2_flash_init()never returns NULL.
Quoted 1 line
Will fix.
Thanks for that Sakari.
---
Cheers,
Rui
Quoted 24 lines
Quoted 18 lines
Quoted 4 lines
drivers/staging/greybus/light.c +1
-0+return PTR_ERR (light->v4l2_flash);drivers/staging/greybus/light.c static int gb_lights_light_v4l2_register(struct gb_light *light) · line 576
Quoted 10 lines
drivers/staging/greybus/light.c +1
-5-return ret; - -out_free: -kfree (sd_cfg); -return ret; +return 0 ; }static void gb_lights_light_v4l2_unregister (struct gb_light *light)After those two changes:
Acked-by Hans Verkuil <[email protected]>Signature · 4 lines
Regards, Sakari Ailus e-mail: [email protected] XMPP: [email protected]
PATCH v2 2/3 v4l2-flash-led-class: Create separate sub-devices for indicators
In reply to Sakari AilusThe V4L2 flash interface allows controlling multiple LEDs through a single sub-devices if, and only if, these LEDs are of different types. This approach scales badly for flash controllers that drive multiple flash LEDs or for LED specific associations. Essentially, the original assumption of a LED driver chip that drives a single flash LED and an indicator LED is no longer valid.
Address the matter by registering one sub-device per LED.
--- drivers/leds/leds-aat1290.c | 4 +- drivers/leds/leds-max77693.c | 4 +- drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++++++++++++++---------- drivers/staging/greybus/light.c | 23 +++-- include/media/v4l2-flash-led-class.h | 41 ++++++--- 5 files changed, 117 insertions(+), 68 deletions(-)
drivers/leds/leds-aat1290.c +2 -2
@@ -432,7 +432,7 @@ static void aat1290_init_v4l2_flash_config(struct aat1290_led *led,strlcpy (v4l2_sd_cfg->dev_name, led_cdev->name,sizeof (v4l2_sd_cfg->dev_name)); - s = &v4l2_sd_cfg->torch_intensity; + s = &v4l2_sd_cfg->intensity; s->min = led->mm_current_scale[0 ]; s->max = led_cfg->max_mm_current; s->step =1 ;
@@ -504,7 +504,7 @@ static int aat1290_led_probe(struct platform_device *pdev)/* Create V4L2 Flash subdev. */ led->v4l2_flash =v4l2_flash_init (dev,of_fwnode_handle (sub_node), - fled_cdev,NULL , &v4l2_flash_ops, + fled_cdev, &v4l2_flash_ops, &v4l2_sd_cfg);if (IS_ERR (led->v4l2_flash)) { ret =PTR_ERR (led->v4l2_flash);
drivers/leds/leds-max77693.c +2 -2
@@ -856,7 +856,7 @@ static void max77693_init_v4l2_flash_config(struct max77693_sub_led *sub_led,"%s %d-%04x" , sub_led->fled_cdev.led_cdev.name, i2c_adapter_id(i2c->adapter), i2c->addr); - s = &v4l2_sd_cfg->torch_intensity; + s = &v4l2_sd_cfg->intensity; s->min =TORCH_IOUT_MIN ; s->max = sub_led->fled_cdev.led_cdev.max_brightness *TORCH_IOUT_STEP ; s->step =TORCH_IOUT_STEP ;
@@ -931,7 +931,7 @@ static int max77693_register_led(struct max77693_sub_led *sub_led,/* Register in the V4L2 subsystem. */ sub_led->v4l2_flash =v4l2_flash_init (dev,of_fwnode_handle (sub_node), - fled_cdev,NULL , &v4l2_flash_ops, + fled_cdev, &v4l2_flash_ops, &v4l2_sd_cfg);if (IS_ERR (sub_led->v4l2_flash)) { ret =PTR_ERR (sub_led->v4l2_flash);
drivers/media/v4l2-core/v4l2-flash-led-class.c +67 -46
207 lines not on this page · raw message
drivers/staging/greybus/light.c +18 -5
@@ -58,6 +58,7 @@ struct gb_light {bool ready;#if IS_REACHABLE (CONFIG_V4L2_FLASH_LED_CLASS )struct v4l2_flash *v4l2_flash; +struct v4l2_flash *v4l2_flash_ind;#endif };
@@ -534,7 +535,7 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) {struct gb_connection *connection =get_conn_from_light (light);struct device *dev = &connection->bundle->dev; -struct v4l2_flash_config sd_cfg = { {0 } }; +struct v4l2_flash_config sd_cfg = { {0 } }, sd_cfg_ind = { {0 } };struct led_classdev_flash *fled;struct led_classdev *iled =NULL ;struct gb_channel *channel_torch, *channel_ind, *channel_flash;
@@ -542,12 +543,12 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) channel_torch =get_channel_from_mode (light,GB_CHANNEL_MODE_TORCH );if (channel_torch)__gb_lights_channel_v4l2_config (&channel_torch->intensity_uA, - &sd_cfg.torch_intensity); + &sd_cfg.intensity); channel_ind =get_channel_from_mode (light,GB_CHANNEL_MODE_INDICATOR );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg.indicator_intensity); + &sd_cfg_ind.intensity); iled = &channel_ind->fled.led_cdev; }
@@ -557,6 +558,8 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) fled = &channel_flash->fled;snprintf (sd_cfg.dev_name,sizeof (sd_cfg.dev_name),"%s" , light->name); +snprintf (sd_cfg_ind.dev_name,sizeof (sd_cfg_ind.dev_name), +"%s indicator" , light->name);/* Set the possible values to faults, in our case all faults */ sd_cfg.flash_faults = LED_FAULT_OVER_VOLTAGE | LED_FAULT_TIMEOUT |
@@ -565,16 +568,26 @@ static int gb_lights_light_v4l2_register(struct gb_light *light)LED_FAULT_UNDER_VOLTAGE |LED_FAULT_INPUT_VOLTAGE |LED_FAULT_LED_OVER_TEMPERATURE ; - light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, &sd_cfg); + light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, &v4l2_flash_ops, + &sd_cfg);if (IS_ERR_OR_NULL (light->v4l2_flash))return PTR_ERR (light->v4l2_flash); +if (channel_ind) { + light->v4l2_flash_ind = +v4l2_flash_indicator_init (dev,NULL , iled, &sd_cfg_ind); +if (IS_ERR_OR_NULL (light->v4l2_flash_ind)) { +v4l2_flash_release (light->v4l2_flash); +return PTR_ERR (light->v4l2_flash_ind); + } + } + return 0; }static void gb_lights_light_v4l2_unregister (struct gb_light *light) { +v4l2_flash_release (light->v4l2_flash_ind);v4l2_flash_release (light->v4l2_flash); }#else
include/media/v4l2-flash-led-class.h +28 -13
71 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH v2 2/3] v4l2-flash-led-class: Create separate sub-devices for indicators
Hi,
Quoted 9 lines · Sakari Ailus
The V4L2 flash interface allows controlling multiple LEDs through a single sub-devices if, and only if, these LEDs are of different types. This approach scales badly for flash controllers that drive multiple flash LEDs or for LED specific associations. Essentially, the original assumption of a LED driver chip that drives a single flash LED and an indicator LED is no longer valid.
Address the matter by registering one sub-device per LED.
Quoted 8 lines
Signed-off-by Sakari Ailus <[email protected]>Reviewed-by Jacek Anaszewski <[email protected]>Acked-by Pavel Machek <[email protected]>--- drivers/leds/leds-aat1290.c | 4 +- drivers/leds/leds-max77693.c | 4 +- drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++++++++++++++---------- drivers/staging/greybus/light.c | 23 +++--
For greybus/light:
---
Cheers,
Rui
Re: [PATCH v2 2/3] v4l2-flash-led-class: Create separate sub-devices for indicators
In reply to Sakari AilusQuoted 7 lines · Sakari Ailus
The V4L2 flash interface allows controlling multiple LEDs through a single sub-devices if, and only if, these LEDs are of different types. This approach scales badly for flash controllers that drive multiple flash LEDs or for LED specific associations. Essentially, the original assumption of a LED driver chip that drives a single flash LED and an indicator LED is no longer valid.
Quoted 5 lines
Address the matter by registering one sub-device per LED.
Signed-off-by Sakari Ailus <[email protected]>Reviewed-by Jacek Anaszewski <[email protected]>Acked-by Pavel Machek <[email protected]>
Looks good, but I have the same comment about using '= {};' to zero a struct and the use of IS_ERR instead of IS_ERR_OR_NULL for the return value check of v4l2_flash_init as in the 1/3 patch.
After updating that you can add my:
Regards,
Hans
Quoted 428 lines
--- drivers/leds/leds-aat1290.c | 4 +- drivers/leds/leds-max77693.c | 4 +- drivers/media/v4l2-core/v4l2-flash-led-class.c | 113 +++++++++++++++---------- drivers/staging/greybus/light.c | 23 +++-- include/media/v4l2-flash-led-class.h | 41 ++++++--- 5 files changed, 117 insertions(+), 68 deletions(-)drivers/leds/leds-aat1290.c +2
-2@@ -432,7 +432,7 @@ static void aat1290_init_v4l2_flash_config(struct aat1290_led *led,strlcpy (v4l2_sd_cfg->dev_name, led_cdev->name,sizeof (v4l2_sd_cfg->dev_name)); - s = &v4l2_sd_cfg->torch_intensity; + s = &v4l2_sd_cfg->intensity; s->min = led->mm_current_scale[0 ]; s->max = led_cfg->max_mm_current; s->step =1 ;@@ -504,7 +504,7 @@ static int aat1290_led_probe(struct platform_device *pdev)/* Create V4L2 Flash subdev. */ led->v4l2_flash =v4l2_flash_init (dev,of_fwnode_handle (sub_node), - fled_cdev,NULL , &v4l2_flash_ops, + fled_cdev, &v4l2_flash_ops, &v4l2_sd_cfg);if (IS_ERR (led->v4l2_flash)) { ret =PTR_ERR (led->v4l2_flash);drivers/leds/leds-max77693.c +2
-2@@ -856,7 +856,7 @@ static void max77693_init_v4l2_flash_config(struct max77693_sub_led *sub_led,"%s %d-%04x" , sub_led->fled_cdev.led_cdev.name, i2c_adapter_id(i2c->adapter), i2c->addr); - s = &v4l2_sd_cfg->torch_intensity; + s = &v4l2_sd_cfg->intensity; s->min =TORCH_IOUT_MIN ; s->max = sub_led->fled_cdev.led_cdev.max_brightness *TORCH_IOUT_STEP ; s->step =TORCH_IOUT_STEP ;@@ -931,7 +931,7 @@ static int max77693_register_led(struct max77693_sub_led *sub_led,/* Register in the V4L2 subsystem. */ sub_led->v4l2_flash =v4l2_flash_init (dev,of_fwnode_handle (sub_node), - fled_cdev,NULL , &v4l2_flash_ops, + fled_cdev, &v4l2_flash_ops, &v4l2_sd_cfg);if (IS_ERR (sub_led->v4l2_flash)) { ret =PTR_ERR (sub_led->v4l2_flash);drivers/media/v4l2-core/v4l2-flash-led-class.c +67
-46@@ -197,7 +197,7 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c) {struct v4l2_flash *v4l2_flash =v4l2_ctrl_to_v4l2_flash (c);struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; -struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev :NULL ;struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;bool external_strobe;int ret =0 ;@@ -299,10 +299,26 @@ static void __fill_ctrl_init_data(struct v4l2_flash *v4l2_flash, struct v4l2_flash_ctrl_data *ctrl_init_data) {struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; -struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev :NULL ;struct v4l2_ctrl_config *ctrl_cfg;u32 mask; +/* Init INDICATOR_INTENSITY ctrl data */ +if (v4l2_flash->iled_cdev) { + ctrl_init_data[INDICATOR_INTENSITY ].cid = +V4L2_CID_FLASH_INDICATOR_INTENSITY ; + ctrl_cfg = &ctrl_init_data[INDICATOR_INTENSITY ].config; +__lfs_to_v4l2_ctrl_config (&flash_cfg->intensity, + ctrl_cfg); + ctrl_cfg->id =V4L2_CID_FLASH_INDICATOR_INTENSITY ; + ctrl_cfg->min =0 ; + ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE | +V4L2_CTRL_FLAG_EXECUTE_ON_WRITE ; + } + +if (!led_cdev ||WARN_ON (!(led_cdev->flags &LED_DEV_CAP_FLASH ))) +return ; +/* Init FLASH_FAULT ctrl data */ if (flash_cfg->flash_faults) { ctrl_init_data[FLASH_FAULT ].cid =V4L2_CID_FLASH_FAULT ;@@ -330,27 +346,11 @@ static void __fill_ctrl_init_data(struct v4l2_flash *v4l2_flash,/* Init TORCH_INTENSITY ctrl data */ ctrl_init_data[TORCH_INTENSITY ].cid =V4L2_CID_FLASH_TORCH_INTENSITY ; ctrl_cfg = &ctrl_init_data[TORCH_INTENSITY ].config; -__lfs_to_v4l2_ctrl_config (&flash_cfg->torch_intensity, ctrl_cfg); +__lfs_to_v4l2_ctrl_config (&flash_cfg->intensity, ctrl_cfg); ctrl_cfg->id =V4L2_CID_FLASH_TORCH_INTENSITY ; ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE |V4L2_CTRL_FLAG_EXECUTE_ON_WRITE ; -/* Init INDICATOR_INTENSITY ctrl data */ -if (v4l2_flash->iled_cdev) { - ctrl_init_data[INDICATOR_INTENSITY ].cid = -V4L2_CID_FLASH_INDICATOR_INTENSITY ; - ctrl_cfg = &ctrl_init_data[INDICATOR_INTENSITY ].config; -__lfs_to_v4l2_ctrl_config (&flash_cfg->indicator_intensity, - ctrl_cfg); - ctrl_cfg->id =V4L2_CID_FLASH_INDICATOR_INTENSITY ; - ctrl_cfg->min =0 ; - ctrl_cfg->flags =V4L2_CTRL_FLAG_VOLATILE | -V4L2_CTRL_FLAG_EXECUTE_ON_WRITE ; - } - -if (!(led_cdev->flags &LED_DEV_CAP_FLASH )) -return ; -/* Init FLASH_STROBE ctrl data */ ctrl_init_data[FLASH_STROBE ].cid =V4L2_CID_FLASH_STROBE ; ctrl_cfg = &ctrl_init_data[FLASH_STROBE ].config;@@ -485,7 +485,9 @@ static int __sync_device_with_v4l2_controls(struct v4l2_flash *v4l2_flash)struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;int ret =0 ; -v4l2_flash_set_led_brightness (v4l2_flash, ctrls[TORCH_INTENSITY ]); +if (ctrls[TORCH_INTENSITY ]) +v4l2_flash_set_led_brightness (v4l2_flash, + ctrls[TORCH_INTENSITY ]);if (ctrls[INDICATOR_INTENSITY ]) v4l2_flash_set_led_brightness(v4l2_flash,@@ -527,19 +529,21 @@ static int v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) {struct v4l2_flash *v4l2_flash =v4l2_subdev_to_v4l2_flash (sd);struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; -struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev :NULL ;struct led_classdev *led_cdev_ind = v4l2_flash->iled_cdev;int ret =0 ;if (!v4l2_fh_is_singular (&fh->vfh))return 0 ; -mutex_lock (&led_cdev->led_access); +if (led_cdev) { +mutex_lock (&led_cdev->led_access); -led_sysfs_disable (led_cdev); -led_trigger_remove (led_cdev); +led_sysfs_disable (led_cdev); +led_trigger_remove (led_cdev); -mutex_unlock (&led_cdev->led_access); +mutex_unlock (&led_cdev->led_access); + }if (led_cdev_ind) {mutex_lock (&led_cdev_ind->led_access);@@ -556,9 +560,11 @@ static int v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)return 0 ; out_sync_device: -mutex_lock (&led_cdev->led_access); -led_sysfs_enable (led_cdev); -mutex_unlock (&led_cdev->led_access); +if (led_cdev) { +mutex_lock (&led_cdev->led_access); +led_sysfs_enable (led_cdev); +mutex_unlock (&led_cdev->led_access); + }if (led_cdev_ind) {mutex_lock (&led_cdev_ind->led_access);@@ -573,21 +579,24 @@ static int v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) {struct v4l2_flash *v4l2_flash =v4l2_subdev_to_v4l2_flash (sd);struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; -struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev :NULL ;struct led_classdev *led_cdev_ind = v4l2_flash->iled_cdev;int ret =0 ;if (!v4l2_fh_is_singular (&fh->vfh))return 0 ; -mutex_lock (&led_cdev->led_access); +if (led_cdev) { +mutex_lock (&led_cdev->led_access); -if (v4l2_flash->ctrls[STROBE_SOURCE ]) - ret =v4l2_ctrl_s_ctrl (v4l2_flash->ctrls[STROBE_SOURCE ], +if (v4l2_flash->ctrls[STROBE_SOURCE ]) + ret =v4l2_ctrl_s_ctrl ( + v4l2_flash->ctrls[STROBE_SOURCE ],V4L2_FLASH_STROBE_SOURCE_SOFTWARE ); -led_sysfs_enable (led_cdev); +led_sysfs_enable (led_cdev); -mutex_unlock (&led_cdev->led_access); +mutex_unlock (&led_cdev->led_access); + }if (led_cdev_ind) {mutex_lock (&led_cdev_ind->led_access);@@ -605,25 +614,19 @@ static const struct v4l2_subdev_internal_ops v4l2_flash_subdev_internal_ops = {static const struct v4l2_subdev_ops v4l2_flash_subdev_ops; -struct v4l2_flash *v4l2_flash_init ( +static struct v4l2_flash *__v4l2_flash_init (struct device *dev,struct fwnode_handle *fwn, -struct led_classdev_flash *fled_cdev, -struct led_classdev *iled_cdev, -const struct v4l2_flash_ops *ops, -struct v4l2_flash_config *config) +struct led_classdev_flash *fled_cdev,struct led_classdev *iled_cdev, +const struct v4l2_flash_ops *ops,struct v4l2_flash_config *config) {struct v4l2_flash *v4l2_flash; -struct led_classdev *led_cdev;struct v4l2_subdev *sd;int ret; -if (!fled_cdev || !config) +if (!config)return ERR_PTR (-EINVAL ); - led_cdev = &fled_cdev->led_cdev; - - v4l2_flash =devm_kzalloc (led_cdev->dev,sizeof (*v4l2_flash), -GFP_KERNEL ); + v4l2_flash =devm_kzalloc (dev,sizeof (*v4l2_flash),GFP_KERNEL );if (!v4l2_flash)return ERR_PTR (-ENOMEM );@@ -632,7 +635,7 @@ struct v4l2_flash *v4l2_flash_init( v4l2_flash->iled_cdev = iled_cdev; v4l2_flash->ops = ops; sd->dev = dev; - sd->fwnode = fwn ? fwn :dev_fwnode (led_cdev->dev); + sd->fwnode = fwn ? fwn :dev_fwnode (dev);v4l2_subdev_init (sd, &v4l2_flash_subdev_ops); sd->internal_ops = &v4l2_flash_subdev_internal_ops; sd->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;@@ -664,8 +667,26 @@ struct v4l2_flash *v4l2_flash_init(return ERR_PTR (ret); } + +struct v4l2_flash *v4l2_flash_init ( +struct device *dev,struct fwnode_handle *fwn, +struct led_classdev_flash *fled_cdev, +const struct v4l2_flash_ops *ops, +struct v4l2_flash_config *config) +{ +return __v4l2_flash_init (dev, fwn, fled_cdev,NULL , ops, config); +}EXPORT_SYMBOL_GPL (v4l2_flash_init); +struct v4l2_flash *v4l2_flash_indicator_init ( +struct device *dev,struct fwnode_handle *fwn, +struct led_classdev *iled_cdev, +struct v4l2_flash_config *config) +{ +return __v4l2_flash_init (dev, fwn,NULL , iled_cdev,NULL , config); +} +EXPORT_SYMBOL_GPL (v4l2_flash_indicator_init); +void v4l2_flash_release (struct v4l2_flash *v4l2_flash) {struct v4l2_subdev *sd;drivers/staging/greybus/light.c +18
-5@@ -58,6 +58,7 @@ struct gb_light {bool ready;#if IS_REACHABLE (CONFIG_V4L2_FLASH_LED_CLASS )struct v4l2_flash *v4l2_flash; +struct v4l2_flash *v4l2_flash_ind;#endif };@@ -534,7 +535,7 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) {struct gb_connection *connection =get_conn_from_light (light);struct device *dev = &connection->bundle->dev; -struct v4l2_flash_config sd_cfg = { {0 } }; +struct v4l2_flash_config sd_cfg = { {0 } }, sd_cfg_ind = { {0 } };struct led_classdev_flash *fled;struct led_classdev *iled =NULL ;struct gb_channel *channel_torch, *channel_ind, *channel_flash;@@ -542,12 +543,12 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) channel_torch =get_channel_from_mode (light,GB_CHANNEL_MODE_TORCH );if (channel_torch)__gb_lights_channel_v4l2_config (&channel_torch->intensity_uA, - &sd_cfg.torch_intensity); + &sd_cfg.intensity); channel_ind =get_channel_from_mode (light,GB_CHANNEL_MODE_INDICATOR );if (channel_ind) {__gb_lights_channel_v4l2_config (&channel_ind->intensity_uA, - &sd_cfg.indicator_intensity); + &sd_cfg_ind.intensity); iled = &channel_ind->fled.led_cdev; }@@ -557,6 +558,8 @@ static int gb_lights_light_v4l2_register(struct gb_light *light) fled = &channel_flash->fled;snprintf (sd_cfg.dev_name,sizeof (sd_cfg.dev_name),"%s" , light->name); +snprintf (sd_cfg_ind.dev_name,sizeof (sd_cfg_ind.dev_name), +"%s indicator" , light->name);/* Set the possible values to faults, in our case all faults */ sd_cfg.flash_faults = LED_FAULT_OVER_VOLTAGE | LED_FAULT_TIMEOUT |@@ -565,16 +568,26 @@ static int gb_lights_light_v4l2_register(struct gb_light *light)LED_FAULT_UNDER_VOLTAGE |LED_FAULT_INPUT_VOLTAGE |LED_FAULT_LED_OVER_TEMPERATURE ; - light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, iled, - &v4l2_flash_ops, &sd_cfg); + light->v4l2_flash =v4l2_flash_init (dev,NULL , fled, &v4l2_flash_ops, + &sd_cfg);if (IS_ERR_OR_NULL (light->v4l2_flash))return PTR_ERR (light->v4l2_flash); +if (channel_ind) { + light->v4l2_flash_ind = +v4l2_flash_indicator_init (dev,NULL , iled, &sd_cfg_ind); +if (IS_ERR_OR_NULL (light->v4l2_flash_ind)) { +v4l2_flash_release (light->v4l2_flash); +return PTR_ERR (light->v4l2_flash_ind); + } + } + return 0; }static void gb_lights_light_v4l2_unregister (struct gb_light *light) { +v4l2_flash_release (light->v4l2_flash_ind);v4l2_flash_release (light->v4l2_flash); }#else include/media/v4l2-flash-led-class.h +28
-13@@ -56,8 +56,7 @@ struct v4l2_flash_ops {* struct v4l2_flash_config - V4L2 Flash sub-device initialization data * @dev_name: the name of the media entity, * unique in the system -* @torch_intensity: constraints for the LED in torch mode -* @indicator_intensity: constraints for the indicator LED +* @intensity: non-flash strobe constraints for the LED * @flash_faults: bitmask of flash faults that the LED flash class * device can report; corresponding LED_FAULT* bit * definitions are available in the header file @@ -66,8 +65,7 @@ struct v4l2_flash_ops {*/ struct v4l2_flash_config {char dev_name[32 ]; -struct led_flash_setting torch_intensity; -struct led_flash_setting indicator_intensity; +struct led_flash_setting intensity;u32 flash_faults;unsigned int has_external_strobe:1 ; };@@ -110,8 +108,6 @@ static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)* @dev: flash device, e.g. an I2C device * @fwn: fwnode_handle of the LED, may be NULL if the same as device's * @fled_cdev: LED flash class device to wrap -* @iled_cdev: LED flash class device representing indicator LED associated -* with fled_cdev, may be NULL * @ops: V4L2 Flash device ops * @config: initialization data for V4L2 Flash sub-device * @@ -124,9 +120,24 @@ static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)struct v4l2_flash *v4l2_flash_init (struct device *dev,struct fwnode_handle *fwn,struct led_classdev_flash *fled_cdev, -struct led_classdev *iled_cdev, -const struct v4l2_flash_ops *ops, -struct v4l2_flash_config *config); +const struct v4l2_flash_ops *ops,struct v4l2_flash_config *config); + +/** +* v4l2_flash_indicator_init - initialize V4L2 indicator sub-device +* @dev: flash device, e.g. an I2C device +* @fwn: fwnode_handle of the LED, may be NULL if the same as device's +* @iled_cdev: LED flash class device representing the indicator LED +* @config: initialization data for V4L2 Flash sub-device +* +* Create V4L2 Flash sub-device wrapping given LED subsystem device. +* +* Returns: A valid pointer, or, when an error occurs, the return +* value is encoded using ERR_PTR(). Use IS_ERR() to check and +* PTR_ERR() to obtain the numeric return value. +*/ +struct v4l2_flash *v4l2_flash_indicator_init ( +struct device *dev,struct fwnode_handle *fwn, +struct led_classdev *iled_cdev,struct v4l2_flash_config *config);/** * v4l2_flash_release - release V4L2 Flash sub-device @@ -139,10 +150,14 @@ void v4l2_flash_release(struct v4l2_flash *v4l2_flash);#else static inline struct v4l2_flash *v4l2_flash_init (struct device *dev,struct fwnode_handle *fwn, -struct led_classdev_flash *fled_cdev, -struct led_classdev *iled_cdev, -const struct v4l2_flash_ops *ops, -struct v4l2_flash_config *config) +struct led_classdev_flash *fled_cdev,struct v4l2_flash_config *config) +{ +return NULL ; +} + +static inline struct v4l2_flash *v4l2_flash_indicator_init ( +struct device *dev,struct fwnode_handle *fwn, +struct led_classdev *iled_cdev,struct v4l2_flash_config *config) {return NULL ; }
PATCH v2 3/3 v4l2-flash-led-class: Document v4l2_flash_init() references
In reply to Sakari AilusThe v4l2_flash_init() keeps a reference to the ops struct but not to the config struct (nor anything it contains). Document this.
--- include/media/v4l2-flash-led-class.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/media/v4l2-flash-led-class.h +6 -0
@@ -112,6 +112,9 @@ static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)* @config: initialization data for V4L2 Flash sub-device * * Create V4L2 Flash sub-device wrapping given LED subsystem device. +* The ops pointer is stored by the V4L2 flash framework. No +* references are held to config nor its contents once this function +* has returned. * * Returns: A valid pointer, or, when an error occurs, the return * value is encoded using ERR_PTR(). Use IS_ERR() to check and
@@ -130,6 +133,9 @@ struct v4l2_flash *v4l2_flash_init(* @config: initialization data for V4L2 Flash sub-device * * Create V4L2 Flash sub-device wrapping given LED subsystem device. +* The ops pointer is stored by the V4L2 flash framework. No +* references are held to config nor its contents once this function +* has returned. * * Returns: A valid pointer, or, when an error occurs, the return * value is encoded using ERR_PTR(). Use IS_ERR() to check and
Signature · 1 line
2.11.0
Re: [PATCH v2 3/3] v4l2-flash-led-class: Document v4l2_flash_init() references
Quoted 5 lines · Sakari Ailus
The
v4l2_flash_init()keeps a reference to the ops struct but not to the config struct (nor anything it contains). Document this.Signed-off-by Sakari Ailus <[email protected]>Acked-by Pavel Machek <[email protected]>
Regards,
Hans
Quoted 29 lines
--- include/media/v4l2-flash-led-class.h | 6 ++++++ 1 file changed, 6 insertions(+)include/media/v4l2-flash-led-class.h +6
-0@@ -112,6 +112,9 @@ static inline struct v4l2_flash *v4l2_ctrl_to_v4l2_flash(struct v4l2_ctrl *c)* @config: initialization data for V4L2 Flash sub-device * * Create V4L2 Flash sub-device wrapping given LED subsystem device. +* The ops pointer is stored by the V4L2 flash framework. No +* references are held to config nor its contents once this function +* has returned. * * Returns: A valid pointer, or, when an error occurs, the return * value is encoded using ERR_PTR(). Use IS_ERR() to check and @@ -130,6 +133,9 @@ struct v4l2_flash *v4l2_flash_init(* @config: initialization data for V4L2 Flash sub-device * * Create V4L2 Flash sub-device wrapping given LED subsystem device. +* The ops pointer is stored by the V4L2 flash framework. No +* references are held to config nor its contents once this function +* has returned. * * Returns: A valid pointer, or, when an error occurs, the return * value is encoded using ERR_PTR(). Use IS_ERR() to check and