@@ -2120,11 +2120,14 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
2120
2120
return state_index ;
2121
2121
/* last mode is usually default, array is low to high */
2122
2122
for (i = 0 ; i < num_modes ; i ++ ) {
2123
- rdev -> pm .power_state [state_index ].clock_info =
2124
- kcalloc (1 , sizeof (struct radeon_pm_clock_info ),
2125
- GFP_KERNEL );
2123
+ /* avoid memory leaks from invalid modes or unknown frev. */
2124
+ if (!rdev -> pm .power_state [state_index ].clock_info ) {
2125
+ rdev -> pm .power_state [state_index ].clock_info =
2126
+ kzalloc (sizeof (struct radeon_pm_clock_info ),
2127
+ GFP_KERNEL );
2128
+ }
2126
2129
if (!rdev -> pm .power_state [state_index ].clock_info )
2127
- return state_index ;
2130
+ goto out ;
2128
2131
rdev -> pm .power_state [state_index ].num_clock_modes = 1 ;
2129
2132
rdev -> pm .power_state [state_index ].clock_info [0 ].voltage .type = VOLTAGE_NONE ;
2130
2133
switch (frev ) {
@@ -2243,8 +2246,15 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
2243
2246
break ;
2244
2247
}
2245
2248
}
2249
+ out :
2250
+ /* free any unused clock_info allocation. */
2251
+ if (state_index && state_index < num_modes ) {
2252
+ kfree (rdev -> pm .power_state [state_index ].clock_info );
2253
+ rdev -> pm .power_state [state_index ].clock_info = NULL ;
2254
+ }
2255
+
2246
2256
/* last mode is usually default */
2247
- if (rdev -> pm .default_power_state_index == -1 ) {
2257
+ if (state_index && rdev -> pm .default_power_state_index == -1 ) {
2248
2258
rdev -> pm .power_state [state_index - 1 ].type =
2249
2259
POWER_STATE_TYPE_DEFAULT ;
2250
2260
rdev -> pm .default_power_state_index = state_index - 1 ;
0 commit comments