drm/i915/dsi: silence a warning about uninitialized return value
Subsystems (2)
PATCH 1/1 drm/i915/dsi: silence a warning about uninitialized return value
When building the kernel with clang and some warning flags, the compiler reports that the return value of dcs_get_backlight() may be uninitialized:
drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable
'data' is used uninitialized whenever 'for' loop exits because its
condition is false [-Werror,-Wsometimes-uninitialized]
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro
'for_each_dsi_port'
#define for_each_dsi_port(__port, __ports_mask)
for_each_port_masked(__port, __ports_mask)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro
'for_each_port_masked'
for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note:
uninitialized use occurs here
return data;
^~~~As intel_dsi->dcs_backlight_ports seems to be always initialized to a non-null value, the content of the for loop is always executed and there is no bug in the current code. Nevertheless the compiler has no way of knowing that assumption, so initialize variable 'data' to silence the warning here.
--- drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c +1 -1
@@ -46,7 +46,7 @@ static u32 dcs_get_backlight(struct intel_connector *connector)struct intel_encoder *encoder = connector->encoder;struct intel_dsi *intel_dsi =enc_to_intel_dsi (&encoder->base);struct mipi_dsi_device *dsi_device; -u8 data; +u8 data =0 ;enum port port;/* FIXME: Need to take care of 16 bit brightness level */
Signature · 1 line
2.9.3
Patchwork
CI✗ Fi.CI.BAT: failure for series starting with [1/1] drm/i915/dsi: silence a warning about uninitialized return value
== Series Details ==
== Series Details ==
Series: series starting with [1/1] drm/i915/dsi: silence a warning about uninitialized return value
URL : https://patchwork.freedesktop.org/series/12044/
State : failure
== Summary ==
Series 12044v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/12044/revisions/1/mbox/
Test gem_exec_suspend:
Subgroup basic-s3:
pass -> INCOMPLETE (fi-hsw-4770k)
Test kms_cursor_legacy:
Subgroup basic-cursor-vs-flip-varying-size:
pass -> FAIL (fi-bsw-n3050)
Test kms_flip:
Subgroup basic-flip-vs-wf_vblank:
dmesg-warn -> PASS (fi-snb-2520m)fi-bdw-5557u total:252 pass:233 dwarn:2 dfail:1 fail:1 skip:15 fi-bsw-n3050 total:252 pass:202 dwarn:1 dfail:1 fail:2 skip:46 fi-hsw-4770k total:107 pass:91 dwarn:0 dfail:0 fail:0 skip:15 fi-hsw-4770r total:252 pass:222 dwarn:2 dfail:1 fail:1 skip:26 fi-ivb-3520m total:252 pass:217 dwarn:2 dfail:1 fail:1 skip:31 fi-skl-6260u total:252 pass:234 dwarn:2 dfail:1 fail:1 skip:14 fi-skl-6700k total:252 pass:219 dwarn:3 dfail:1 fail:1 skip:28 fi-snb-2520m total:252 pass:205 dwarn:1 dfail:1 fail:2 skip:43 fi-snb-2600 total:252 pass:205 dwarn:2 dfail:1 fail:1 skip:43
Results at /archive/results/CI_IGT_test/Patchwork_2474/
8575dc5c7d052498cbf939333c102d3fcac4cd52 drm-intel-nightly: 2016y-09m-06d-08h-36m-12s UTC integration manifest 14d227f drm/i915/dsi: silence a warning about uninitialized return value
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 23 lines · Nicolas Iooss
When building the kernel with clang and some warning flags, the compiler reports that the return value of
dcs_get_backlight()may be uninitialized:drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable 'data' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized] for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro 'for_each_dsi_port' #define for_each_dsi_port(__port, __ports_mask) for_each_port_masked(__port, __ports_mask) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro 'for_each_port_masked' for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \ ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note: uninitialized use occurs here return data; ^~~~
Quoted 7 lines
As
intel_dsi->dcs_backlight_portsseems to be always initialized to a non-null value, the content of the for loop is always executed and there is no bug in the current code. Nevertheless the compiler has no way of knowing that assumption, so initialize variable 'data' to silence the warning here.Signed-off-by Nicolas Iooss <[email protected]>
Interesting ... there are two things that could lead to this (possibly) incorrect analysis. Either it thinks the loop could be executed zero times, which would be a deficiency in the compiler, as the initialiser and loop bound are both known (different) constants:
enum port {
PORT_A = 0,
PORT_B,
PORT_C,
PORT_D,
PORT_E,
I915_MAX_PORTS
};or, it doesn't understand that because we've passed &data to another function, it can have been set by the callee. It may be extra confusing that the callee takes (void *); or it may be being ultra-sophisticated in its analysis and noted that in one error path data is *not* set (and we then discard the error and use data anyway). As an experiment, you could try:
static u8 mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd)
{
u8 data = 0;
mipi_dsi_dcs_read(dsi_device, cmd, &data, sizeof(data));
return data;
}static u32 dcs_get_backlight(struct intel_connector *connector)
{
struct intel_encoder *encoder = connector->encoder;
struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
struct mipi_dsi_device *dsi_device;
enum port port;
u8 data;
/* FIXME: Need to take care of 16 bit brightness level */
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
dsi_device = intel_dsi->dsi_hosts[port]->device;
data = mipi_dsi_dcs_read1(dsi_device,
MIPI_DCS_GET_DISPLAY_BRIGHTNESS);
break;
}
return data;
}If it complains about that then it's a shortcoming in the loop analysis. If not you could try:
static u8 mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd)
{
u8 data;
ssize_t nbytes = sizeof(data);
nbytes = mipi_dsi_dcs_read(dsi_device, cmd, &data, nbytes);
return nbytes == sizeof(data) ? data : 0;
}and if complains about that then it doesn't understand that passing &data allows it to be set. If it doesn't complain about this version, then the original error was actually correct, in the sense that data can indeed be used uninitialised if certain error paths can be taken.
Here's an R-b for your fix anyway ...
.Dave.
Quoted 9 lines
drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c +0
-0
drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c static u32 dcs_get_backlight(struct intel_connector *connector) · line 52
Quoted 8 lines
drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c +1
-1@@ -46,7 +46,7 @@ static u32 dcs_get_backlight(struct intel_connector *connector)struct intel_encoder *encoder = connector->encoder;struct intel_dsi *intel_dsi =enc_to_intel_dsi (&encoder->base);struct mipi_dsi_device *dsi_device; -u8 data; +u8 data =0 ;enum port port;/* FIXME: Need to take care of 16 bit brightness level */
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 48 lines · Dave Gordon
Quoted 25 lines · Nicolas Iooss
When building the kernel with clang and some warning flags, the compiler reports that the return value of
dcs_get_backlight()may be uninitialized:drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable 'data' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized] for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro 'for_each_dsi_port' #define for_each_dsi_port(__port, __ports_mask) for_each_port_masked(__port,
__ports_mask)^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro 'for_each_port_masked' for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \ ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note: uninitialized use occurs here return data; ^~~~Quoted 7 lines
As
intel_dsi->dcs_backlight_portsseems to be always initialized to a non-null value, the content of the for loop is always executed and there is no bug in the current code. Nevertheless the compiler has no way of knowing that assumption, so initialize variable 'data' to silence the warning here.Signed-off-by Nicolas Iooss <[email protected]>Interesting ... there are two things that could lead to this (possibly) incorrect analysis. Either it thinks the loop could be executed zero times, which would be a deficiency in the compiler, as the initialiser and loop bound are both known (different) constants:
enum port { PORT_A = 0, PORT_B, PORT_C, PORT_D, PORT_E, I915_MAX_PORTS };
Quoted 6 lines
or, it doesn't understand that because we've passed &data to another function, it can have been set by the callee. It may be extra confusing that the callee takes (void *); or it may be being ultra-sophisticated in its analysis and noted that in one error path data is *not* set (and we then discard the error and use data anyway). As an experiment, you could try:
The code that the compiler sees is not a simple loop other enum 'port' but "for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {", which is expanded [1] to:
for ((port) = PORT_A; (port) < I915_MAX_PORTS; (port)++)
if (!((intel_dsi->dcs_backlight_ports) & (1 << (port)))) {} else {This is why I spoke of intel_dsi->dcs_backlight_ports in my description:
if it is zero, the body of the loop is never run.
As for the analyses of calls using &data, clang does not warn about the variable being maybe uninitialized following a call. This is quite expected as this would lead to too many false positives, even though it may miss some bugs.
Quoted 29 lines
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data = 0; mipi_dsi_dcs_read(dsi_device, cmd, &data, sizeof(data)); return data; }static u32
dcs_get_backlight(struct intel_connector *connector){ struct intel_encoder *encoder = connector->encoder; struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); struct mipi_dsi_device *dsi_device; enum port port; u8 data; /* FIXME: Need to take care of 16 bit brightness level */ for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { dsi_device = intel_dsi->dsi_hosts[port]->device; data = mipi_dsi_dcs_read1(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS); break; } return data; }
Quoted 1 line
If it complains about that then it's a shortcoming in the loop analysis.
It complains (in dcs_get_backlight), because for_each_dsi_port() still hides an 'if' condition.
Quoted 11 lines
If not you could try:
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data; ssize_t nbytes = sizeof(data); nbytes = mipi_dsi_dcs_read(dsi_device, cmd, &data, nbytes); return nbytes == sizeof(data) ? data : 0; }
Quoted 4 lines
and if complains about that then it doesn't understand that passing &data allows it to be set. If it doesn't complain about this version, then the original error was actually correct, in the sense that data can indeed be used uninitialised if certain error paths can be taken.
clang did not complain with this last case.
Quoted 3 lines
Here's an R-b for your fix anyway ...
Reviewed-by Dave Gordon <[email protected]>
Thanks!
Nicolas
[1] I used "make drivers/gpu/drm/i915/intel_dsi_dcs_backlight.i" to see the output of the preprocessor.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 96 lines · Nicolas Iooss
Quoted 48 lines · Dave Gordon
Quoted 25 lines · Nicolas Iooss
When building the kernel with clang and some warning flags, the compiler reports that the return value of
dcs_get_backlight()may be uninitialized:drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable 'data' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized] for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro 'for_each_dsi_port' #define for_each_dsi_port(__port, __ports_mask) for_each_port_masked(__port,
__ports_mask)^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro 'for_each_port_masked' for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \ ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note: uninitialized use occurs here return data; ^~~~Quoted 7 lines
As
intel_dsi->dcs_backlight_portsseems to be always initialized to a non-null value, the content of the for loop is always executed and there is no bug in the current code. Nevertheless the compiler has no way of knowing that assumption, so initialize variable 'data' to silence the warning here.Signed-off-by Nicolas Iooss <[email protected]>Interesting ... there are two things that could lead to this (possibly) incorrect analysis. Either it thinks the loop could be executed zero times, which would be a deficiency in the compiler, as the initialiser and loop bound are both known (different) constants:
enum port { PORT_A = 0, PORT_B, PORT_C, PORT_D, PORT_E, I915_MAX_PORTS };Quoted 6 lines
or, it doesn't understand that because we've passed &data to another function, it can have been set by the callee. It may be extra confusing that the callee takes (void *); or it may be being ultra-sophisticated in its analysis and noted that in one error path data is *not* set (and we then discard the error and use data anyway). As an experiment, you could try:
The code that the compiler sees is not a simple loop other enum 'port' but "
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports){", which is expanded [1] to:for ((port) = PORT_A; (port) < I915_MAX_PORTS; (port)++) if (!((intel_dsi->dcs_backlight_ports) & (1 << (port)))) {} else {This is why I spoke of
intel_dsi->dcs_backlight_portsin my description:
if it is zero, the body of the loop is never run.As for the analyses of calls using &data, clang does not warn about the variable being maybe uninitialized following a call. This is quite expected as this would lead to too many false positives, even though it may miss some bugs.
Quoted 25 lines
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data = 0; mipi_dsi_dcs_read(dsi_device, cmd, &data, sizeof(data)); return data; }static u32
dcs_get_backlight(struct intel_connector *connector){ struct intel_encoder *encoder = connector->encoder; struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); struct mipi_dsi_device *dsi_device; enum port port; u8 data; /* FIXME: Need to take care of 16 bit brightness level */ for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { dsi_device = intel_dsi->dsi_hosts[port]->device; data = mipi_dsi_dcs_read1(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS); break; }
Quoted 7 lines
Quoted 4 lines
return data; }If it complains about that then it's a shortcoming in the loop analysis.
It complains (in
dcs_get_backlight), becausefor_each_dsi_port()still hides an 'if' condition.
So it does, In that case the complaint is really quite reasonable.
Quoted 11 lines
Quoted 11 lines
If not you could try:
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data; ssize_t nbytes = sizeof(data); nbytes = mipi_dsi_dcs_read(dsi_device, cmd, &data, nbytes); return nbytes == sizeof(data) ? data : 0; }
Quoted 6 lines
Quoted 4 lines
and if complains about that then it doesn't understand that passing &data allows it to be set. If it doesn't complain about this version, then the original error was actually correct, in the sense that data can indeed be used uninitialised if certain error paths can be taken.
clang did not complain with this last case.
It probably should have, since the (hidden) if() could still result in this function never being called. Oh well ...
.Dave.
Quoted 9 lines
Quoted 3 lines
Here's an R-b for your fix anyway ...
Reviewed-by Dave Gordon <[email protected]>Thanks!
Nicolas[1] I used "make
drivers/gpu/drm/i915/intel_dsi_dcs_backlight.i" to see the output of the preprocessor.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 127 lines · Dave Gordon
Quoted 100 lines · Nicolas Iooss
Quoted 52 lines · Dave Gordon
Quoted 28 lines · Nicolas Iooss
When building the kernel with clang and some warning flags, the compiler
reports that the return value ofdcs_get_backlight()may be uninitialized:drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable 'data' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized] for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro 'for_each_dsi_port' #define for_each_dsi_port(__port, __ports_mask) for_each_port_masked(__port,
__ports_mask)^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro 'for_each_port_masked' for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \ ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note: uninitialized use occurs here return data; ^~~~Quoted 8 lines
As
intel_dsi->dcs_backlight_portsseems to be always initialized to a non-null value, the content of the for loop is always executed and there
is no bug in the current code. Nevertheless the compiler has no way of knowing that assumption, so initialize variable 'data' to silence the warning here.Signed-off-by Nicolas Iooss <[email protected]>Interesting ... there are two things that could lead to this (possibly) incorrect analysis. Either it thinks the loop could be executed zero times, which would be a deficiency in the compiler, as the initialiser and loop bound are both known (different) constants:
enum port { PORT_A = 0, PORT_B, PORT_C, PORT_D, PORT_E, I915_MAX_PORTS };Quoted 6 lines
or, it doesn't understand that because we've passed &data to another function, it can have been set by the callee. It may be extra confusing that the callee takes (void *); or it may be being ultra-sophisticated in its analysis and noted that in one error path data is *not* set (and we then discard the error and use data anyway). As an experiment, you could try:
The code that the compiler sees is not a simple loop other enum 'port' but "
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports){", which is expanded [1] to:for ((port) = PORT_A; (port) < I915_MAX_PORTS; (port)++) if (!((intel_dsi->dcs_backlight_ports) & (1 << (port)))) {} else {This is why I spoke of
intel_dsi->dcs_backlight_portsin my description:
if it is zero, the body of the loop is never run.As for the analyses of calls using &data, clang does not warn about the variable being maybe uninitialized following a call. This is quite expected as this would lead to too many false positives, even though it may miss some bugs.
Quoted 25 lines
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data = 0; mipi_dsi_dcs_read(dsi_device, cmd, &data, sizeof(data)); return data; }static u32
dcs_get_backlight(struct intel_connector *connector){ struct intel_encoder *encoder = connector->encoder; struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); struct mipi_dsi_device *dsi_device; enum port port; u8 data; /* FIXME: Need to take care of 16 bit brightness level */ for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { dsi_device = intel_dsi->dsi_hosts[port]->device; data = mipi_dsi_dcs_read1(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS); break; }Quoted 7 lines
Quoted 4 lines
return data; }If it complains about that then it's a shortcoming in the loop analysis.
It complains (in
dcs_get_backlight), becausefor_each_dsi_port()still hides an 'if' condition.So it does, In that case the complaint is really quite reasonable.
Quoted 16 lines
Quoted 15 lines
If not you could try:
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data; ssize_t nbytes = sizeof(data); nbytes = mipi_dsi_dcs_read(dsi_device, cmd, &data, nbytes); return nbytes == sizeof(data) ? data : 0; }and if complains about that then it doesn't understand that passing &data allows it to be set. If it doesn't complain about this version, then the original error was actually correct, in the sense that data can indeed be used uninitialised if certain error paths can be taken.
Quoted 4 lines
Quoted 1 line
clang did not complain with this last case.
It probably should have, since the (hidden)
if()could still result in this function never being called. Oh well ...
Sorry, my message was not clear enough. The compiler did not complain in mipi_dsi_dcs_read1() in the last case, but the -Wsometimes-uninitialized warning was still there for variable 'data' in dcs_get_backlight(), as expected because of the "hidden if".
Nicolas
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 133 lines · Nicolas Iooss
Quoted 127 lines · Dave Gordon
Quoted 100 lines · Nicolas Iooss
Quoted 52 lines · Dave Gordon
Quoted 28 lines · Nicolas Iooss
When building the kernel with clang and some warning flags, the compiler
reports that the return value ofdcs_get_backlight()may be uninitialized:drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable 'data' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized] for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro 'for_each_dsi_port' #define for_each_dsi_port(__port, __ports_mask) for_each_port_masked(__port,
__ports_mask)^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro 'for_each_port_masked' for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \ ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note: uninitialized use occurs here return data; ^~~~Quoted 8 lines
As
intel_dsi->dcs_backlight_portsseems to be always initialized to a non-null value, the content of the for loop is always executed and there
is no bug in the current code. Nevertheless the compiler has no way of knowing that assumption, so initialize variable 'data' to silence the warning here.Signed-off-by Nicolas Iooss <[email protected]>Interesting ... there are two things that could lead to this (possibly) incorrect analysis. Either it thinks the loop could be executed zero times, which would be a deficiency in the compiler, as the initialiser and loop bound are both known (different) constants:
enum port { PORT_A = 0, PORT_B, PORT_C, PORT_D, PORT_E, I915_MAX_PORTS };Quoted 6 lines
or, it doesn't understand that because we've passed &data to another function, it can have been set by the callee. It may be extra confusing that the callee takes (void *); or it may be being ultra-sophisticated in its analysis and noted that in one error path data is *not* set (and we then discard the error and use data anyway). As an experiment, you could try:
The code that the compiler sees is not a simple loop other enum 'port' but "
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports){", which is expanded [1] to:for ((port) = PORT_A; (port) < I915_MAX_PORTS; (port)++) if (!((intel_dsi->dcs_backlight_ports) & (1 << (port)))) {} else {This is why I spoke of
intel_dsi->dcs_backlight_portsin my description:
if it is zero, the body of the loop is never run.As for the analyses of calls using &data, clang does not warn about the variable being maybe uninitialized following a call. This is quite expected as this would lead to too many false positives, even though it may miss some bugs.
Quoted 25 lines
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data = 0; mipi_dsi_dcs_read(dsi_device, cmd, &data, sizeof(data)); return data; }static u32
dcs_get_backlight(struct intel_connector *connector){ struct intel_encoder *encoder = connector->encoder; struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); struct mipi_dsi_device *dsi_device; enum port port; u8 data; /* FIXME: Need to take care of 16 bit brightness level */ for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { dsi_device = intel_dsi->dsi_hosts[port]->device; data = mipi_dsi_dcs_read1(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS); break; }Quoted 7 lines
Quoted 4 lines
return data; }If it complains about that then it's a shortcoming in the loop analysis.
It complains (in
dcs_get_backlight), becausefor_each_dsi_port()still hides an 'if' condition.So it does, In that case the complaint is really quite reasonable.
Quoted 16 lines
Quoted 15 lines
If not you could try:
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data; ssize_t nbytes = sizeof(data); nbytes = mipi_dsi_dcs_read(dsi_device, cmd, &data, nbytes); return nbytes == sizeof(data) ? data : 0; }and if complains about that then it doesn't understand that passing &data allows it to be set. If it doesn't complain about this version, then the original error was actually correct, in the sense that data can indeed be used uninitialised if certain error paths can be taken.
Quoted 4 lines
Quoted 1 line
clang did not complain with this last case.
It probably should have, since the (hidden)
if()could still result in this function never being called. Oh well ...
Quoted 6 lines
Sorry, my message was not clear enough. The compiler did not complain in
mipi_dsi_dcs_read1()in the last case, but the -Wsometimes-uninitialized warning was still there for variable 'data' indcs_get_backlight(), as expected because of the "hidden if".Nicolas
OK, thanks.
BTW do you see any "may be used uninitialised" warnings in gen{6,8}_ggtt_insert_entries()? In particular
for_each_sgt_dma(addr, sgt_iter, st) {
gtt_entry = gen8_pte_encode(addr, level, true);
gen8_set_pte(>t_entries[i++], gtt_entry);
}[snip]
if (i != 0)
WARN_ON(readq(>t_entries[i-1]) != gtt_entry);Or maybe clang is smart enough to realise that the WARN_ON() is reachable only if the gen8_set_pte() has already been executed at least once?
.Dave.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 166 lines · Dave Gordon
Quoted 146 lines · Nicolas Iooss
Quoted 140 lines · Dave Gordon
Quoted 110 lines · Nicolas Iooss
Quoted 56 lines · Dave Gordon
Quoted 38 lines · Nicolas Iooss
When building the kernel with clang and some warning flags, the compiler
reports that the return value ofdcs_get_backlight()may be uninitialized:drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable 'data' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized] for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro 'for_each_dsi_port' #define for_each_dsi_port(__port, __ports_mask) for_each_port_masked(__port,
__ports_mask)^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro 'for_each_port_masked' for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \ ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note: uninitialized use occurs here return data; ^~~~As
intel_dsi->dcs_backlight_portsseems to be always initialized to a non-null value, the content of the for loop is always executed and there
is no bug in the current code. Nevertheless the compiler has no way of
knowing that assumption, so initialize variable 'data' to silence the warning here.Quoted 1 line
Signed-off-by Nicolas Iooss <[email protected]>Interesting ... there are two things that could lead to this (possibly)
incorrect analysis. Either it thinks the loop could be executed zero times, which would be a deficiency in the compiler, as the initialiser and loop bound are both known (different) constants:enum port { PORT_A = 0, PORT_B, PORT_C, PORT_D, PORT_E, I915_MAX_PORTS };Quoted 8 lines
or, it doesn't understand that because we've passed &data to another function, it can have been set by the callee. It may be extra confusing
that the callee takes (void *); or it may be being ultra-sophisticated in its analysis and noted that in one error path data is *not* set (and
we then discard the error and use data anyway). As an experiment, you could try:The code that the compiler sees is not a simple loop other enum 'port' but "
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports){", which is expanded [1] to:for ((port) = PORT_A; (port) < I915_MAX_PORTS; (port)++) if (!((intel_dsi->dcs_backlight_ports) & (1 << (port)))) {}else {
This is why I spoke of
intel_dsi->dcs_backlight_portsin my description:
if it is zero, the body of the loop is never run.As for the analyses of calls using &data, clang does not warn about the variable being maybe uninitialized following a call. This is quite expected as this would lead to too many false positives, even though it may miss some bugs.
Quoted 27 lines
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data = 0; mipi_dsi_dcs_read(dsi_device, cmd, &data, sizeof(data)); return data; }static u32
dcs_get_backlight(struct intel_connector *connector){
structintel_encoder*encoder =connector->encoder; structintel_dsi*intel_dsi=enc_to_intel_dsi(&encoder->base); struct mipi_dsi_device *dsi_device; enum port port; u8 data; /* FIXME: Need to take care of 16 bit brightness level */ for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { dsi_device = intel_dsi->dsi_hosts[port]->device; data = mipi_dsi_dcs_read1(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS); break; }Quoted 8 lines
Quoted 5 lines
return data; }If it complains about that then it's a shortcoming in the loop analysis.
It complains (in
dcs_get_backlight), becausefor_each_dsi_port()still hides an 'if' condition.So it does, In that case the complaint is really quite reasonable.
Quoted 18 lines
Quoted 17 lines
If not you could try:
static u8
mipi_dsi_dcs_read1(struct mipi_dsi_device *dsi_device, u8 cmd){ u8 data; ssize_t nbytes = sizeof(data); nbytes = mipi_dsi_dcs_read(dsi_device, cmd, &data, nbytes); return nbytes == sizeof(data) ? data : 0; }and if complains about that then it doesn't understand that passing &data allows it to be set. If it doesn't complain about this version, then the original error was actually correct, in the sense that data can
indeed be used uninitialised if certain error paths can be taken.Quoted 4 lines
Quoted 1 line
clang did not complain with this last case.
It probably should have, since the (hidden)
if()could still result in this function never being called. Oh well ...Quoted 6 lines
Sorry, my message was not clear enough. The compiler did not complain in
mipi_dsi_dcs_read1()in the last case, but the -Wsometimes-uninitialized warning was still there for variable 'data' indcs_get_backlight(), as expected because of the "hidden if".Nicolas
OK, thanks.
BTW do you see any "may be used uninitialised" warnings in gen{6,8}_ggtt_insert_entries()? In particular
for_each_sgt_dma(addr, sgt_iter, st) { gtt_entry = gen8_pte_encode(addr, level, true); gen8_set_pte(>t_entries[i++], gtt_entry); }[snip]
Quoted 8 lines
if (i != 0) WARN_ON(readq(>t_entries[i-1]) != gtt_entry);Or maybe clang is smart enough to realise that the
WARN_ON()is reachable only if thegen8_set_pte()has already been executed at least once?.Dave.
The clang I am using (version 3.8.1) does not report any -Wsometimes-uninitialized warning in drivers/gpu/drm/i915/i915_gem_gtt.c. Even when I introduce a statement which uses gtt_entry right after the for_each_sgt_dma loop (like printk("%llu", gtt_entry);) no warning is produced. Therefore the lack of the warning does not mean the compiler is finding that i != 0 only when the loop got executed once, I guess the loop condition is too complex for the compiler to decide whether the loop body is always executed.
Nicolas
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Hello,
I sent the patch below a few weeks ago. I got some comments (cf. [1]) which looked good, but the patch has not been merged in linux-next yet. Do I need to fix something (like rewrite the commit message) in order to get it merged?
Thanks,
Nicolas
[1] https://patchwork.freedesktop.org/patch/108941/
Quoted 48 lines · Nicolas Iooss
When building the kernel with clang and some warning flags, the compiler reports that the return value of
dcs_get_backlight()may be uninitialized:drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:53:2: error: variable 'data' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized] for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi.h:126:49: note: expanded from macro 'for_each_dsi_port' #define for_each_dsi_port(__port, __ports_mask) for_each_port_masked(__port, __ports_mask) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/i915_drv.h:322:26: note: expanded from macro 'for_each_port_masked' for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \ ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c:60:9: note: uninitialized use occurs here return data; ^~~~As
intel_dsi->dcs_backlight_portsseems to be always initialized to a non-null value, the content of the for loop is always executed and there is no bug in the current code. Nevertheless the compiler has no way of knowing that assumption, so initialize variable 'data' to silence the warning here.Signed-off-by Nicolas Iooss <[email protected]>--- drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/intel_dsi_dcs_backlight.c +1
-1@@ -46,7 +46,7 @@ static u32 dcs_get_backlight(struct intel_connector *connector)struct intel_encoder *encoder = connector->encoder;struct intel_dsi *intel_dsi =enc_to_intel_dsi (&encoder->base);struct mipi_dsi_device *dsi_device; -u8 data; +u8 data =0 ;enum port port;/* FIXME: Need to take care of 16 bit brightness level */
Quoted 6 lines · Nicolas Iooss
Hello,
I sent the patch below a few weeks ago. I got some comments (cf. [1]) which looked good, but the patch has not been merged in linux-next yet. Do I need to fix something (like rewrite the commit message) in order to get it merged?
It basically boils down to that you said it doesn't fix a bug, but shuts up a non-default compiler using custom warning flags.
But there is a bug in that code, as mipi_dsi_dcs_read() may return an error value, which may just be ENOMEM, but if it did we would return the garbage. Not only should we fix the error handling here, but you also need to fix the error handling in drivers/video/backlight/backlight.c as despite many callees returning an error, it assumes that bd->ops->get_brightness() never returns an error...
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre