aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/0110-drm-amd-display-Fix-color-module-crash-when-hotplug-.patch
blob: b18e530f3197d4c11025c7c995c81a935564d011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
From 732bedba7cc5b5dc772191b824182f5f859d1d26 Mon Sep 17 00:00:00 2001
From: Anthony Koo <Anthony.Koo@amd.com>
Date: Fri, 23 Dec 2016 15:43:04 -0500
Subject: [PATCH 0110/4131] drm/amd/display: Fix color module crash when
 hotplug monitors.

Assume we have two monitors, and monitor 0 is unplugged.
This shifts the internal state of index 1 to index 0 by memcpy.
This means there are two copies of the gamma pointer previously
owned by state[1].

When hotplug occurs, this re-assigns the new display with state[1],
which has some garbage left over from before, including the
gamma pointer.

We should correctly clear unused states and re-initialize correctly.

Also, due to async nature of the hotplug and other events like commit,
we also need to safe guard against sink that has been removed.

Signed-off-by: Anthony Koo <anthony.koo@amd.com>
Reviewed-by: Aric Cyr <Aric.Cyr@amd.com>
Reviewed-by: Tony Cheng <Tony.Cheng@amd.com>
Acked-by: Harry Wentland <Harry.Wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/display/modules/color/color.c | 309 ++++++++++++----------
 1 file changed, 175 insertions(+), 134 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/modules/color/color.c b/drivers/gpu/drm/amd/display/modules/color/color.c
