Skip to contentSkip to conversation

uninitialized variable in dcn10 code

DISCUSSION Tom St Denis 3 participants 4 messages Nov 14, 2017 2 messages not in the archive

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

Hi Harry,

At display/dc/dcn10/dcn10_hw_sequencer.c:2140

	if (num_planes > 0) {
		struct dc_stream_state *stream_for_cursor;

		program_all_pipe_in_tree(dc, top_pipe_to_program, context);

		for (i = 0; i < dc->res_pool->pipe_count; i++) {
			struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];

			if (stream == pipe_ctx->stream) {
				stream_for_cursor = pipe_ctx->stream;
				break;
			}
		}

		/* TODO: this is a hack w/a for switching from mpo to pipe split */
		if (stream_for_cursor->cursor_attributes.address.quad_part != 0) {
			struct dc_cursor_position position = { 0 };

			dc_stream_set_cursor_position(stream_for_cursor, &position);
			dc_stream_set_cursor_attributes(stream_for_cursor,
				&stream_for_cursor->cursor_attributes);
		}
	}

The variable "stream_for_cursor" could be used uninitialized in the TODO block. The pointer should be probably initialized to NULL at the top.

Cheers,
Tom
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 78e8d6e4-663b-ffa8-9c38-f18093e5edd7-5C7GfCeVMHo@public.gmane.org

#2 lore raw
Quoted 22 lines · Tom St Denis

Hi Harry,

At display/dc/dcn10/dcn10_hw_sequencer.c:2140

    if (num_planes > 0) {
        struct dc_stream_state *stream_for_cursor;

        program_all_pipe_in_tree(dc, top_pipe_to_program, context);

        for (i = 0; i < dc->res_pool->pipe_count; i++) { struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];

            if (stream == pipe_ctx->stream) { stream_for_cursor = pipe_ctx->stream; break;
            }
        }

        /* TODO: this is a hack w/a for switching from mpo to pipe split */ if (stream_for_cursor->cursor_attributes.address.quad_part != 0) { struct dc_cursor_position position = { 0 };

Quoted 8 lines

            dc_stream_set_cursor_position(stream_for_cursor, &position); dc_stream_set_cursor_attributes(stream_for_cursor, &stream_for_cursor->cursor_attributes);
        }
    }

The variable "stream_for_cursor" could be used uninitialized in the TODO block.  The pointer should be probably initialized to NULL at the top.

BTW, the compiler points this out:

drivers/gpu/drm//amd/amdgpu/../display/dc/dcn10/dcn10_hw_sequencer.c: In function ‘dcn10_apply_ctx_for_surface’:
drivers/gpu/drm//amd/amdgpu/../display/dc/dcn10/dcn10_hw_sequencer.c:2146:5: warning: ‘stream_for_cursor’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     &stream_for_cursor->cursor_attributes);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 961cdb00-033e-82b5-c9f9-f1ac72c12bd3-otUistvHUpPR7s880joybQ@public.gmane.org

#4 lore raw
Quoted 32 lines · Michel Dänzer
Quoted 22 lines · Tom St Denis

Hi Harry,

At display/dc/dcn10/dcn10_hw_sequencer.c:2140

    if (num_planes > 0) {
        struct dc_stream_state *stream_for_cursor;

        program_all_pipe_in_tree(dc, top_pipe_to_program, context);

        for (i = 0; i < dc->res_pool->pipe_count; i++) { struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];

            if (stream == pipe_ctx->stream) { stream_for_cursor = pipe_ctx->stream; break;
            }
        }

        /* TODO: this is a hack w/a for switching from mpo to pipe split */ if (stream_for_cursor->cursor_attributes.address.quad_part != 0) { struct dc_cursor_position position = { 0 };

Quoted 8 lines

            dc_stream_set_cursor_position(stream_for_cursor, &position); dc_stream_set_cursor_attributes(stream_for_cursor, &stream_for_cursor->cursor_attributes);
        }
    }

The variable "stream_for_cursor" could be used uninitialized in the TODO block.  The pointer should be probably initialized to NULL at the top.

Quoted 7 lines

BTW, the compiler points this out:

drivers/gpu/drm//amd/amdgpu/../display/dc/dcn10/dcn10_hw_sequencer.c: In function ‘dcn10_apply_ctx_for_surface’:
drivers/gpu/drm//amd/amdgpu/../display/dc/dcn10/dcn10_hw_sequencer.c:2146:5: warning: ‘stream_for_cursor’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     &stream_for_cursor->cursor_attributes);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Yes, newer gcc (~5.8) does. We were still running Ubuntu 14.04 on our pre-submission build system and its gcc version didn't catch this. Jordan upgraded us to Ubuntu 16.04 with newer gcc that should catch this now.

Harry

Quoted 1 line

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

Reviewed-by
#5 lore raw
In reply to a message not in the archive
Quoted 22 lines · Tom St Denis

Hi Harry,

At display/dc/dcn10/dcn10_hw_sequencer.c:2140

    if (num_planes > 0) {
        struct dc_stream_state *stream_for_cursor;

        program_all_pipe_in_tree(dc, top_pipe_to_program, context);

        for (i = 0; i < dc->res_pool->pipe_count; i++) { struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];

            if (stream == pipe_ctx->stream) { stream_for_cursor = pipe_ctx->stream; break;
            }
        }

        /* TODO: this is a hack w/a for switching from mpo to pipe split */ if (stream_for_cursor->cursor_attributes.address.quad_part != 0) { struct dc_cursor_position position = { 0 };

Quoted 8 lines

            dc_stream_set_cursor_position(stream_for_cursor, &position); dc_stream_set_cursor_attributes(stream_for_cursor, &stream_for_cursor->cursor_attributes);
        }
    }

The variable "stream_for_cursor" could be used uninitialized in the TODO block.  The pointer should be probably initialized to NULL at the top.

Thanks, Tom. Gerrit decided not to push three commits when I merged the latest DC changes. I merged them now. Sorry for the churn. Fixed by this:

commit bec63856e26de10c1d3a3f1422acdb7e0719651f (HEAD -> amd-staging-drm-next, origin/amd-staging-drm-next)

Author: Leo (Sunpeng) Li <[email protected]>
Date:   Wed Nov 8 15:30:19 2017 -0500

drm/amd/display: Fix use before initialize warning

on stream_for_cursor. Initialize to NULL.

Change-Id Ic032bfe78b33e466e560d33488e0fd8df060f694
drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c +1 -1
index 30f458701f9c..b5d048b364a4 100644
@@ -2124,7 +2124,7 @@ static void dcn10_apply_ctx_for_surface(
        }
 
        if (num_planes > 0) {
-               struct dc_stream_state *stream_for_cursor;
+               struct dc_stream_state *stream_for_cursor = NULL;
 
                program_all_pipe_in_tree(dc, top_pipe_to_program, context);
 

Harry

Quoted 2 lines

Cheers,
Tom

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