@@ -1228,7 +1228,7 @@ int smu_v13_0_set_fan_speed_rpm(struct smu_context *smu,
uint32_t tach_period;
int ret;
- if (!speed)
+ if (!speed || speed > smu->fan_max_rpm)
return -EINVAL;
ret = smu_v13_0_auto_fan_control(smu, 0);
@@ -947,6 +947,16 @@ static int smu_v13_0_0_get_dpm_ultimate_freq(struct smu_context *smu,
return 0;
}
+static int smu_v13_0_0_get_fan_parameters(struct smu_context *smu)
+{
+ struct smu_table_context *table_context = &smu->smu_table;
+ PPTable_t *smc_pptable = table_context->driver_pptable;
+
+ smu->fan_max_rpm = smc_pptable->SkuTable.FanMaximumRpm;
+
+ return 0;
+}
+
static int smu_v13_0_0_read_sensor(struct smu_context *smu,
enum amd_pp_sensors sensor,
void *data,
@@ -3045,6 +3055,7 @@ static const struct pptable_funcs smu_v13_0_0_ppt_funcs = {
.get_dpm_ultimate_freq = smu_v13_0_0_get_dpm_ultimate_freq,
.get_vbios_bootup_values = smu_v13_0_get_vbios_bootup_values,
.read_sensor = smu_v13_0_0_read_sensor,
+ .get_fan_parameters = smu_v13_0_0_get_fan_parameters,
.feature_is_enabled = smu_cmn_feature_is_enabled,
.print_clk_levels = smu_v13_0_0_print_clk_levels,
.force_clk_levels = smu_v13_0_0_force_clk_levels,
@@ -936,6 +936,16 @@ static int smu_v13_0_7_get_dpm_ultimate_freq(struct smu_context *smu,
return 0;
}
+static int smu_v13_0_7_get_fan_parameters(struct smu_context *smu)
+{
+ struct smu_table_context *table_context = &smu->smu_table;
+ PPTable_t *smc_pptable = table_context->driver_pptable;
+
+ smu->fan_max_rpm = smc_pptable->SkuTable.FanMaximumRpm;
+
+ return 0;
+}
+
static int smu_v13_0_7_read_sensor(struct smu_context *smu,
enum amd_pp_sensors sensor,
void *data,
@@ -2628,6 +2638,7 @@ static const struct pptable_funcs smu_v13_0_7_ppt_funcs = {
.get_dpm_ultimate_freq = smu_v13_0_7_get_dpm_ultimate_freq,
.get_vbios_bootup_values = smu_v13_0_get_vbios_bootup_values,
.read_sensor = smu_v13_0_7_read_sensor,
+ .get_fan_parameters = smu_v13_0_7_get_fan_parameters,
.feature_is_enabled = smu_cmn_feature_is_enabled,
.print_clk_levels = smu_v13_0_7_print_clk_levels,
.force_clk_levels = smu_v13_0_7_force_clk_levels,
If user-provided fan speed is higher than max speed, ->set_fan_speed_rpm() won't return error code, which can lead not only to problems with the hardware, but also to a zero division in smu_v13_0_set_fan_speed_rpm, since (8 * speed), which is used as a divisor, can evaluate to zero because of an integer overflow. Define ->get_fan_parameters() callbacks for smu_v13_0_0 and smu_v13_0_7 in order to have smu->fan_max_rpm variable initialized. Modify ->set_fan_speed_rpm() callback to fail if speed is higher than smu->fan_max_rpm. Fixes: c05d1c401572 ("drm/amd/swsmu: add aldebaran smu13 ip support (v3)") Signed-off-by: Murad Masimov <m.masimov@maxima.ru> --- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 2 +- drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 11 +++++++++++ drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) -- 2.39.2