Skip to content

Commit fb7db66

Browse files
johnfanMrDuartePT
authored andcommitted
fix: Output 0 if point id not in curve
1 parent 4ef6609 commit fb7db66

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

kernel_module/legion-laptop.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,24 +2200,27 @@ static bool fancurve_set_speed_pwm(struct fancurve *fancurve, int point_id,
22002200
static bool fancurve_get_speed_pwm(const struct fancurve *fancurve,
22012201
int point_id, int fan_id, int *value)
22022202
{
2203-
const u8 *speed;
2203+
int speed;
2204+
2205+
pr_info("%s 1 point id=%d, fancurve=%p, fancurve.fan_speed_unit=%d, fancurve.size=%ld",
2206+
__func__, point_id, (void *) fancurve, fancurve->fan_speed_unit, fancurve->size);
22042207

22052208
if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) {
22062209
pr_err("Point id %d or fan id %d not valid", point_id, fan_id);
22072210
return false;
22082211
}
2209-
speed = fan_id == 0 ? &fancurve->points[point_id].speed1 :
2210-
&fancurve->points[point_id].speed2;
2212+
speed = fan_id == 0 ? fancurve->points[point_id].speed1 :
2213+
fancurve->points[point_id].speed2;
22112214

22122215
switch (fancurve->fan_speed_unit) {
22132216
case FAN_SPEED_UNIT_PERCENT:
2214-
*value = *speed * 255 / 100;
2217+
*value = speed * 255 / 100;
22152218
return true;
22162219
case FAN_SPEED_UNIT_PWM:
2217-
*value = *speed;
2220+
*value = speed;
22182221
return true;
22192222
case FAN_SPEED_UNIT_RPM_HUNDRED:
2220-
*value = *speed * 255 * 100 / MAX_RPM;
2223+
*value = speed * 255 * 100 / MAX_RPM;
22212224
return true;
22222225
default:
22232226
pr_info("No method to get for fan_speed_unit %d.",
@@ -5138,6 +5141,7 @@ static ssize_t autopoint_show(struct device *dev,
51385141
struct legion_private *priv = dev_get_drvdata(dev);
51395142
int fancurve_attr_id = to_sensor_dev_attr_2(devattr)->nr;
51405143
int point_id = to_sensor_dev_attr_2(devattr)->index;
5144+
bool ok = true;
51415145

51425146
mutex_lock(&priv->fancurve_mutex);
51435147
err = read_fancurve(priv, &fancurve);
@@ -5155,10 +5159,16 @@ static ssize_t autopoint_show(struct device *dev,
51555159

51565160
switch (fancurve_attr_id) {
51575161
case FANCURVE_ATTR_PWM1:
5158-
fancurve_get_speed_pwm(&fancurve, point_id, 0, &value);
5162+
pr_info("%s ->3a pwm1 point id=%d, fancurve_attr_id id=%d",
5163+
__func__, point_id, fancurve_attr_id);
5164+
ok = fancurve_get_speed_pwm(&fancurve, point_id, 0, &value);
5165+
pr_info("%s ok: %d->3a2", __func__, ok);
51595166
break;
51605167
case FANCURVE_ATTR_PWM2:
5161-
fancurve_get_speed_pwm(&fancurve, point_id, 1, &value);
5168+
pr_info("%s ->3b pwm2 point id=%d, fancurve_attr_id id=%d",
5169+
__func__, point_id, fancurve_attr_id);
5170+
ok = fancurve_get_speed_pwm(&fancurve, point_id, 1, &value);
5171+
pr_info("%s ok: %d->3b2", __func__, ok);
51625172
break;
51635173
case FANCURVE_ATTR_CPU_TEMP:
51645174
value = fancurve.points[point_id].cpu_max_temp_celsius;
@@ -5192,7 +5202,11 @@ static ssize_t autopoint_show(struct device *dev,
51925202
fancurve_attr_id);
51935203
return -EOPNOTSUPP;
51945204
}
5195-
5205+
if (!ok) {
5206+
pr_info("%s 4a: error!", __func__);
5207+
value = 0;
5208+
}
5209+
pr_info("%s 4b XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", __func__);
51965210
return sprintf(buf, "%d\n", value);
51975211
}
51985212

0 commit comments

Comments
 (0)