index 3611de9..74298c8 100644
--- a/drivers/gpu/drm/amd/display/modules/color/color.c
+++ b/drivers/gpu/drm/amd/display/modules/color/color.c
@@ -643,10 +643,10 @@ static void initialize_fix_point_color_values(
 /* Given a specific dc_sink* this function finds its equivalent
  * on the dc_sink array and returns the corresponding index
  */
-static unsigned int sink_index_from_sink(struct core_color *core_color,
+static int sink_index_from_sink(struct core_color *core_color,
 		const struct dc_sink *sink)
 {
-	unsigned int index = 0;
+	int index = 0;
 
 	for (index = 0; index < core_color->num_sinks; index++)
 		if (core_color->caps[index].sink == sink)
@@ -654,7 +654,7 @@ static unsigned int sink_index_from_sink(struct core_color *core_color,
 
 	/* Could not find sink requested */
 	ASSERT(false);
-	return index;
+	return -1;
 }
 
 static void calculate_rgb_matrix_legacy(struct core_color *core_color,
@@ -1427,6 +1427,65 @@ static bool update_color_gamut_data(struct color_gamut_data *input_data,
 	return true;
 }
 
+void initialize_color_state(struct core_color *core_color, int index)
+{
+	core_color->state[index].user_enable_color_temperature = true;
+
+	core_color->state[index].custom_color_temperature = 6500;
+
+	core_color->state[index].contrast.current = 100;
+	core_color->state[index].contrast.min = 0;
+	core_color->state[index].contrast.max = 200;
+
+	core_color->state[index].saturation.current = 100;
+	core_color->state[index].saturation.min = 0;
+	core_color->state[index].saturation.max = 200;
+
+	core_color->state[index].brightness.current = 0;
+	core_color->state[index].brightness.min = -100;
+	core_color->state[index].brightness.max = 100;
+
+	core_color->state[index].hue.current = 0;
+	core_color->state[index].hue.min = -30;
+	core_color->state[index].hue.max = 30;
+
+	core_color->state[index].gamma = NULL;
+
+	core_color->state[index].preferred_quantization_range =
+		QUANTIZATION_RANGE_FULL;
+
+	core_color->state[index].source_gamut.color_space =
+		color_space_srgb;
+	core_color->state[index].source_gamut.white_point =
+		color_white_point_type_6500k_noon;
+	core_color->state[index].source_gamut.gamut.blueX = 1500;
+	core_color->state[index].source_gamut.gamut.blueY = 600;
+	core_color->state[index].source_gamut.gamut.greenX = 3000;
+	core_color->state[index].source_gamut.gamut.greenY = 6000;
+	core_color->state[index].source_gamut.gamut.redX = 6400;
+	core_color->state[index].source_gamut.gamut.redY = 3300;
+	core_color->state[index].source_gamut.gamut.whiteX = 3127;
+	core_color->state[index].source_gamut.gamut.whiteY = 3290;
+
+	core_color->state[index].destination_gamut.color_space =
+		color_space_srgb;
+	core_color->state[index].destination_gamut.white_point =
+		color_white_point_type_6500k_noon;
+	core_color->state[index].destination_gamut.gamut.blueX = 1500;
+	core_color->state[index].destination_gamut.gamut.blueY = 600;
+	core_color->state[index].destination_gamut.gamut.greenX = 3000;
+	core_color->state[index].destination_gamut.gamut.greenY = 6000;
+	core_color->state[index].destination_gamut.gamut.redX = 6400;
+	core_color->state[index].destination_gamut.gamut.redY = 3300;
+	core_color->state[index].destination_gamut.gamut.whiteX = 3127;
+	core_color->state[index].destination_gamut.gamut.whiteY = 3290;
+
+	core_color->state[index].input_transfer_function =
+				transfer_func_srgb;
+	core_color->state[index].output_transfer_function =
+				transfer_func_srgb;
+}
+
 struct mod_color *mod_color_create(struct dc *dc)
 {
 	int i = 0;
@@ -1452,54 +1511,7 @@ struct mod_color *mod_color_create(struct dc *dc)
 
 	/*hardcoded to sRGB with 6500 color temperature*/
 	for (i = 0; i < MOD_COLOR_MAX_CONCURRENT_SINKS; i++) {
-		core_color->state[i].source_gamut.color_space =
-				color_space_srgb;
-		core_color->state[i].source_gamut.white_point =
-				color_white_point_type_6500k_noon;
-		core_color->state[i].source_gamut.gamut.blueX = 1500;
-		core_color->state[i].source_gamut.gamut.blueY = 600;
-		core_color->state[i].source_gamut.gamut.greenX = 3000;
-		core_color->state[i].source_gamut.gamut.greenY = 6000;
-		core_color->state[i].source_gamut.gamut.redX = 6400;
-		core_color->state[i].source_gamut.gamut.redY = 3300;
-		core_color->state[i].source_gamut.gamut.whiteX = 3127;
-		core_color->state[i].source_gamut.gamut.whiteY = 3290;
-
-		core_color->state[i].destination_gamut.color_space =
-				color_space_srgb;
-		core_color->state[i].destination_gamut.white_point =
-				color_white_point_type_6500k_noon;
-		core_color->state[i].destination_gamut.gamut.blueX = 1500;
-		core_color->state[i].destination_gamut.gamut.blueY = 600;
-		core_color->state[i].destination_gamut.gamut.greenX = 3000;
-		core_color->state[i].destination_gamut.gamut.greenY = 6000;
-		core_color->state[i].destination_gamut.gamut.redX = 6400;
-		core_color->state[i].destination_gamut.gamut.redY = 3300;
-		core_color->state[i].destination_gamut.gamut.whiteX = 3127;
-		core_color->state[i].destination_gamut.gamut.whiteY = 3290;
-
-		core_color->state[i].input_transfer_function =
-						transfer_func_srgb;
-		core_color->state[i].output_transfer_function =
-						transfer_func_srgb;
-
-		core_color->state[i].custom_color_temperature = 6500;
-
-		core_color->state[i].contrast.current = 100;
-		core_color->state[i].contrast.min = 0;
-		core_color->state[i].contrast.max = 200;
-
-		core_color->state[i].saturation.current = 100;
-		core_color->state[i].saturation.min = 0;
-		core_color->state[i].saturation.max = 200;
-
-		core_color->state[i].brightness.current = 0;
-		core_color->state[i].brightness.min = -100;
-		core_color->state[i].brightness.max = 100;
-
-		core_color->state[i].hue.current = 0;
-		core_color->state[i].hue.min = -30;
-		core_color->state[i].hue.max = 30;
+		initialize_color_state(core_color, i);
 	}
 
 	if (core_color->state == NULL)
@@ -1589,8 +1601,8 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 	if (core_color->num_sinks < MOD_COLOR_MAX_CONCURRENT_SINKS) {
 		dc_sink_retain(sink);
 		core_color->caps[core_color->num_sinks].sink = sink;
-		core_color->state[core_color->num_sinks].
-				user_enable_color_temperature = true;
+
+		initialize_color_state(core_color, core_color->num_sinks);
 
 		core_color->edid_caps[core_color->num_sinks].colorimetry_caps =
 				edid_caps->colorimetry_caps;
@@ -1601,7 +1613,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 		flag.save_per_edid = true;
 		flag.save_per_link = false;
 
-
 		if (dm_read_persistent_data(core_dc->ctx, sink,
 						COLOR_REGISTRY_NAME,
 						"enablecolortempadj",
@@ -1610,9 +1621,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 			core_color->state[core_color->num_sinks].
 				user_enable_color_temperature =
 						persistent_color_temp_enable;
-		else
-			core_color->state[core_color->num_sinks].
-				user_enable_color_temperature = true;
 
 		if (dm_read_persistent_data(core_dc->ctx, sink,
 						COLOR_REGISTRY_NAME,
@@ -1622,9 +1630,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 			core_color->state[core_color->num_sinks].
 					custom_color_temperature
 					= persistent_custom_color_temp;
-		else
-			core_color->state[core_color->num_sinks].
-					custom_color_temperature = 6500;
 
 		if (dm_read_persistent_data(core_dc->ctx, sink,
 					COLOR_REGISTRY_NAME,
@@ -1635,23 +1640,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 			memcpy(&core_color->state[core_color->num_sinks].
 				source_gamut.gamut, &persistent_source_gamut,
 				sizeof(struct color_space_coordinates));
-		} else {
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.blueX = 1500;
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.blueY = 600;
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.greenX = 3000;
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.greenY = 6000;
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.redX = 6400;
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.redY = 3300;
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.whiteX = 3127;
-			core_color->state[core_color->num_sinks].
-					source_gamut.gamut.whiteY = 3290;
 		}
 
 		if (dm_read_persistent_data(core_dc->ctx, sink, COLOR_REGISTRY_NAME,
@@ -1663,23 +1651,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 				destination_gamut.gamut,
 				&persistent_destination_gamut,
 				sizeof(struct color_space_coordinates));
-		} else {
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.blueX = 1500;
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.blueY = 600;
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.greenX = 3000;
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.greenY = 6000;
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.redX = 6400;
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.redY = 3300;
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.whiteX = 3127;
-			core_color->state[core_color->num_sinks].
-					destination_gamut.gamut.whiteY = 3290;
 		}
 
 		if (dm_read_persistent_data(core_dc->ctx, sink, COLOR_REGISTRY_NAME,
@@ -1688,9 +1659,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 						sizeof(int), &flag))
 			core_color->state[core_color->num_sinks].
 				brightness.current = persistent_brightness;
-		else
-			core_color->state[core_color->num_sinks].
-				brightness.current = 0;
 
 		if (dm_read_persistent_data(core_dc->ctx, sink, COLOR_REGISTRY_NAME,
 						"contrast",
@@ -1698,9 +1666,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 						sizeof(int), &flag))
 			core_color->state[core_color->num_sinks].
 				contrast.current = persistent_contrast;
-		else
-			core_color->state[core_color->num_sinks].
-				contrast.current = 100;
 
 		if (dm_read_persistent_data(core_dc->ctx, sink, COLOR_REGISTRY_NAME,
 						"hue",
@@ -1708,9 +1673,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 						sizeof(int), &flag))
 			core_color->state[core_color->num_sinks].
 				hue.current = persistent_hue;
-		else
-			core_color->state[core_color->num_sinks].
-				hue.current = 0;
 
 		if (dm_read_persistent_data(core_dc->ctx, sink, COLOR_REGISTRY_NAME,
 						"saturation",
@@ -1718,9 +1680,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 						sizeof(int), &flag))
 			core_color->state[core_color->num_sinks].
 				saturation.current = persistent_saturation;
-		else
-			core_color->state[core_color->num_sinks].
-				saturation.current = 100;
 
 		if (dm_read_persistent_data(core_dc->ctx, sink,
 						COLOR_REGISTRY_NAME,
@@ -1730,9 +1689,6 @@ bool mod_color_add_sink(struct mod_color *mod_color, const struct dc_sink *sink,
 			core_color->state[core_color->num_sinks].
 			preferred_quantization_range =
 					persistent_quantization_range;
-		else
-			core_color->state[core_color->num_sinks].
-			preferred_quantization_range = QUANTIZATION_RANGE_FULL;
 
 		core_color->num_sinks++;
 		return true;
@@ -1751,6 +1707,10 @@ bool mod_color_remove_sink(struct mod_color *mod_color,
 			if (core_color->state[i].gamma) {
 				dc_gamma_release(&core_color->state[i].gamma);
 			}
+			memset(&core_color->state[i], 0,
+					sizeof(struct color_state));
+			memset(&core_color->edid_caps[i], 0,
+					sizeof(struct color_edid_caps));
 
 			/* To remove this sink, shift everything after down */
 			for (j = i; j < core_color->num_sinks - 1; j++) {
@@ -1766,6 +1726,11 @@ bool mod_color_remove_sink(struct mod_color *mod_color,
 					sizeof(struct color_edid_caps));
 			}
 
+			memset(&core_color->state[core_color->num_sinks - 1], 0,
+				sizeof(struct color_state));
+			memset(&core_color->edid_caps[core_color->num_sinks - 1], 0,
+				sizeof(struct color_edid_caps));
+
 			core_color->num_sinks--;
 
 			dc_sink_release(sink);
@@ -1786,11 +1751,14 @@ bool mod_color_update_gamut_to_stream(struct mod_color *mod_color,
 	struct gamut_src_dst_matrix *matrix =
 			dm_alloc(sizeof(struct gamut_src_dst_matrix));
 
-	unsigned int stream_index, sink_index, j;
+	unsigned int stream_index, j;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		/* Write persistent data in registry*/
 		flag.save_per_edid = true;
@@ -1880,11 +1848,14 @@ bool mod_color_adjust_source_gamut(struct mod_color *mod_color,
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		update_color_gamut_data(input_gamut_data,
 				&core_color->state[sink_index].source_gamut);
@@ -1903,11 +1874,14 @@ bool mod_color_adjust_source_gamut_and_tf(struct mod_color *mod_color,
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 		update_color_gamut_data(input_gamut_data,
 				&core_color->state[sink_index].source_gamut);
 		core_color->state[sink_index].input_transfer_function =
@@ -1926,11 +1900,14 @@ bool mod_color_adjust_destination_gamut(struct mod_color *mod_color,
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		update_color_gamut_data(input_gamut_data,
 			&core_color->state[sink_index].destination_gamut);
@@ -1948,12 +1925,15 @@ bool mod_color_set_white_point(struct mod_color *mod_color,
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams;
 			stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 		core_color->state[sink_index].source_gamut.gamut.whiteX =
 				white_point->whiteX;
 		core_color->state[sink_index].source_gamut.gamut.whiteY =
@@ -1972,11 +1952,14 @@ bool mod_color_set_mastering_info(struct mod_color *mod_color,
 		const struct dc_hdr_static_metadata *mastering_info)
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 		memcpy(&core_color->state[sink_index].mastering_info,
 				mastering_info,
 				sizeof(struct dc_hdr_static_metadata));
@@ -1991,7 +1974,10 @@ bool mod_color_get_mastering_info(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	memcpy(mastering_info, &core_color->state[sink_index].mastering_info,
 			sizeof(struct dc_hdr_static_metadata));
@@ -2007,11 +1993,14 @@ bool mod_color_set_user_enable(struct mod_color *mod_color,
 			MOD_COLOR_TO_CORE(mod_color);
 	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
 	struct persistent_data_flag flag;
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 		core_color->state[sink_index].user_enable_color_temperature
 				= user_enable;
 
@@ -2037,7 +2026,10 @@ bool mod_color_get_user_enable(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	*user_enable = core_color->state[sink_index].
 					user_enable_color_temperature;
@@ -2052,7 +2044,10 @@ bool mod_color_get_custom_color_temperature(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	*color_temperature = core_color->state[sink_index].
 			custom_color_temperature;
@@ -2068,11 +2063,14 @@ bool mod_color_set_custom_color_temperature(struct mod_color *mod_color,
 			MOD_COLOR_TO_CORE(mod_color);
 	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
 	struct persistent_data_flag flag;
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 		core_color->state[sink_index].custom_color_temperature
 				= color_temperature;
 
@@ -2098,7 +2096,10 @@ bool mod_color_get_color_saturation(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	*color_saturation = core_color->state[sink_index].saturation;
 
@@ -2112,7 +2113,10 @@ bool mod_color_get_color_contrast(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	*color_contrast = core_color->state[sink_index].contrast;
 
@@ -2126,7 +2130,10 @@ bool mod_color_get_color_brightness(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	*color_brightness = core_color->state[sink_index].brightness;
 
@@ -2140,7 +2147,10 @@ bool mod_color_get_color_hue(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	*color_hue = core_color->state[sink_index].hue;
 
@@ -2154,7 +2164,10 @@ bool mod_color_get_source_gamut(struct mod_color *mod_color,
 	struct core_color *core_color =
 			MOD_COLOR_TO_CORE(mod_color);
 
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
 
 	*source_gamut = core_color->state[sink_index].source_gamut.gamut;
 
@@ -2169,11 +2182,14 @@ bool mod_color_notify_mode_change(struct mod_color *mod_color,
 	struct gamut_src_dst_matrix *matrix =
 			dm_alloc(sizeof(struct gamut_src_dst_matrix));
 
-	unsigned int stream_index, sink_index, j;
+	unsigned int stream_index, j;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		if (!build_gamut_remap_matrix
 			(core_color->state[sink_index].source_gamut.gamut,
@@ -2247,11 +2263,14 @@ bool mod_color_set_brightness(struct mod_color *mod_color,
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
 	struct persistent_data_flag flag;
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		struct core_stream *core_stream =
 						DC_STREAM_TO_CORE
@@ -2291,11 +2310,14 @@ bool mod_color_set_contrast(struct mod_color *mod_color,
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
 	struct persistent_data_flag flag;
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		struct core_stream *core_stream =
 						DC_STREAM_TO_CORE
@@ -2335,11 +2357,14 @@ bool mod_color_set_hue(struct mod_color *mod_color,
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
 	struct persistent_data_flag flag;
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		struct core_stream *core_stream =
 						DC_STREAM_TO_CORE
@@ -2378,11 +2403,14 @@ bool mod_color_set_saturation(struct mod_color *mod_color,
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
 	struct persistent_data_flag flag;
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		struct core_stream *core_stream =
 						DC_STREAM_TO_CORE
@@ -2420,11 +2448,14 @@ bool mod_color_set_input_gamma_correction(struct mod_color *mod_color,
 		struct dc_gamma *gamma)
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 
 		struct dc_surface *surface =
 				dc_stream_to_surface_from_pipe_ctx(core_color,
@@ -2471,9 +2502,12 @@ bool mod_color_persist_user_preferred_quantization_range(
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
 	struct core_dc *core_dc = DC_TO_CORE(core_color->dc);
 	struct persistent_data_flag flag;
-	unsigned int sink_index;
+	int sink_index;
 
 	sink_index = sink_index_from_sink(core_color, sink);
+	if (sink_index == -1)
+		return false;
+
 	if (core_color->state[sink_index].
 			preferred_quantization_range != quantization_range) {
 		core_color->state[sink_index].preferred_quantization_range =
@@ -2498,7 +2532,11 @@ bool mod_color_get_preferred_quantization_range(struct mod_color *mod_color,
 		enum dc_quantization_range *quantization_range)
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
-	unsigned int sink_index = sink_index_from_sink(core_color, sink);
+	int sink_index = sink_index_from_sink(core_color, sink);
+
+	if (sink_index == -1)
+		return false;
+
 	enum dc_quantization_range user_preferred_quantization_range =
 			core_color->state[sink_index].
 				preferred_quantization_range;
@@ -2601,7 +2639,8 @@ bool mod_color_update_gamut_info(struct mod_color *mod_color,
 		const struct dc_stream **streams, int num_streams)
 {
 	struct core_color *core_color = MOD_COLOR_TO_CORE(mod_color);
-	unsigned int stream_index, sink_index;
+	unsigned int stream_index;
+	int sink_index;
 	bool should_defer = false;
 	bool is_hdr = false;
 	enum color_color_space source_color_space;
@@ -2612,6 +2651,8 @@ bool mod_color_update_gamut_info(struct mod_color *mod_color,
 	for (stream_index = 0; stream_index < num_streams; stream_index++) {
 		sink_index = sink_index_from_sink(core_color,
 				streams[stream_index]->sink);
+		if (sink_index == -1)
+			continue;
 		source_color_space =
 			core_color->state[sink_index].source_gamut.color_space;
 		input_transfer_function =
-- 
2.7.4