diff options
| author | Kai Krakow <kai@kaishome.de> | 2026-08-08 22:36:04 +0200 |
|---|---|---|
| committer | Kai Krakow <kai@kaishome.de> | 2026-08-09 00:20:00 +0200 |
| commit | f014217288927246f92ee876afbbf9de8ba707be (patch) | |
| tree | 2f633faa5eec53b2441650f5a243b90cd77df4ac /src | |
| parent | 8187920ed261c7024826f8204cc7bea45153a3da (diff) | |
| download | hid-tmff2-f014217288927246f92ee876afbbf9de8ba707be.tar.gz hid-tmff2-f014217288927246f92ee876afbbf9de8ba707be.zip | |
use an unsigned 16-bit type for gain
+ Gain is documented and sent to the hardware as a value in the range 0 to
65535, but the module parameter and sysfs attribute accept wider integer
values. Store gain as a u16 and parse sysfs writes with kstrtou16 so
out-of-range values are rejected instead of being silently changed.
+ This constrains only the configured value. Calculations combining gain
values still require a wider intermediate to cover the product of two
full-range 16-bit values.
Diffstat (limited to 'src')
| -rw-r--r-- | src/hid-tmff2.c | 13 | ||||
| -rw-r--r-- | src/hid-tmff2.h | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/hid-tmff2.c b/src/hid-tmff2.c index 162a30a..9cf07b9 100644 --- a/src/hid-tmff2.c +++ b/src/hid-tmff2.c @@ -43,8 +43,8 @@ MODULE_PARM_DESC(alt_mode, "Alternate mode, eg. F1 mode"); #define GAIN_MAX 65535 -int gain = 40000; -module_param(gain, int, 0); +u16 gain = 40000; +module_param(gain, ushort, 0); MODULE_PARM_DESC(gain, "Level of gain (0-65535)"); @@ -230,14 +230,15 @@ static ssize_t gain_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct tmff2_device_entry *tmff2 = tmff2_from_hdev(to_hid_device(dev)); - unsigned int value; + u16 value; int ret; if (!tmff2) return -ENODEV; - if ((ret = kstrtouint(buf, 0, &value))) { - dev_err(dev, "kstrtouint failed at gain_store: %i", ret); + ret = kstrtou16(buf, 0, &value); + if (ret) { + dev_err(dev, "failed to parse gain: %d\n", ret); return ret; } @@ -251,7 +252,7 @@ static ssize_t gain_store(struct device *dev, static ssize_t gain_show(struct device *dev, struct device_attribute *attr, char *buf) { - return scnprintf(buf, PAGE_SIZE, "%i\n", gain); + return scnprintf(buf, PAGE_SIZE, "%u\n", gain); } static DEVICE_ATTR_RW(gain); diff --git a/src/hid-tmff2.h b/src/hid-tmff2.h index 6ad1d82..58ab8f3 100644 --- a/src/hid-tmff2.h +++ b/src/hid-tmff2.h @@ -11,7 +11,7 @@ extern int spring_level; extern int damper_level; extern int friction_level; extern int range; -extern int gain; +extern u16 gain; extern int alt_mode; #define USB_VENDOR_ID_THRUSTMASTER 0x044f |
