drm/amd/display: Do not create memory allocation if stats not enabled
authorAnthony Koo <Anthony.Koo@amd.com>
Fri, 6 Apr 2018 16:07:19 +0000 (12:07 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 15 May 2018 18:43:24 +0000 (13:43 -0500)
Signed-off-by: Anthony Koo <Anthony.Koo@amd.com>
Reviewed-by: Aric Cyr <Aric.Cyr@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/stats/stats.c

index ed5f6809a64e06a9f0e257024f42a91acf827e8e..48e02197919fa41e66d71090d678f26e726349b6 100644 (file)
@@ -115,18 +115,22 @@ struct mod_stats *mod_stats_create(struct dc *dc)
                        &reg_data, sizeof(unsigned int), &flag))
                core_stats->enabled = reg_data;
 
-       core_stats->entries = DAL_STATS_ENTRIES_REGKEY_DEFAULT;
-       if (dm_read_persistent_data(dc->ctx, NULL, NULL,
-                       DAL_STATS_ENTRIES_REGKEY,
-                       &reg_data, sizeof(unsigned int), &flag)) {
-               if (reg_data > DAL_STATS_ENTRIES_REGKEY_MAX)
-                       core_stats->entries = DAL_STATS_ENTRIES_REGKEY_MAX;
-               else
-                       core_stats->entries = reg_data;
-       }
+       if (core_stats->enabled) {
+               core_stats->entries = DAL_STATS_ENTRIES_REGKEY_DEFAULT;
+               if (dm_read_persistent_data(dc->ctx, NULL, NULL,
+                               DAL_STATS_ENTRIES_REGKEY,
+                               &reg_data, sizeof(unsigned int), &flag)) {
+                       if (reg_data > DAL_STATS_ENTRIES_REGKEY_MAX)
+                               core_stats->entries = DAL_STATS_ENTRIES_REGKEY_MAX;
+                       else
+                               core_stats->entries = reg_data;
+               }
 
-       core_stats->time = kzalloc(sizeof(struct stats_time_cache) * core_stats->entries,
-                                       GFP_KERNEL);
+               core_stats->time = kzalloc(sizeof(struct stats_time_cache) * core_stats->entries,
+                                               GFP_KERNEL);
+       } else {
+               core_stats->entries = 0;
+       }
 
        if (core_stats->time == NULL)
                goto fail_construct;