Skip to contentSkip to conversation

drm/komeda: Use memset to initialize config_id

PATCH In review Nathan Chancellor 3 participants 3 messages Apr 25, 2019 – Apr 26, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/komeda: Use memset to initialize config_id

Clang warns:

drivers/gpu/drm/arm/display/komeda/komeda_dev.c:76:38: warning: suggest braces around initialization of subobject [-Wmissing-braces]

        union komeda_config_id config_id = {0,};
                                            ^
                                            {}

1 warning generated.

One way to fix these warnings is to add additional braces like Clang suggests; however, there has been a bit of push back from some maintainers, who just prefer memset as it is unambiguous, doesn't depend on a particular compiler version, and properly initializes all subobjects [1][2]. Do that here so there are no more warnings.

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/

Fixes 4cc734cb79a8 ("drm/komeda: Add sysfs attribute: core_id and config_id")
---
 drivers/gpu/drm/arm/display/komeda/komeda_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_dev.c +2 -1
index 9d6c31cca875..e605a518f59a 100644
@@ -73,9 +73,10 @@ config_id_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct komeda_dev *mdev = dev_to_mdev(dev);
 	struct komeda_pipeline *pipe = mdev->pipelines[0];
-	union komeda_config_id config_id = {0,};
+	union komeda_config_id config_id;
 	int i;
 
+	memset(&config_id, 0, sizeof(config_id));
 	config_id.max_line_sz = pipe->layers[0]->hsize_in.end;
 	config_id.n_pipelines = mdev->n_pipelines;
 	config_id.n_scalers = pipe->n_scalers;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Nathan Chancellor

Clang warns:

drivers/gpu/drm/arm/display/komeda/komeda_dev.c:76:38: warning: suggest braces around initialization of subobject [-Wmissing-braces]

        union komeda_config_id config_id = {0,};
                                            ^
                                            {}

1 warning generated.

One way to fix these warnings is to add additional braces like Clang suggests; however, there has been a bit of push back from some maintainers, who just prefer memset as it is unambiguous, doesn't depend on a particular compiler version, and properly initializes all subobjects [1][2]. Do that here so there are no more warnings.

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/

Fixes 4cc734cb79a8 ("drm/komeda: Add sysfs attribute: core_id and config_id")
---
 drivers/gpu/drm/arm/display/komeda/komeda_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_dev.c +0 -0
index 9d6c31cca875..e605a518f59a 100644

drivers/gpu/drm/arm/display/komeda/komeda_dev.c config_id_show(struct device *dev, struct device_attribute *attr, char *buf) · line 76

Quoted 4 lines
drivers/gpu/drm/arm/display/komeda/komeda_dev.c +0 -1
@@ -73,9 +73,10 @@ config_id_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct komeda_dev *mdev = dev_to_mdev(dev);
        struct komeda_pipeline *pipe = mdev->pipelines[0];
-       union komeda_config_id config_id = {0,};

Haven't seen a trailing comma too often. Thanks for the patch.

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_dev.c +2 -1
+       union komeda_config_id config_id;
        int i;
 
+       memset(&config_id, 0, sizeof(config_id));
        config_id.max_line_sz = pipe->layers[0]->hsize_in.end;
        config_id.n_pipelines = mdev->n_pipelines;
        config_id.n_scalers = pipe->n_scalers;
--

2.21.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Nathan Chancellor
Quoted 15 lines · Nathan Chancellor

Clang warns:

drivers/gpu/drm/arm/display/komeda/komeda_dev.c:76:38: warning: suggest braces around initialization of subobject [-Wmissing-braces]

        union komeda_config_id config_id = {0,};
                                            ^
                                            {}

1 warning generated.

One way to fix these warnings is to add additional braces like Clang suggests; however, there has been a bit of push back from some maintainers, who just prefer memset as it is unambiguous, doesn't depend on a particular compiler version, and properly initializes all subobjects [1][2]. Do that here so there are no more warnings.

Quoted 6 lines

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/

Fixes 4cc734cb79a8 ("drm/komeda: Add sysfs attribute: core_id and config_id")

I'll pull the patch into my tree today.

Best regards,
Liviu

Quoted 23 lines
---
 drivers/gpu/drm/arm/display/komeda/komeda_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_dev.c +2 -1
index 9d6c31cca875..e605a518f59a 100644
@@ -73,9 +73,10 @@ config_id_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct komeda_dev *mdev = dev_to_mdev(dev);
 	struct komeda_pipeline *pipe = mdev->pipelines[0];
-	union komeda_config_id config_id = {0,};
+	union komeda_config_id config_id;
 	int i;
 
+	memset(&config_id, 0, sizeof(config_id));
 	config_id.max_line_sz = pipe->layers[0]->hsize_in.end;
 	config_id.n_pipelines = mdev->n_pipelines;
 	config_id.n_scalers = pipe->n_scalers;
Signature · 1 line
2.21.0
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