Silancing a false positive: "may be used uninitialized"
Subsystems (2)
PATCH 1/1 Silancing a false positive: "may be used uninitialized"
Hello all,
Silancing a false positive:
warning: 'width' may be used uninitialized in this function drivers/gpu/drm/drm_edid.c
==========================================================================
drivers/gpu/drm/drm_edid.c +1 -1
@@ -913,7 +913,7 @@const int rates[] = {60 ,85 ,75 ,60 ,50 };for (i =0 ; i <4 ; i++) { -int width, height; +int uninitialized_var (width ), height; cvt = &(timing->data.other_data.data.cvt[i]); height = (cvt->code[0 ] + ((cvt->code[1 ] &0xf0 ) <<8 ) +1 ) *2 ;
Quoted 5 lines · Marin Mitov
Hello all,
Silancing a false positive:
warning: 'width' may be used uninitialized in this functiondrivers/gpu/drm/drm_edid.c
Is it guaranteed that the switch will always see a value covered by the four cases it has? If not width would be used without having been initialised.
Perhaps adding
default: BUG();
would be worthwhile?
Quoted 19 lines
Signed-off-by Marin Mitov <[email protected]>==========================================================================
drivers/gpu/drm/drm_edid.c +1
-2@@ -913,7 +913,7 @@const int rates[] = {60 ,85 ,75 ,60 ,50 };for (i =0 ; i <4 ; i++) { -int width, height; +int uninitialized_var (width ), height; cvt = &(timing->data.other_data.data.cvt[i]); height = (cvt->code[0 ] + ((cvt->code[1 ] &0xf0 ) <<8 ) +1 ) *2 ; --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 9 lines · Simon Horman
Quoted 5 lines · Marin Mitov
Hello all,
Silancing a false positive:
warning: 'width' may be used uninitialized in this functiondrivers/gpu/drm/drm_edid.cIs it guaranteed that the switch will always see a value covered by the four cases it has?
Yes it is. The value is masked (& 0xc0) so all the possible values are (0x00, 0x40, 0x80, 0xc0) covered by the switch. That's why it is false positive.
Quoted 29 lines
If not width would be used without having been initialised.
Perhaps adding
default: BUG();would be worthwhile?
Quoted 19 lines
Signed-off-by Marin Mitov <[email protected]>==========================================================================
drivers/gpu/drm/drm_edid.c +1
-2@@ -913,7 +913,7 @@const int rates[] = {60 ,85 ,75 ,60 ,50 };for (i =0 ; i <4 ; i++) { -int width, height; +int uninitialized_var (width ), height; cvt = &(timing->data.other_data.data.cvt[i]); height = (cvt->code[0 ] + ((cvt->code[1 ] &0xf0 ) <<8 ) +1 ) *2 ; --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 8 lines · Marin Mitov
Quoted 7 lines · Simon Horman
Quoted 5 lines · Marin Mitov
Hello all,
Silancing a false positive:
warning: 'width' may be used uninitialized in this functiondrivers/gpu/drm/drm_edid.c
Quoted 5 lines
Quoted 2 lines
Is it guaranteed that the switch will always see a value covered by the four cases it has?
Yes it is. The value is masked (&
0xc0) so all the possible values are (0x00,0x40,0x80,0xc0) covered by the switch. That's why it is false positive.
Of course, silly me.