Skip to contentSkip to conversation

drm/i915/selftests: Fix uninitialized variable

PATCH In review Aditya Swarup 4 participants 7 messages Mar 3, 2020 – Mar 4, 2020

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

PATCH 1/1 drm/i915/selftests: Fix uninitialized variable

Static code analysis tool identified struct lrc_timestamp data as being uninitialized and then data.ce[] is being checked for NULL/negative value in the error path. Initializing data variable fixes the issue.

Cc Matt Roper <[email protected]>
Cc Chris Wilson <[email protected]>
---
 drivers/gpu/drm/i915/gt/selftest_lrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/selftest_lrc.c +1 -1
index ccf9debacd90..9b75b3c77a5b 100644
@@ -4725,7 +4725,7 @@ static int live_lrc_timestamp(void *arg)
 {
 	struct intel_gt *gt = arg;
 	enum intel_engine_id id;
-	struct lrc_timestamp data;
+	struct lrc_timestamp data = { 0 };
 	const u32 poison[] = {
 		0,
 		S32_MAX,
Signature · 6 lines
2.25.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#1 lore raw
Quoted 16 lines · Aditya Swarup

Static code analysis tool identified struct lrc_timestamp data as being uninitialized and then data.ce[] is being checked for NULL/negative value in the error path. Initializing data variable fixes the issue.

Cc Matt Roper <[email protected]>
Cc Chris Wilson <[email protected]>
---
 drivers/gpu/drm/i915/gt/selftest_lrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/selftest_lrc.c +0 -0
index ccf9debacd90..9b75b3c77a5b 100644

drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_lrc_timestamp(void *arg) · line 4728

Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +1 -1
@@ -4725,7 +4725,7 @@ static int live_lrc_timestamp(void *arg)
 {
 	struct intel_gt *gt = arg;
 	enum intel_engine_id id;
-	struct lrc_timestamp data;
+	struct lrc_timestamp data = { 0 };

{} is preferred over {0}.

BR,
Jani.

Quoted 3 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +0 -0
 	const u32 poison[] = {
 		0,
 		S32_MAX,
Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 12 lines · Jani Nikula
Quoted 11 lines · Aditya Swarup

Static code analysis tool identified struct lrc_timestamp data as being uninitialized and then data.ce[] is being checked for NULL/negative value in the error path. Initializing data variable fixes the issue.

Cc Matt Roper <[email protected]>
Cc Chris Wilson <[email protected]>
---
 drivers/gpu/drm/i915/gt/selftest_lrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_lrc_timestamp(void *arg) · line 4728

Quoted 10 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +1 -1
index ccf9debacd90..9b75b3c77a5b 100644
@@ -4725,7 +4725,7 @@ static int live_lrc_timestamp(void *arg)
 {
 	struct intel_gt *gt = arg;
 	enum intel_engine_id id;
-	struct lrc_timestamp data;
+	struct lrc_timestamp data = { 0 };

{} is preferred over {0}.

Is there a reference for this (e.g., in the kernel coding style)? I thought this came up a couple years ago and the consensus was the other way, although I could be misremembering. Unless it's changed in a recent standard, I think {} is only legal in C++, so using it in C code is a gcc-ism?

Matt

Quoted 14 lines

BR,
Jani.

Quoted 3 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +0 -0
 	const u32 poison[] = {
 		0,
 		S32_MAX,
Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 9 lines
Matt Roper
Graphics Software Engineer
VTT-OSGC Platform Enablement
Intel Corporation
(916) 356-2795
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#3 lore raw
Quoted 7 lines · Matt Roper
Quoted 5 lines · Jani Nikula

drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_lrc_timestamp(void *arg) · line 4728

Quoted 2 lines · Aditya Swarup
drivers/gpu/drm/i915/gt/selftest_lrc.c +1 -1
-	struct lrc_timestamp data;
+	struct lrc_timestamp data = { 0 };

{} is preferred over {0}.

Quoted 5 lines

Is there a reference for this (e.g., in the kernel coding style)? I thought this came up a couple years ago and the consensus was the other way, although I could be misremembering. Unless it's changed in a recent standard, I think {} is only legal in C++, so using it in C code is a gcc-ism?

Both are widely used in the kernel. I think we've mostly converged to {} in i915. Yes, it's a gcc-ism in C code, but the kernel is gcc, not standard C.

I can't find a reference right now, but ISTR there are some warnings issued in some cases with the {0} initializer, depending on the struct and perhaps on the compiler.

Anyway, we're 71 to 9 in favor of {} in i915, so please go with that.

BR,
Jani.

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#4 lore raw
Quoted 14 lines · Jani Nikula
Quoted 7 lines · Matt Roper
Quoted 5 lines · Jani Nikula

drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_lrc_timestamp(void *arg) · line 4728

Quoted 2 lines · Aditya Swarup
drivers/gpu/drm/i915/gt/selftest_lrc.c +1 -1
-	struct lrc_timestamp data;
+	struct lrc_timestamp data = { 0 };

{} is preferred over {0}.

Quoted 5 lines

Is there a reference for this (e.g., in the kernel coding style)? I thought this came up a couple years ago and the consensus was the other way, although I could be misremembering. Unless it's changed in a recent standard, I think {} is only legal in C++, so using it in C code is a gcc-ism?

Quoted 7 lines

Both are widely used in the kernel. I think we've mostly converged to {} in i915. Yes, it's a gcc-ism in C code, but the kernel is gcc, not standard C.

I can't find a reference right now, but ISTR there are some warnings issued in some cases with the {0} initializer, depending on the struct and perhaps on the compiler.

Here's one [1].

BR,
Jani.

[1] http://patchwork.freedesktop.org/patch/msgid/20200304183654.GA9011@paulmck-ThinkPad-P72

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

[Intel-gfx] ✗ Fi.CI.BUILD: failure for drm/i915/selftests: Fix uninitialized variable (rev2)

In reply to Aditya Swarup
== Series Details ==

== Series Details ==

Series: drm/i915/selftests: Fix uninitialized variable (rev2)
URL : https://patchwork.freedesktop.org/series/42194/
State : failure

== Summary ==

Applying: drm/i915/selftests: Fix uninitialized variable
Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/gt/selftest_lrc.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/gpu/drm/i915/gt/selftest_lrc.c
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/gt/selftest_lrc.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch Patch failed at 0001 drm/i915/selftests: Fix uninitialized variable When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by on v1 1/1
#6 lore raw
In reply to Aditya Swarup
Quoted 7 lines · Aditya Swarup

Static code analysis tool identified struct lrc_timestamp data as being uninitialized and then data.ce[] is being checked for NULL/negative value in the error path. Initializing data variable fixes the issue.

Cc Matt Roper <[email protected]>
Cc Chris Wilson <[email protected]>
Quoted 20 lines
---
 drivers/gpu/drm/i915/gt/selftest_lrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/selftest_lrc.c +1 -1
index ccf9debacd90..9b75b3c77a5b 100644
@@ -4725,7 +4725,7 @@ static int live_lrc_timestamp(void *arg)
 {
 	struct intel_gt *gt = arg;
 	enum intel_engine_id id;
-	struct lrc_timestamp data;
+	struct lrc_timestamp data = { 0 };
 	const u32 poison[] = {
 		0,
 		S32_MAX,
Signature · 1 line
2.25.0
Signature · 9 lines
Matt Roper
Graphics Software Engineer
VTT-OSGC Platform Enablement
Intel Corporation
(916) 356-2795
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx