[PATCH 21/28] iio: light: veml6030: use = { } instead of memset()

David Lechner posted 28 patches 4 months ago
[PATCH 21/28] iio: light: veml6030: use = { } instead of memset()
Posted by David Lechner 4 months ago
Use { } instead of memset() to zero-initialize stack memory to simplify
the code.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/light/veml6030.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/iio/light/veml6030.c b/drivers/iio/light/veml6030.c
index 473a9c3e32a3a53f373595a5113b47e795f5366c..0945f146bedbda79511e704158122acaac5e60c1 100644
--- a/drivers/iio/light/veml6030.c
+++ b/drivers/iio/light/veml6030.c
@@ -892,9 +892,7 @@ static irqreturn_t veml6030_trigger_handler(int irq, void *p)
 	struct {
 		u16 chans[2];
 		aligned_s64 timestamp;
-	} scan;
-
-	memset(&scan, 0, sizeof(scan));
+	} scan = { };
 
 	iio_for_each_active_channel(iio, ch) {
 		ret = regmap_read(data->regmap, VEML6030_REG_DATA(ch),

-- 
2.43.0
Re: [PATCH 21/28] iio: light: veml6030: use = { } instead of memset()
Posted by Javier Carrasco 4 months ago
On Thu Jun 12, 2025 at 3:39 AM +05, David Lechner wrote:
> Use { } instead of memset() to zero-initialize stack memory to simplify
> the code.
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>  drivers/iio/light/veml6030.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/iio/light/veml6030.c b/drivers/iio/light/veml6030.c
> index 473a9c3e32a3a53f373595a5113b47e795f5366c..0945f146bedbda79511e704158122acaac5e60c1 100644
> --- a/drivers/iio/light/veml6030.c
> +++ b/drivers/iio/light/veml6030.c
> @@ -892,9 +892,7 @@ static irqreturn_t veml6030_trigger_handler(int irq, void *p)
>  	struct {
>  		u16 chans[2];
>  		aligned_s64 timestamp;
> -	} scan;
> -
> -	memset(&scan, 0, sizeof(scan));
> +	} scan = { };
>  
>  	iio_for_each_active_channel(iio, ch) {
>  		ret = regmap_read(data->regmap, VEML6030_REG_DATA(ch),

Thank you for the patch, it looks cleaner and simpler :) I trust the
sources you provided, but I tested it with real hardware just in case.

Tested-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Reviewed-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>