Check sysfs_emit_at() in smu_v13_0_0_emit_clk_levels() and smu_v13_0_7_emit_clk_levels() and stop emitting when the sysfs page is full
Signed-off-by: Asad Kamal <[email protected]> --- .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 263 +++++++++++++----- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 251 ++++++++++++----- 2 files changed, 376 insertions(+), 138 deletions(-) diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c index 30d9cfac0d89..fa91837f7024 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c @@ -1206,7 +1206,7 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, struct smu_13_0_dpm_context *dpm_context = smu_dpm->dpm_context; OverDriveTableExternal_t *od_table = (OverDriveTableExternal_t *)smu->smu_table.overdrive_table; - int i, curr_freq, size = *offset, start_offset = *offset; + int i, curr_freq, size = *offset, start_offset = *offset, n; struct smu_dpm_table *single_dpm_table = NULL; struct smu_pcie_table *pcie_table; uint32_t gen_speed, lane_width; @@ -1265,10 +1265,16 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFXCLK_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_SCLK:\n"); - size += sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMhz\n", - od_table->OverDriveTable.GfxclkFmin, - od_table->OverDriveTable.GfxclkFmax); + n = sysfs_emit_at(buf, size, "OD_SCLK:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMhz\n", + od_table->OverDriveTable.GfxclkFmin, + od_table->OverDriveTable.GfxclkFmax); + if (!n) + goto out; + size += n; break; case SMU_OD_MCLK: @@ -1276,10 +1282,16 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_UCLK_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_MCLK:\n"); - size += sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMHz\n", - od_table->OverDriveTable.UclkFmin, - od_table->OverDriveTable.UclkFmax); + n = sysfs_emit_at(buf, size, "OD_MCLK:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMHz\n", + od_table->OverDriveTable.UclkFmin, + od_table->OverDriveTable.UclkFmax); + if (!n) + goto out; + size += n; break; case SMU_OD_VDDGFX_OFFSET: @@ -1287,9 +1299,15 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFX_VF_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_VDDGFX_OFFSET:\n"); - size += sysfs_emit_at(buf, size, "%dmV\n", - od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]); + n = sysfs_emit_at(buf, size, "OD_VDDGFX_OFFSET:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%dmV\n", + od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_CURVE: @@ -1297,27 +1315,43 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_FAN_CURVE:\n"); - for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++) - size += sysfs_emit_at(buf, size, "%d: %dC %d%%\n", - i, - (int)od_table->OverDriveTable.FanLinearTempPoints[i], - (int)od_table->OverDriveTable.FanLinearPwmPoints[i]); + n = sysfs_emit_at(buf, size, "OD_FAN_CURVE:\n"); + if (!n) + goto out; + size += n; + for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++) { + n = sysfs_emit_at(buf, size, "%d: %dC %d%%\n", + i, + (int)od_table->OverDriveTable.FanLinearTempPoints[i], + (int)od_table->OverDriveTable.FanLinearPwmPoints[i]); + if (!n) + goto out; + size += n; + } - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_CURVE_TEMP, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "FAN_CURVE(hotspot temp): %uC %uC\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "FAN_CURVE(hotspot temp): %uC %uC\n", + min_value, max_value); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_CURVE_PWM, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "FAN_CURVE(fan speed): %u%% %u%%\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "FAN_CURVE(fan speed): %u%% %u%%\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; @@ -1326,17 +1360,29 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_ACOUSTIC_LIMIT:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.AcousticLimitRpmThreshold); - - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "OD_ACOUSTIC_LIMIT:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.AcousticLimitRpmThreshold); + if (!n) + goto out; + size += n; + + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ACOUSTIC_LIMIT: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ACOUSTIC_LIMIT: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_ACOUSTIC_TARGET: @@ -1344,17 +1390,29 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_ACOUSTIC_TARGET:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.AcousticTargetRpmThreshold); - - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "OD_ACOUSTIC_TARGET:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.AcousticTargetRpmThreshold); + if (!n) + goto out; + size += n; + + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ACOUSTIC_TARGET, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ACOUSTIC_TARGET: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ACOUSTIC_TARGET: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_TARGET_TEMPERATURE: @@ -1362,17 +1420,29 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_TARGET_TEMPERATURE:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanTargetTemperature); - - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "FAN_TARGET_TEMPERATURE:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanTargetTemperature); + if (!n) + goto out; + size += n; + + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_TARGET_TEMPERATURE, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "TARGET_TEMPERATURE: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "TARGET_TEMPERATURE: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_MINIMUM_PWM: @@ -1380,17 +1450,29 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanMinimumPwm); - - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanMinimumPwm); + if (!n) + goto out; + size += n; + + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_MINIMUM_PWM, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "MINIMUM_PWM: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "MINIMUM_PWM: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_ZERO_RPM_ENABLE: @@ -1398,17 +1480,29 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_ZERO_FAN_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_ZERO_RPM_ENABLE:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanZeroRpmEnable); - - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "FAN_ZERO_RPM_ENABLE:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanZeroRpmEnable); + if (!n) + goto out; + size += n; + + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ZERO_RPM_ENABLE, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ZERO_RPM_ENABLE: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ZERO_RPM_ENABLE: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_ZERO_RPM_STOP_TEMP: @@ -1416,17 +1510,29 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_ZERO_FAN_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_ZERO_RPM_STOP_TEMPERATURE:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanZeroRpmStopTemp); - - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "FAN_ZERO_RPM_STOP_TEMPERATURE:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanZeroRpmStopTemp); + if (!n) + goto out; + size += n; + + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_0_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ZERO_RPM_STOP_TEMPERATURE: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ZERO_RPM_STOP_TEMPERATURE: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_RANGE: @@ -1435,7 +1541,10 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, !smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_GFX_VF_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; if (smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT)) { smu_v13_0_0_get_od_setting_limits(smu, @@ -1446,8 +1555,11 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFXCLK_FMAX, NULL, &max_value); - size += sysfs_emit_at(buf, size, "SCLK: %7uMhz %10uMhz\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "SCLK: %7uMhz %10uMhz\n", + min_value, max_value); + if (!n) + goto out; + size += n; } if (smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT)) { @@ -1459,8 +1571,11 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_UCLK_FMAX, NULL, &max_value); - size += sysfs_emit_at(buf, size, "MCLK: %7uMhz %10uMhz\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "MCLK: %7uMhz %10uMhz\n", + min_value, max_value); + if (!n) + goto out; + size += n; } if (smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_GFX_VF_CURVE_BIT)) { @@ -1468,8 +1583,11 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFX_VF_CURVE, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "VDDGFX_OFFSET: %7dmv %10dmv\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "VDDGFX_OFFSET: %7dmv %10dmv\n", + min_value, max_value); + if (!n) + goto out; + size += n; } break; @@ -1489,6 +1607,7 @@ static int smu_v13_0_0_emit_clk_levels(struct smu_context *smu, curr_freq, buf, offset); } +out: *offset += size - start_offset; return 0; diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c index d253ce367476..25f977a42a1c 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c @@ -1216,7 +1216,7 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, struct smu_13_0_dpm_context *dpm_context = smu_dpm->dpm_context; OverDriveTableExternal_t *od_table = (OverDriveTableExternal_t *)smu->smu_table.overdrive_table; - int i, curr_freq, size = *offset, start_offset = *offset; + int i, curr_freq, size = *offset, start_offset = *offset, n; struct smu_dpm_table *single_dpm_table = NULL; struct smu_pcie_table *pcie_table; uint32_t gen_speed, lane_width; @@ -1275,10 +1275,16 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFXCLK_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_SCLK:\n"); - size += sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMhz\n", - od_table->OverDriveTable.GfxclkFmin, - od_table->OverDriveTable.GfxclkFmax); + n = sysfs_emit_at(buf, size, "OD_SCLK:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMhz\n", + od_table->OverDriveTable.GfxclkFmin, + od_table->OverDriveTable.GfxclkFmax); + if (!n) + goto out; + size += n; break; case SMU_OD_MCLK: @@ -1286,10 +1292,16 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_UCLK_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_MCLK:\n"); - size += sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMHz\n", - od_table->OverDriveTable.UclkFmin, - od_table->OverDriveTable.UclkFmax); + n = sysfs_emit_at(buf, size, "OD_MCLK:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "0: %uMhz\n1: %uMHz\n", + od_table->OverDriveTable.UclkFmin, + od_table->OverDriveTable.UclkFmax); + if (!n) + goto out; + size += n; break; case SMU_OD_VDDGFX_OFFSET: @@ -1297,9 +1309,15 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFX_VF_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_VDDGFX_OFFSET:\n"); - size += sysfs_emit_at(buf, size, "%dmV\n", - od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]); + n = sysfs_emit_at(buf, size, "OD_VDDGFX_OFFSET:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%dmV\n", + od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_CURVE: @@ -1307,27 +1325,43 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_FAN_CURVE:\n"); - for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++) - size += sysfs_emit_at(buf, size, "%d: %dC %d%%\n", - i, - (int)od_table->OverDriveTable.FanLinearTempPoints[i], - (int)od_table->OverDriveTable.FanLinearPwmPoints[i]); + n = sysfs_emit_at(buf, size, "OD_FAN_CURVE:\n"); + if (!n) + goto out; + size += n; + for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++) { + n = sysfs_emit_at(buf, size, "%d: %dC %d%%\n", + i, + (int)od_table->OverDriveTable.FanLinearTempPoints[i], + (int)od_table->OverDriveTable.FanLinearPwmPoints[i]); + if (!n) + goto out; + size += n; + } - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_CURVE_TEMP, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "FAN_CURVE(hotspot temp): %uC %uC\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "FAN_CURVE(hotspot temp): %uC %uC\n", + min_value, max_value); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_CURVE_PWM, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "FAN_CURVE(fan speed): %u%% %u%%\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "FAN_CURVE(fan speed): %u%% %u%%\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; @@ -1336,17 +1370,29 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_ACOUSTIC_LIMIT:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.AcousticLimitRpmThreshold); + n = sysfs_emit_at(buf, size, "OD_ACOUSTIC_LIMIT:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.AcousticLimitRpmThreshold); + if (!n) + goto out; + size += n; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ACOUSTIC_LIMIT: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ACOUSTIC_LIMIT: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_ACOUSTIC_TARGET: @@ -1354,17 +1400,29 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "OD_ACOUSTIC_TARGET:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.AcousticTargetRpmThreshold); + n = sysfs_emit_at(buf, size, "OD_ACOUSTIC_TARGET:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.AcousticTargetRpmThreshold); + if (!n) + goto out; + size += n; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ACOUSTIC_TARGET, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ACOUSTIC_TARGET: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ACOUSTIC_TARGET: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_TARGET_TEMPERATURE: @@ -1372,17 +1430,29 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_TARGET_TEMPERATURE:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanTargetTemperature); + n = sysfs_emit_at(buf, size, "FAN_TARGET_TEMPERATURE:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanTargetTemperature); + if (!n) + goto out; + size += n; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_TARGET_TEMPERATURE, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "TARGET_TEMPERATURE: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "TARGET_TEMPERATURE: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_MINIMUM_PWM: @@ -1390,17 +1460,29 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_FAN_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanMinimumPwm); + n = sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanMinimumPwm); + if (!n) + goto out; + size += n; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_MINIMUM_PWM, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "MINIMUM_PWM: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "MINIMUM_PWM: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_ZERO_RPM_ENABLE: @@ -1408,17 +1490,29 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_ZERO_FAN_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_ZERO_RPM_ENABLE:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanZeroRpmEnable); + n = sysfs_emit_at(buf, size, "FAN_ZERO_RPM_ENABLE:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanZeroRpmEnable); + if (!n) + goto out; + size += n; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ZERO_RPM_ENABLE, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ZERO_RPM_ENABLE: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ZERO_RPM_ENABLE: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_FAN_ZERO_RPM_STOP_TEMP: @@ -1426,17 +1520,29 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_ZERO_FAN_BIT)) break; - size += sysfs_emit_at(buf, size, "FAN_ZERO_RPM_STOP_TEMPERATURE:\n"); - size += sysfs_emit_at(buf, size, "%d\n", - (int)od_table->OverDriveTable.FanZeroRpmStopTemp); + n = sysfs_emit_at(buf, size, "FAN_ZERO_RPM_STOP_TEMPERATURE:\n"); + if (!n) + goto out; + size += n; + n = sysfs_emit_at(buf, size, "%d\n", + (int)od_table->OverDriveTable.FanZeroRpmStopTemp); + if (!n) + goto out; + size += n; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; smu_v13_0_7_get_od_setting_limits(smu, PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "ZERO_RPM_STOP_TEMPERATURE: %u %u\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "ZERO_RPM_STOP_TEMPERATURE: %u %u\n", + min_value, max_value); + if (!n) + goto out; + size += n; break; case SMU_OD_RANGE: @@ -1445,7 +1551,10 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, !smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_GFX_VF_CURVE_BIT)) break; - size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + n = sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE"); + if (!n) + goto out; + size += n; if (smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT)) { smu_v13_0_7_get_od_setting_limits(smu, @@ -1456,8 +1565,11 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFXCLK_FMAX, NULL, &max_value); - size += sysfs_emit_at(buf, size, "SCLK: %7uMhz %10uMhz\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "SCLK: %7uMhz %10uMhz\n", + min_value, max_value); + if (!n) + goto out; + size += n; } if (smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT)) { @@ -1469,8 +1581,11 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_UCLK_FMAX, NULL, &max_value); - size += sysfs_emit_at(buf, size, "MCLK: %7uMhz %10uMhz\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "MCLK: %7uMhz %10uMhz\n", + min_value, max_value); + if (!n) + goto out; + size += n; } if (smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_GFX_VF_CURVE_BIT)) { @@ -1478,8 +1593,11 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, PP_OD_FEATURE_GFX_VF_CURVE, &min_value, &max_value); - size += sysfs_emit_at(buf, size, "VDDGFX_OFFSET: %7dmv %10dmv\n", - min_value, max_value); + n = sysfs_emit_at(buf, size, "VDDGFX_OFFSET: %7dmv %10dmv\n", + min_value, max_value); + if (!n) + goto out; + size += n; } break; @@ -1499,6 +1617,7 @@ static int smu_v13_0_7_emit_clk_levels(struct smu_context *smu, curr_freq, buf, offset); } +out: *offset += size - start_offset; return 0; -- 2.46.0
