Skip to contentSkip to conversation

linux-input: dynamically allocate ABS axis information

RFC In review Daniel Mack 5 participants 20 messages May 19, 2010 – Aug 13, 2010

Subsystems (2)
lore
Share & tools
lore
#5 lore raw

PATCH 4/4 input: dynamically allocate ABS information

In reply to Daniel Mack

As all callers are now changed to only use the input_abs_*() access helpers, switching over to dynamically allocated ABS information is easy.

Cc Dmitry Torokhov <[email protected]>
---
 drivers/input/input.c |   26 ++++++++++++++++++++
 include/linux/input.h |   63 +++++++++++++++++++++++++++++++-----------------
 2 files changed, 67 insertions(+), 22 deletions(-)
drivers/input/input.c +26 -0
index 5bc92f6..ced6b39 100644
@@ -373,6 +373,25 @@ void input_inject_event(struct input_handle *handle,
 EXPORT_SYMBOL(input_inject_event);
 
 /**
+ * input_alloc_absinfo - allocates an input_absinfo struct
+ * @dev: the input device
+ * @axis: the ABS axis
+ *
+ * If the absinfo struct the caller asked for is already allocated, this
+ * functions will not do anything but return it.
+ */
+struct input_absinfo *input_alloc_absinfo(struct input_dev *dev, int axis)
+{
+	if (!dev->absinfo[axis])
+		dev->absinfo[axis] =
+			kzalloc(sizeof(struct input_absinfo), GFP_KERNEL);
+
+	WARN(!dev->absinfo[axis], "%s(): kzalloc() failed?\n", __func__);
+	return dev->absinfo[axis];
+}
+EXPORT_SYMBOL(input_alloc_absinfo);
+
+/**
  * input_grab_device - grabs device for exclusive use
  * @handle: input handle that wants to own the device
  *
@@ -1276,9 +1295,16 @@ static const struct attribute_group *input_dev_attr_groups[] = {
 
 static void input_dev_release(struct device *device)
 {
+	int i;
 	struct input_dev *dev = to_input_dev(device);
 
 	input_ff_destroy(dev);
+
+	for (i = 0; i < ABS_CNT; i++) {
+		kfree(dev->absinfo[i]);
+		dev->absinfo[i] = NULL;
+	}
+
 	kfree(dev);
 
 	module_put(THIS_MODULE);
include/linux/input.h +41 -22

131 lines not on this page · raw message

Signature · 1 line
1.7.1
#0 lore raw

To support more axis on input devices, we should dynamically allocate ABS axis information. Currently, six values (value, min, max, fuzz, flat and resolution) are stored in arrays, each of ABS_CNT elements.

The following four patches makes the input core reuse the input_absinfo struct and only carry one pointer per axis. These structs are allocated on demand now, making it less painful to add new ABS axis eventually.

As everything is now nicely abstracted, we might even move over to a more efficient storage than a linear pointer, but that can be done later.

I successfully tested this on my desktop machine here.

Let me know what you think.

Thanks,
Daniel

[PATCH 1/4] input: use ABS_CNT rather than (ABS_MAX + 1) [PATCH 2/4] input: add static inline helpers for ABS properties [PATCH 3/4] input: switch to input_abs_*() access functions [PATCH 4/4] input: dynamically allocate ABS information

#1 lore raw

PATCH 1/4 input: use ABS_CNT rather than (ABS_MAX + 1)

Cc Dmitry Torokhov <[email protected]>
---
 drivers/hid/hid-debug.c     |    2 +-
 drivers/input/joydev.c      |   10 +++++-----
 drivers/input/misc/uinput.c |    4 ++--
 include/linux/input.h       |   12 ++++++------
 include/linux/joystick.h    |    4 ++--
 include/linux/uinput.h      |   10 +++++-----
 6 files changed, 21 insertions(+), 21 deletions(-)
drivers/hid/hid-debug.c +1 -1
index 56f314f..c940267 100644
@@ -811,7 +811,7 @@ static const char *relatives[REL_MAX + 1] = {
 	[REL_WHEEL] = "Wheel",		[REL_MISC] = "Misc",
 };
 
-static const char *absolutes[ABS_MAX + 1] = {
+static const char *absolutes[ABS_CNT] = {
 	[ABS_X] = "X",			[ABS_Y] = "Y",
 	[ABS_Z] = "Z",			[ABS_RX] = "Rx",
 	[ABS_RY] = "Ry",		[ABS_RZ] = "Rz",
drivers/input/joydev.c +5 -5
index c52bec4..d1902ac 100644
@@ -47,15 +47,15 @@ struct joydev {
 	struct mutex mutex;
 	struct device dev;
 
-	struct js_corr corr[ABS_MAX + 1];
+	struct js_corr corr[ABS_CNT];
 	struct JS_DATA_SAVE_TYPE glue;
 	int nabs;
 	int nkey;
 	__u16 keymap[KEY_MAX - BTN_MISC + 1];
 	__u16 keypam[KEY_MAX - BTN_MISC + 1];
-	__u8 absmap[ABS_MAX + 1];
-	__u8 abspam[ABS_MAX + 1];
-	__s16 abs[ABS_MAX + 1];
+	__u8 absmap[ABS_CNT];
+	__u8 abspam[ABS_CNT];
+	__s16 abs[ABS_CNT];
 };
 
 struct joydev_client {
@@ -826,7 +826,7 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
 	joydev->handle.handler = handler;
 	joydev->handle.private = joydev;
 
-	for (i = 0; i < ABS_MAX + 1; i++)
+	for (i = 0; i < ABS_CNT; i++)
 		if (test_bit(i, dev->absbit)) {
 			joydev->absmap[i] = joydev->nabs;
 			joydev->abspam[joydev->nabs] = i;
drivers/input/misc/uinput.c +2 -2
index 1477466..f3f03b7 100644
@@ -300,7 +300,7 @@ static int uinput_validate_absbits(struct input_dev *dev)
 	unsigned int cnt;
 	int retval = 0;
 
-	for (cnt = 0; cnt < ABS_MAX + 1; cnt++) {
+	for (cnt = 0; cnt < ABS_CNT; cnt++) {
 		if (!test_bit(cnt, dev->absbit))
 			continue;
 
@@ -387,7 +387,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
 	dev->id.product	= user_dev->id.product;
 	dev->id.version	= user_dev->id.version;
 
-	size = sizeof(int) * (ABS_MAX + 1);
+	size = sizeof(int) * (ABS_CNT);
 	memcpy(dev->absmax, user_dev->absmax, size);
 	memcpy(dev->absmin, user_dev->absmin, size);
 	memcpy(dev->absfuzz, user_dev->absfuzz, size);
include/linux/input.h +6 -6
index 7ed2251..0e41f77 100644
@@ -1154,7 +1154,7 @@ struct input_dev {
 
 	int sync;
 
-	int abs[ABS_MAX + 1];
+	int abs[ABS_CNT];
 	int rep[REP_MAX + 1];
 
 	unsigned long key[BITS_TO_LONGS(KEY_CNT)];
@@ -1162,11 +1162,11 @@ struct input_dev {
 	unsigned long snd[BITS_TO_LONGS(SND_CNT)];
 	unsigned long sw[BITS_TO_LONGS(SW_CNT)];
 
-	int absmax[ABS_MAX + 1];
-	int absmin[ABS_MAX + 1];
-	int absfuzz[ABS_MAX + 1];
-	int absflat[ABS_MAX + 1];
-	int absres[ABS_MAX + 1];
+	int absmax[ABS_CNT];
+	int absmin[ABS_CNT];
+	int absfuzz[ABS_CNT];
+	int absflat[ABS_CNT];
+	int absres[ABS_CNT];
 
 	int (*open)(struct input_dev *dev);
 	void (*close)(struct input_dev *dev);
include/linux/joystick.h +2 -2
index 9e20c29..47199b1 100644
@@ -64,8 +64,8 @@ struct js_event {
 #define JSIOCSCORR		_IOW('j', 0x21, struct js_corr)			/* set correction values */
 #define JSIOCGCORR		_IOR('j', 0x22, struct js_corr)			/* get correction values */
 
-#define JSIOCSAXMAP		_IOW('j', 0x31, __u8[ABS_MAX + 1])		/* set axis mapping */
-#define JSIOCGAXMAP		_IOR('j', 0x32, __u8[ABS_MAX + 1])		/* get axis mapping */
+#define JSIOCSAXMAP		_IOW('j', 0x31, __u8[ABS_CNT])			/* set axis mapping */
+#define JSIOCGAXMAP		_IOR('j', 0x32, __u8[ABS_CNT])			/* get axis mapping */
 #define JSIOCSBTNMAP		_IOW('j', 0x33, __u16[KEY_MAX - BTN_MISC + 1])	/* set button mapping */
 #define JSIOCGBTNMAP		_IOR('j', 0x34, __u16[KEY_MAX - BTN_MISC + 1])	/* get button mapping */
 
include/linux/uinput.h +5 -5
index 15ddd44..60c81da 100644
@@ -166,11 +166,11 @@ struct uinput_ff_erase {
 struct uinput_user_dev {
 	char name[UINPUT_MAX_NAME_SIZE];
 	struct input_id id;
-        int ff_effects_max;
-        int absmax[ABS_MAX + 1];
-        int absmin[ABS_MAX + 1];
-        int absfuzz[ABS_MAX + 1];
-        int absflat[ABS_MAX + 1];
+	int ff_effects_max;
+	int absmax[ABS_CNT];
+	int absmin[ABS_CNT];
+	int absfuzz[ABS_CNT];
+	int absflat[ABS_CNT];
 };
 #endif	/* __UINPUT_H_ */
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/4 input: add static inline helpers for ABS properties

In reply to Daniel Mack

In preparation for dynamically allocated ABS axis, introduce a number of sttaic inline access helpers. This should make the transition less painful.

Cc Dmitry Torokhov <[email protected]>
---
 include/linux/input.h |   60 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)
include/linux/input.h +60 -0
index 0e41f77..ff1ee6d 100644
@@ -1188,6 +1188,66 @@ struct input_dev {
 };
 #define to_input_dev(d) container_of(d, struct input_dev, dev)
 
+static inline int input_abs(struct input_dev *dev, int axis)
+{
+	return dev->abs[axis];
+}
+
+static inline int input_abs_max(struct input_dev *dev, int axis)
+{
+	return dev->absmax[axis];
+}
+
+static inline int input_abs_min(struct input_dev *dev, int axis)
+{
+	return dev->absmin[axis];
+}
+
+static inline int input_abs_fuzz(struct input_dev *dev, int axis)
+{
+	return dev->absfuzz[axis];
+}
+
+static inline int input_abs_flat(struct input_dev *dev, int axis)
+{
+	return dev->absflat[axis];
+}
+
+static inline int input_abs_res(struct input_dev *dev, int axis)
+{
+	return dev->absres[axis];
+}
+
+static inline void input_abs_set(struct input_dev *dev, int axis, int val)
+{
+	dev->abs[axis] = val;
+}
+
+static inline void input_abs_set_max(struct input_dev *dev, int axis, int val)
+{
+	dev->absmax[axis] = val;
+}
+
+static inline void input_abs_set_min(struct input_dev *dev, int axis, int val)
+{
+	dev->absmin[axis] = val;
+}
+
+static inline void input_abs_set_fuzz(struct input_dev *dev, int axis, int val)
+{
+	dev->absfuzz[axis] = val;
+}
+
+static inline void input_abs_set_flat(struct input_dev *dev, int axis, int val)
+{
+	dev->absflat[axis] = val;
+}
+
+static inline void input_abs_set_res(struct input_dev *dev, int axis, int val)
+{
+	dev->absres[axis] = val;
+}
+
 /*
  * Verify that we are in sync with input_device_id mod_devicetable.h #defines
  */
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/4 input: switch to input_abs_*() access functions

In reply to Daniel Mack

Change all call sites in drivers/input to not access the ABS axis information directly anymore. Make them use the access helpers instead.

Also use input_set_abs_params() when possible.
Did some code refactoring as I was on it.

Cc Dmitry Torokhov <[email protected]>
---
 drivers/hid/hid-wacom.c             |   15 +++++++------
 drivers/input/evdev.c               |   26 +++++++++++-----------
 drivers/input/input.c               |    7 +++--
 drivers/input/joydev.c              |   24 +++++++++++---------
 drivers/input/joystick/a3d.c        |    2 +-
 drivers/input/joystick/adi.c        |    2 +-
 drivers/input/joystick/amijoy.c     |    4 +-
 drivers/input/joystick/gf2k.c       |   16 +++++++------
 drivers/input/joystick/interact.c   |    8 +++---
 drivers/input/joystick/sidewinder.c |   18 +++++++++++----
 drivers/input/keyboard/hil_kbd.c    |   21 ++++++++++-------
 drivers/input/misc/uinput.c         |   29 ++++++++++++++----------
 drivers/input/mouse/pc110pad.c      |    4 +-
 drivers/input/mouse/synaptics.c     |    4 +-
 drivers/input/mousedev.c            |   40 ++++++++++++++--------------------
 drivers/input/tablet/acecad.c       |   16 +++++++-------
 drivers/input/tablet/aiptek.c       |   18 +++++++-------
 17 files changed, 135 insertions(+), 119 deletions(-)
drivers/hid/hid-wacom.c +8 -7
index f7700cf..ce766a3 100644
@@ -85,7 +85,7 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
 				input_report_key(input, BTN_RIGHT, 0);
 				input_report_key(input, BTN_MIDDLE, 0);
 				input_report_abs(input, ABS_DISTANCE,
-						input->absmax[ABS_DISTANCE]);
+					input_abs_max(input, ABS_DISTANCE));
 			} else {
 				input_report_key(input, BTN_TOUCH, 0);
 				input_report_key(input, BTN_STYLUS, 0);
@@ -235,13 +235,14 @@ static int wacom_probe(struct hid_device *hdev,
 	set_bit(BTN_TOOL_RUBBER, input->keybit);
 	set_bit(BTN_TOOL_MOUSE, input->keybit);
 
-	input->absmax[ABS_PRESSURE] = 511;
-	input->absmax[ABS_DISTANCE] = 32;
+	input_abs_set_max(input, ABS_PRESSURE, 511);
+	input_abs_set_max(input, ABS_DISTANCE, 32);
 
-	input->absmax[ABS_X] = 16704;
-	input->absmax[ABS_Y] = 12064;
-	input->absfuzz[ABS_X] = 4;
-	input->absfuzz[ABS_Y] = 4;
+	input_abs_set_max(input, ABS_X, 16704);
+	input_abs_set_max(input, ABS_Y, 12064);
+
+	input_abs_set_fuzz(input, ABS_X, 4);
+	input_abs_set_fuzz(input, ABS_Y, 4);
 
 	return 0;
 err_free:
drivers/input/evdev.c +13 -13
index 2ee6c7a..ab19102 100644
@@ -624,12 +624,12 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 
 				t = _IOC_NR(cmd) & ABS_MAX;
 
-				abs.value = dev->abs[t];
-				abs.minimum = dev->absmin[t];
-				abs.maximum = dev->absmax[t];
-				abs.fuzz = dev->absfuzz[t];
-				abs.flat = dev->absflat[t];
-				abs.resolution = dev->absres[t];
+				abs.value = input_abs(dev, t);
+				abs.minimum = input_abs_min(dev, t);
+				abs.maximum = input_abs_max(dev, t);
+				abs.fuzz = input_abs_fuzz(dev, t);
+				abs.flat = input_abs_flat(dev, t);
+				abs.resolution = input_abs_res(dev, t);
 
 				if (copy_to_user(p, &abs, min_t(size_t,
 								_IOC_SIZE(cmd),
@@ -672,13 +672,13 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 				 */
 				spin_lock_irq(&dev->event_lock);
 
-				dev->abs[t] = abs.value;
-				dev->absmin[t] = abs.minimum;
-				dev->absmax[t] = abs.maximum;
-				dev->absfuzz[t] = abs.fuzz;
-				dev->absflat[t] = abs.flat;
-				dev->absres[t] = _IOC_SIZE(cmd) < sizeof(struct input_absinfo) ?
-							0 : abs.resolution;
+				input_abs_set(dev, t, abs.value);
+				input_abs_set_min(dev, t, abs.minimum);
+				input_abs_set_max(dev, t, abs.maximum);
+				input_abs_set_fuzz(dev, t, abs.fuzz);
+				input_abs_set_flat(dev, t, abs.flat);
+				input_abs_set_res(dev, t, _IOC_SIZE(cmd) < sizeof(struct input_absinfo) ?
+								0 : abs.resolution);
 
 				spin_unlock_irq(&dev->event_lock);
 
drivers/input/input.c +4 -3
index 9c79bd5..5bc92f6 100644
@@ -241,10 +241,11 @@ static void input_handle_event(struct input_dev *dev,
 			}
 
 			value = input_defuzz_abs_event(value,
-					dev->abs[code], dev->absfuzz[code]);
+					input_abs(dev, code),
+					input_abs_fuzz(dev, code));
 
-			if (dev->abs[code] != value) {
-				dev->abs[code] = value;
+			if (input_abs(dev, code) != value) {
+				input_abs_set(dev, code, value);
 				disposition = INPUT_PASS_TO_HANDLERS;
 			}
 		}
drivers/input/joydev.c +13 -11
index d1902ac..f34fa8a 100644
@@ -562,11 +562,11 @@ static int joydev_ioctl_common(struct joydev *joydev,
 	case JSIOCSCORR:
 		if (copy_from_user(joydev->corr, argp,
 			      sizeof(joydev->corr[0]) * joydev->nabs))
-		    return -EFAULT;
+			return -EFAULT;
 
 		for (i = 0; i < joydev->nabs; i++) {
 			j = joydev->abspam[i];
-			joydev->abs[i] = joydev_correct(dev->abs[j],
+			joydev->abs[i] = joydev_correct(input_abs(dev, j),
 							&joydev->corr[i]);
 		}
 		return 0;
@@ -849,24 +849,26 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
 
 	for (i = 0; i < joydev->nabs; i++) {
 		j = joydev->abspam[i];
-		if (dev->absmax[j] == dev->absmin[j]) {
+		if (input_abs_max(dev, j) == input_abs_min(dev, j)) {
 			joydev->corr[i].type = JS_CORR_NONE;
-			joydev->abs[i] = dev->abs[j];
+			joydev->abs[i] = input_abs(dev, j);
 			continue;
 		}
 		joydev->corr[i].type = JS_CORR_BROKEN;
-		joydev->corr[i].prec = dev->absfuzz[j];
-		joydev->corr[i].coef[0] =
-			(dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j];
-		joydev->corr[i].coef[1] =
-			(dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j];
+		joydev->corr[i].prec = input_abs_fuzz(dev, j);
+
+		t = (input_abs_max(dev, j) + input_abs_min(dev, j)) / 2
+			- input_abs_flat(dev, j);
+		joydev->corr[i].coef[0] = t;
+		joydev->corr[i].coef[1] = t;
 
-		t = (dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j];
+		t = (input_abs_max(dev, j) - input_abs_min(dev, j)) / 2
+			- 2 * input_abs_flat(dev, j);
 		if (t) {
 			joydev->corr[i].coef[2] = (1 << 29) / t;
 			joydev->corr[i].coef[3] = (1 << 29) / t;
 
-			joydev->abs[i] = joydev_correct(dev->abs[j],
+			joydev->abs[i] = joydev_correct(input_abs(dev, j),
 							joydev->corr + i);
 		}
 	}
drivers/input/joystick/a3d.c +1 -1
index 6489f40..6b84b72 100644
@@ -342,7 +342,7 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 		for (i = 0; i < 4; i++) {
 			if (i < 2)
-				input_set_abs_params(input_dev, axes[i], 48, input_dev->abs[axes[i]] * 2 - 48, 0, 8);
+				input_set_abs_params(input_dev, axes[i], 48, input_abs(input_dev, axes[i]) * 2 - 48, 0, 8);
 			else
 				input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0);
 			input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
drivers/input/joystick/adi.c +1 -1
index 89c4c08..7cc9263 100644
@@ -452,7 +452,7 @@ static void adi_init_center(struct adi *adi)
 	for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
 
 		t = adi->abs[i];
-		x = adi->dev->abs[t];
+		x = input_abs(adi->dev, t);
 
 		if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
 			x = i < adi->axes10 ? 512 : 128;
drivers/input/joystick/amijoy.c +2 -2
index 05022f0..03022f6 100644
@@ -139,8 +139,8 @@ static int __init amijoy_init(void)
 		amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
 			BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
 		for (j = 0; j < 2; j++) {
-			amijoy_dev[i]->absmin[ABS_X + j] = -1;
-			amijoy_dev[i]->absmax[ABS_X + j] = 1;
+			input_abs_set_min(amijoy_dev[i], ABS_X + j, -1);
+			input_abs_set_max(amijoy_dev[i], ABS_X + j, 1);
 		}
 
 		err = input_register_device(amijoy_dev[i]);
drivers/input/joystick/gf2k.c +9 -7
index 45ac70e..b51ea20 100644
@@ -320,8 +320,8 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 	for (i = 0; i < gf2k_hats[gf2k->id]; i++) {
 		set_bit(ABS_HAT0X + i, input_dev->absbit);
-		input_dev->absmin[ABS_HAT0X + i] = -1;
-		input_dev->absmax[ABS_HAT0X + i] = 1;
+		input_abs_set_min(input_dev, ABS_HAT0X + i, -1);
+		input_abs_set_max(input_dev, ABS_HAT0X + i, 1);
 	}
 
 	for (i = 0; i < gf2k_joys[gf2k->id]; i++)
@@ -334,11 +334,13 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
 	gf2k_read(gf2k, data);
 
 	for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
-		input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 :
-			  input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32;
-		input_dev->absmin[gf2k_abs[i]] = 32;
-		input_dev->absfuzz[gf2k_abs[i]] = 8;
-		input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
+		int max = (i < 2) ?
+			input_abs(input_dev, gf2k_abs[i]) * 2 - 32 :
+			input_abs(input_dev, gf2k_abs[0]) +
+				input_abs(input_dev, gf2k_abs[1]) - 32;
+		int flat = (i < 2) ? 24 : 0;
+
+		input_set_abs_params(input_dev, gf2k_abs[i], 32, max, 8, flat);
 	}
 
 	err = input_register_device(gf2k->dev);
drivers/input/joystick/interact.c +4 -4
index 2478289..0d06cb9 100644
@@ -272,11 +272,11 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
 	for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
 		set_bit(t, input_dev->absbit);
 		if (i < interact_type[interact->type].b8) {
-			input_dev->absmin[t] = 0;
-			input_dev->absmax[t] = 255;
+			input_abs_set_min(input_dev, t, 0);
+			input_abs_set_max(input_dev, t, 255);
 		} else {
-			input_dev->absmin[t] = -1;
-			input_dev->absmax[t] = 1;
+			input_abs_set_min(input_dev, t, -1);
+			input_abs_set_max(input_dev, t, 1);
 		}
 	}
 
drivers/input/joystick/sidewinder.c +13 -5
index ca13a6b..76bdbc8 100644
@@ -761,13 +761,21 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
 		input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
 
 		for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
+			int min, max, fuzz, flat;
+
 			code = sw_abs[sw->type][j];
 			set_bit(code, input_dev->absbit);
-			input_dev->absmax[code] = (1 << bits) - 1;
-			input_dev->absmin[code] = (bits == 1) ? -1 : 0;
-			input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0;
-			if (code != ABS_THROTTLE)
-				input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0;
+
+			min = (bits == 1) ? -1 : 0;
+			max = (1 << bits) - 1;
+			fuzz = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0;
+
+			if (code == ABS_THROTTLE)
+				flat = input_abs_flat(input_dev, code);
+			else
+				flat = (bits >= 5) ? (1 << (bits - 5)) : 0;
+
+			input_set_abs_params(input_dev, code, min, max, fuzz, flat);
 		}
 
 		for (j = 0; (code = sw_btn[sw->type][j]); j++)
drivers/input/keyboard/hil_kbd.c +12 -9
index c83f4b2..dcc86b9 100644
@@ -232,15 +232,16 @@ static void hil_dev_handle_ptr_events(struct hil_dev *ptr)
 		if (absdev) {
 			val = lo + (hi << 8);
 #ifdef TABLET_AUTOADJUST
-			if (val < dev->absmin[ABS_X + i])
-				dev->absmin[ABS_X + i] = val;
-			if (val > dev->absmax[ABS_X + i])
-				dev->absmax[ABS_X + i] = val;
+			if (val < input_abs_min(dev, ABS_X + i))
+				input_abs_set_min(dev, ABS_X + i, val);
+			if (val > input_abs_max(dev, ABS_X + i))
+				input_abs_set_max(dev, ABS_X + i, val);
 #endif
-			if (i%3) val = dev->absmax[ABS_X + i] - val;
+			if (i % 3)
+				val = input_abs_max(dev, ABS_X + i) - val;
 			input_report_abs(dev, ABS_X + i, val);
 		} else {
-			val = (int) (((int8_t)lo) | ((int8_t)hi << 8));
+			val = (int) (((int8_t) lo) | ((int8_t) hi << 8));
 			if (i % 3)
 				val *= -1;
 			input_report_rel(dev, REL_X + i, val);
@@ -387,9 +388,11 @@ static void hil_dev_pointer_setup(struct hil_dev *ptr)
 
 #ifdef TABLET_AUTOADJUST
 		for (i = 0; i < ABS_MAX; i++) {
-			int diff = input_dev->absmax[ABS_X + i] / 10;
-			input_dev->absmin[ABS_X + i] += diff;
-			input_dev->absmax[ABS_X + i] -= diff;
+			int diff = input_abs_max(input_dev, ABS_X + i) / 10;
+			input_abs_set_min(input_dev, ABS_X + i,
+				input_abs_min(input_dev, ABS_X + i) + diff)
+			input_abs_set_max(input_dev, ABS_X + i,
+				input_abs_max(input_dev, ABS_X + i) - diff)
 		}
 #endif
 
drivers/input/misc/uinput.c +17 -12
index f3f03b7..988a855 100644
@@ -304,21 +304,25 @@ static int uinput_validate_absbits(struct input_dev *dev)
 		if (!test_bit(cnt, dev->absbit))
 			continue;
 
-		if ((dev->absmax[cnt] <= dev->absmin[cnt])) {
+		if (input_abs_max(dev, cnt) <= input_abs_min(dev, cnt)) {
 			printk(KERN_DEBUG
 				"%s: invalid abs[%02x] min:%d max:%d\n",
 				UINPUT_NAME, cnt,
-				dev->absmin[cnt], dev->absmax[cnt]);
+				input_abs_min(dev, cnt),
+				input_abs_max(dev, cnt));
 			retval = -EINVAL;
 			break;
 		}
 
-		if (dev->absflat[cnt] > (dev->absmax[cnt] - dev->absmin[cnt])) {
+		if (input_abs_flat(dev, cnt) >
+		    input_abs_max(dev, cnt) - input_abs_min(dev, cnt)) {
 			printk(KERN_DEBUG
-				"%s: absflat[%02x] out of range: %d "
+				"%s: abs_flat #%02x out of range: %d "
 				"(min:%d/max:%d)\n",
-				UINPUT_NAME, cnt, dev->absflat[cnt],
-				dev->absmin[cnt], dev->absmax[cnt]);
+				UINPUT_NAME, cnt,
+				input_abs_flat(dev, cnt),
+				input_abs_min(dev, cnt),
+				input_abs_max(dev, cnt));
 			retval = -EINVAL;
 			break;
 		}
@@ -343,7 +347,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
 	struct uinput_user_dev	*user_dev;
 	struct input_dev	*dev;
 	char			*name;
-	int			size;
+	int			i, size;
 	int			retval;
 
 	if (count != sizeof(struct uinput_user_dev))
@@ -387,11 +391,12 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
 	dev->id.product	= user_dev->id.product;
 	dev->id.version	= user_dev->id.version;
 
-	size = sizeof(int) * (ABS_CNT);
-	memcpy(dev->absmax, user_dev->absmax, size);
-	memcpy(dev->absmin, user_dev->absmin, size);
-	memcpy(dev->absfuzz, user_dev->absfuzz, size);
-	memcpy(dev->absflat, user_dev->absflat, size);
+	for (i = 0; i < ABS_CNT; i++) {
+		input_abs_set_max(dev, i, user_dev->absmax[i]);
+		input_abs_set_min(dev, i, user_dev->absmin[i]);
+		input_abs_set_fuzz(dev, i, user_dev->absfuzz[i]);
+		input_abs_set_flat(dev, i, user_dev->absflat[i]);
+	}
 
 	/* check if absmin/absmax/absfuzz/absflat are filled as
 	 * told in Documentation/input/input-programming.txt */
drivers/input/mouse/pc110pad.c +2 -2
index 3941f97..7b02b65 100644
@@ -145,8 +145,8 @@ static int __init pc110pad_init(void)
 	pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
 	pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
 
-	pc110pad_dev->absmax[ABS_X] = 0x1ff;
-	pc110pad_dev->absmax[ABS_Y] = 0x0ff;
+	input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
+	input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
 
 	pc110pad_dev->open = pc110pad_open;
 	pc110pad_dev->close = pc110pad_close;
drivers/input/mouse/synaptics.c +2 -2
index 026df60..28c3aab 100644
@@ -591,8 +591,8 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
 	__clear_bit(REL_X, dev->relbit);
 	__clear_bit(REL_Y, dev->relbit);
 
-	dev->absres[ABS_X] = priv->x_res;
-	dev->absres[ABS_Y] = priv->y_res;
+	input_abs_set_res(dev, ABS_X, priv->x_res);
+	input_abs_set_res(dev, ABS_Y, priv->y_res);
 }
 
 static void synaptics_disconnect(struct psmouse *psmouse)
drivers/input/mousedev.c +17 -23
index f34b22b..3a965a4 100644
@@ -22,6 +22,7 @@
 #include <linux/random.h>
 #include <linux/major.h>
 #include <linux/device.h>
+#include <linux/kernel.h>
 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
 #include <linux/miscdevice.h>
 #endif
@@ -128,17 +129,20 @@ static void mousedev_touchpad_event(struct input_dev *dev,
 				    struct mousedev *mousedev,
 				    unsigned int code, int value)
 {
-	int size, tmp;
 	enum { FRACTION_DENOM = 128 };
+	int tmp;
+
+	/* use X size for ABS_Y to keep the same scale */
+	int size = input_abs_max(dev, ABS_X) - input_abs_min(dev, ABS_X);
+
+	if (size == 0)
+		size = 256 * 2;
 
 	switch (code) {
 
 	case ABS_X:
 		fx(0) = value;
 		if (mousedev->touch && mousedev->pkt_count >= 2) {
-			size = dev->absmax[ABS_X] - dev->absmin[ABS_X];
-			if (size == 0)
-				size = 256 * 2;
 			tmp = ((value - fx(2)) * 256 * FRACTION_DENOM) / size;
 			tmp += mousedev->frac_dx;
 			mousedev->packet.dx = tmp / FRACTION_DENOM;
@@ -150,10 +154,6 @@ static void mousedev_touchpad_event(struct input_dev *dev,
 	case ABS_Y:
 		fy(0) = value;
 		if (mousedev->touch && mousedev->pkt_count >= 2) {
-			/* use X size to keep the same scale */
-			size = dev->absmax[ABS_X] - dev->absmin[ABS_X];
-			if (size == 0)
-				size = 256 * 2;
 			tmp = -((value - fy(2)) * 256 * FRACTION_DENOM) / size;
 			tmp += mousedev->frac_dy;
 			mousedev->packet.dy = tmp / FRACTION_DENOM;
@@ -167,33 +167,27 @@ static void mousedev_touchpad_event(struct input_dev *dev,
 static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev,
 				unsigned int code, int value)
 {
-	int size;
+	int min = input_abs_min(dev, code);
+	int max = input_abs_max(dev, code);
+	int size = max - min;
+
+	clamp(value, min, max);
 
 	switch (code) {
 
 	case ABS_X:
-		size = dev->absmax[ABS_X] - dev->absmin[ABS_X];
 		if (size == 0)
 			size = xres ? : 1;
-		if (value > dev->absmax[ABS_X])
-			value = dev->absmax[ABS_X];
-		if (value < dev->absmin[ABS_X])
-			value = dev->absmin[ABS_X];
-		mousedev->packet.x =
-			((value - dev->absmin[ABS_X]) * xres) / size;
+
+		mousedev->packet.x = ((value - min) * xres) / size;
 		mousedev->packet.abs_event = 1;
 		break;
 
 	case ABS_Y:
-		size = dev->absmax[ABS_Y] - dev->absmin[ABS_Y];
 		if (size == 0)
 			size = yres ? : 1;
-		if (value > dev->absmax[ABS_Y])
-			value = dev->absmax[ABS_Y];
-		if (value < dev->absmin[ABS_Y])
-			value = dev->absmin[ABS_Y];
-		mousedev->packet.y = yres -
-			((value - dev->absmin[ABS_Y]) * yres) / size;
+
+		mousedev->packet.y = yres - ((value - min) * yres) / size;
 		mousedev->packet.abs_event = 1;
 		break;
 	}
drivers/input/tablet/acecad.c +8 -8
index 670c61c..c4bc2d9 100644
@@ -203,9 +203,9 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
 
 	switch (id->driver_info) {
 		case 0:
-			input_dev->absmax[ABS_X] = 5000;
-			input_dev->absmax[ABS_Y] = 3750;
-			input_dev->absmax[ABS_PRESSURE] = 512;
+			input_abs_set_max(input_dev, ABS_X, 5000);
+			input_abs_set_max(input_dev, ABS_Y, 3750);
+			input_abs_set_max(input_dev, ABS_PRESSURE, 512);
 			if (!strlen(acecad->name))
 				snprintf(acecad->name, sizeof(acecad->name),
 					"USB Acecad Flair Tablet %04x:%04x",
@@ -213,9 +213,9 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
 					le16_to_cpu(dev->descriptor.idProduct));
 			break;
 		case 1:
-			input_dev->absmax[ABS_X] = 3000;
-			input_dev->absmax[ABS_Y] = 2250;
-			input_dev->absmax[ABS_PRESSURE] = 1024;
+			input_abs_set_max(input_dev, ABS_X, 3000);
+			input_abs_set_max(input_dev, ABS_Y, 2250);
+			input_abs_set_max(input_dev, ABS_PRESSURE, 1024);
 			if (!strlen(acecad->name))
 				snprintf(acecad->name, sizeof(acecad->name),
 					"USB Acecad 302 Tablet %04x:%04x",
@@ -224,8 +224,8 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
 			break;
 	}
 
-	input_dev->absfuzz[ABS_X] = 4;
-	input_dev->absfuzz[ABS_Y] = 4;
+	input_abs_set_fuzz(input_dev, ABS_X, 4);
+	input_abs_set_fuzz(input_dev, ABS_Y, 4);
 
 	usb_fill_int_urb(acecad->irq, dev, pipe,
 			acecad->data, maxp > 8 ? 8 : maxp,
drivers/input/tablet/aiptek.c +9 -9
index 4be039d..61ea977 100644
@@ -987,20 +987,20 @@ static int aiptek_program_tablet(struct aiptek *aiptek)
 	/* Query getXextension */
 	if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
 		return ret;
-	aiptek->inputdev->absmin[ABS_X] = 0;
-	aiptek->inputdev->absmax[ABS_X] = ret - 1;
+	input_abs_set_min(aiptek->inputdev, ABS_X, 0);
+	input_abs_set_max(aiptek->inputdev, ABS_X, ret - 1);
 
 	/* Query getYextension */
 	if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
 		return ret;
-	aiptek->inputdev->absmin[ABS_Y] = 0;
-	aiptek->inputdev->absmax[ABS_Y] = ret - 1;
+	input_abs_set_min(aiptek->inputdev, ABS_Y, 0);
+	input_abs_set_max(aiptek->inputdev, ABS_Y, ret - 1);
 
 	/* Query getPressureLevels */
 	if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
 		return ret;
-	aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
-	aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
+	input_abs_set_min(aiptek->inputdev, ABS_PRESSURE, 0);
+	input_abs_set_max(aiptek->inputdev, ABS_PRESSURE, ret - 1);
 
 	/* Depending on whether we are in absolute or relative mode, we will
 	 * do a switchToTablet(absolute) or switchToMouse(relative) command.
@@ -1054,8 +1054,8 @@ static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr
 	struct aiptek *aiptek = dev_get_drvdata(dev);
 
 	return snprintf(buf, PAGE_SIZE, "%dx%d\n",
-			aiptek->inputdev->absmax[ABS_X] + 1,
-			aiptek->inputdev->absmax[ABS_Y] + 1);
+			input_abs_max(aiptek->inputdev, ABS_X) + 1,
+			input_abs_max(aiptek->inputdev, ABS_Y) + 1);
 }
 
 /* These structs define the sysfs files, param #1 is the name of the
@@ -1843,7 +1843,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
 		aiptek->curSetting.programmableDelay = speeds[i];
 		(void)aiptek_program_tablet(aiptek);
-		if (aiptek->inputdev->absmax[ABS_X] > 0) {
+		if (input_abs_max(aiptek->inputdev, ABS_X) > 0) {
 			dev_info(&intf->dev,
 				 "Aiptek using %d ms programming speed\n",
 				 aiptek->curSetting.programmableDelay);
Signature · 1 line
1.7.1
#6 lore raw

Re: [4/4] input: dynamically allocate ABS information

In reply to Daniel Mack

Since the patches are fairly intrusive, it would be good to get a little bit of background in the patch description. How much memory is saved? What calls for doing this now? Any cpu cycle side effects?

Henrik

#7 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

In reply to Daniel Mack

Hi Dmitry,

any feelings about this approach?

Thanks,
Daniel

Quoted 200 lines · Daniel Mack

As all callers are now changed to only use the input_abs_*() access helpers, switching over to dynamically allocated ABS information is easy.

Cc Dmitry Torokhov <[email protected]>
---
 drivers/input/input.c |   26 ++++++++++++++++++++
 include/linux/input.h |   63 +++++++++++++++++++++++++++++++-----------------
 2 files changed, 67 insertions(+), 22 deletions(-)
drivers/input/input.c +26 -0
index 5bc92f6..ced6b39 100644
@@ -373,6 +373,25 @@ void input_inject_event(struct input_handle *handle,
 EXPORT_SYMBOL(input_inject_event);
 
 /**
+ * input_alloc_absinfo - allocates an input_absinfo struct
+ * @dev: the input device
+ * @axis: the ABS axis
+ *
+ * If the absinfo struct the caller asked for is already allocated, this
+ * functions will not do anything but return it.
+ */
+struct input_absinfo *input_alloc_absinfo(struct input_dev *dev, int axis)
+{
+	if (!dev->absinfo[axis])
+		dev->absinfo[axis] =
+			kzalloc(sizeof(struct input_absinfo), GFP_KERNEL);
+
+	WARN(!dev->absinfo[axis], "%s(): kzalloc() failed?\n", __func__);
+	return dev->absinfo[axis];
+}
+EXPORT_SYMBOL(input_alloc_absinfo);
+
+/**
  * input_grab_device - grabs device for exclusive use
  * @handle: input handle that wants to own the device
  *
@@ -1276,9 +1295,16 @@ static const struct attribute_group *input_dev_attr_groups[] = {
 
 static void input_dev_release(struct device *device)
 {
+	int i;
 	struct input_dev *dev = to_input_dev(device);
 
 	input_ff_destroy(dev);
+
+	for (i = 0; i < ABS_CNT; i++) {
+		kfree(dev->absinfo[i]);
+		dev->absinfo[i] = NULL;
+	}
+
 	kfree(dev);
 
 	module_put(THIS_MODULE);
include/linux/input.h +41 -22
index ff1ee6d..67650ab 100644
@@ -1154,7 +1154,6 @@ struct input_dev {
 
 	int sync;
 
-	int abs[ABS_CNT];
 	int rep[REP_MAX + 1];
 
 	unsigned long key[BITS_TO_LONGS(KEY_CNT)];
@@ -1162,11 +1161,7 @@ struct input_dev {
 	unsigned long snd[BITS_TO_LONGS(SND_CNT)];
 	unsigned long sw[BITS_TO_LONGS(SW_CNT)];
 
-	int absmax[ABS_CNT];
-	int absmin[ABS_CNT];
-	int absfuzz[ABS_CNT];
-	int absflat[ABS_CNT];
-	int absres[ABS_CNT];
+	struct input_absinfo *absinfo[ABS_CNT];
 
 	int (*open)(struct input_dev *dev);
 	void (*close)(struct input_dev *dev);
@@ -1190,62 +1185,82 @@ struct input_dev {
 
 static inline int input_abs(struct input_dev *dev, int axis)
 {
-	return dev->abs[axis];
+	struct input_absinfo *absinfo = dev->absinfo[axis];
+	return absinfo ? absinfo->value : 0;
 }
 
 static inline int input_abs_max(struct input_dev *dev, int axis)
 {
-	return dev->absmax[axis];
+	struct input_absinfo *absinfo = dev->absinfo[axis];
+	return absinfo ? absinfo->maximum : 0;
 }
 
 static inline int input_abs_min(struct input_dev *dev, int axis)
 {
-	return dev->absmin[axis];
+	struct input_absinfo *absinfo = dev->absinfo[axis];
+	return absinfo ? absinfo->minimum : 0;
 }
 
 static inline int input_abs_fuzz(struct input_dev *dev, int axis)
 {
-	return dev->absfuzz[axis];
+	struct input_absinfo *absinfo = dev->absinfo[axis];
+	return absinfo ? absinfo->fuzz : 0;
 }
 
 static inline int input_abs_flat(struct input_dev *dev, int axis)
 {
-	return dev->absflat[axis];
+	struct input_absinfo *absinfo = dev->absinfo[axis];
+	return absinfo ? absinfo->flat : 0;
 }
 
 static inline int input_abs_res(struct input_dev *dev, int axis)
 {
-	return dev->absres[axis];
+	struct input_absinfo *absinfo = dev->absinfo[axis];
+	return absinfo ? absinfo->resolution: 0;
 }
 
+struct input_absinfo *input_alloc_absinfo(struct input_dev *dev, int axis);
+
 static inline void input_abs_set(struct input_dev *dev, int axis, int val)
 {
-	dev->abs[axis] = val;
+	struct input_absinfo *absinfo = input_alloc_absinfo(dev, axis);
+	if (absinfo)
+		absinfo->value = val;
 }
 
 static inline void input_abs_set_max(struct input_dev *dev, int axis, int val)
 {
-	dev->absmax[axis] = val;
+	struct input_absinfo *absinfo = input_alloc_absinfo(dev, axis);
+	if (absinfo)
+		absinfo->maximum = val;
 }
 
 static inline void input_abs_set_min(struct input_dev *dev, int axis, int val)
 {
-	dev->absmin[axis] = val;
+	struct input_absinfo *absinfo = input_alloc_absinfo(dev, axis);
+	if (absinfo)
+		absinfo->minimum = val;
 }
 
 static inline void input_abs_set_fuzz(struct input_dev *dev, int axis, int val)
 {
-	dev->absfuzz[axis] = val;
+	struct input_absinfo *absinfo = input_alloc_absinfo(dev, axis);
+	if (absinfo)
+		absinfo->fuzz = val;
 }
 
 static inline void input_abs_set_flat(struct input_dev *dev, int axis, int val)
 {
-	dev->absflat[axis] = val;
+	struct input_absinfo *absinfo = input_alloc_absinfo(dev, axis);
+	if (absinfo)
+		absinfo->flat = val;
 }
 
 static inline void input_abs_set_res(struct input_dev *dev, int axis, int val)
 {
-	dev->absres[axis] = val;
+	struct input_absinfo *absinfo = input_alloc_absinfo(dev, axis);
+	if (absinfo)
+		absinfo->resolution = val;
 }
 
 /*
@@ -1469,10 +1484,14 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
 
 static inline void input_set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat)
 {
-	dev->absmin[axis] = min;
-	dev->absmax[axis] = max;
-	dev->absfuzz[axis] = fuzz;
-	dev->absflat[axis] = flat;
+	struct input_absinfo *absinfo = input_alloc_absinfo(dev, axis);
+	if (!absinfo)
+		return;
+
+	absinfo->minimum = min;
+	absinfo->maximum = max;
+	absinfo->fuzz = fuzz;
+	absinfo->flat = flat;
 
 	dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
 }
Signature · 1 line
1.7.1
maintainer
#8 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

Quoted 4 lines · Daniel Mack

Hi Dmitry,

any feelings about this approach?

Still pondering...I applied the very first patch though...

Thanks.

Signature · 1 line
Dmitry
#9 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

Hi Dmitry,

Quoted 5 lines · Dmitry Torokhov
Quoted 2 lines · Daniel Mack

any feelings about this approach?

Still pondering...I applied the very first patch though...

Any news about this? I have no problem throwing away the whole patch set and use a different approach, if there is any :)

And I need one, because I have a patch pending for a MIDI/Controller device which is something like a drum computer control device, and this one has more ABS information channels than currently supported by the input stack.

OTOH, the current plan is to use *axis* information for the transport to the user space, but in fact, their hardware representation is a pressure-sesitive button. Same counts for potentiometers etc, which aren't axis either. So maybe I should use some different layer for such devices? MIDI legacy after all? I'm open to any suggestions :)

Thanks,
Daniel

maintainer
#4 lore raw

Re: [PATCH 3/4] input: switch to input_abs_*() access functions

In reply to Daniel Mack

Hi Daniel,

drivers/input/joydev.c static int joydev_connect(struct input_handler *handler, struct input_dev *dev, · line 863

Quoted 12 lines · Daniel Mack
drivers/input/joydev.c +6 -5
 		joydev->corr[i].type = JS_CORR_BROKEN;
-		joydev->corr[i].prec = dev->absfuzz[j];
-		joydev->corr[i].coef[0] =
-			(dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j];
-		joydev->corr[i].coef[1] =
-			(dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j];
+		joydev->corr[i].prec = input_abs_fuzz(dev, j);
+
+		t = (input_abs_max(dev, j) + input_abs_min(dev, j)) / 2
+			- input_abs_flat(dev, j);
+		joydev->corr[i].coef[0] = t;
+		joydev->corr[i].coef[1] = t;

FYI: this is not equivalent transformation - note that original code either added or subtracted flat from the average to get coefficient.

Quoted 26 lines
drivers/input/mousedev.c +7 -4
@@ -128,17 +129,20 @@ static void mousedev_touchpad_event(struct input_dev *dev,
 				    struct mousedev *mousedev,
 				    unsigned int code, int value)
 {
-	int size, tmp;
 	enum { FRACTION_DENOM = 128 };
+	int tmp;
+
+	/* use X size for ABS_Y to keep the same scale */
+	int size = input_abs_max(dev, ABS_X) - input_abs_min(dev, ABS_X);
+
+	if (size == 0)
+		size = 256 * 2;
 
 	switch (code) {
 
 	case ABS_X:
 		fx(0) = value;
 		if (mousedev->touch && mousedev->pkt_count >= 2) {
-			size = dev->absmax[ABS_X] - dev->absmin[ABS_X];
-			if (size == 0)
-				size = 256 * 2;
 			tmp = ((value - fx(2)) * 256 * FRACTION_DENOM) / size;
 			tmp += mousedev->frac_dx;
 			mousedev->packet.dx = tmp / FRACTION_DENOM;

drivers/input/mousedev.c static void mousedev_touchpad_event(struct input_dev *dev, · line 156

Quoted 7 lines
drivers/input/mousedev.c +0 -4
@@ -150,10 +154,6 @@ static void mousedev_touchpad_event(struct input_dev *dev,
 	case ABS_Y:
 		fy(0) = value;
 		if (mousedev->touch && mousedev->pkt_count >= 2) {
-			/* use X size to keep the same scale */
-			size = dev->absmax[ABS_X] - dev->absmin[ABS_X];
-			if (size == 0)
-				size = 256 * 2;

The reason we had the repeating code blocks is that we don't do calculations for events we are not interested in. This especially important for multitouch devices generating lots of data.

I think I will keep it the way it was.

No need to resubmit, I am working on the patches...

Thanks.

Signature · 1 line
Dmitry
maintainer
#19 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

In reply to Daniel Mack
Quoted 9 lines · Daniel Mack

/**
+ * input_alloc_absinfo - allocates an input_absinfo struct
+ * @dev: the input device
+ * @axis: the ABS axis
+ *
+ * If the absinfo struct the caller asked for is already allocated, this
+ * functions will not do anything but return it.
+ */

drivers/input/input.c void input_inject_event(struct input_handle *handle, · line 390

Quoted 8 lines
drivers/input/input.c +8 -0
+struct input_absinfo *input_alloc_absinfo(struct input_dev *dev, int axis)
+{
+	if (!dev->absinfo[axis])
+		dev->absinfo[axis] =
+			kzalloc(sizeof(struct input_absinfo), GFP_KERNEL);
+
+	WARN(!dev->absinfo[axis], "%s(): kzalloc() failed?\n", __func__);
+	return dev->absinfo[axis];

This causes us to allocate every absinfo structure separately and use 64 additional pointers (256 bytes on 32 bit boxes and even more on 64 bit boxes). If device uses enough axis we end up eating up most savings.

I think we should simply alloctate ABS_CNT worth of absinfo first time we try to set up abs parameters and be done with it so we'll be saving space for devices not reporting absolute events.

Another optionw woudl be to allow drivers specify size of absinfo array but I am not sure if it worth it.

Thanks.

Signature · 1 line
Dmitry
maintainer
#10 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

In reply to Daniel Mack
Quoted 12 lines · Daniel Mack

Hi Dmitry,

Quoted 5 lines · Dmitry Torokhov
Quoted 2 lines · Daniel Mack

any feelings about this approach?

Still pondering...I applied the very first patch though...

Any news about this? I have no problem throwing away the whole patch set and use a different approach, if there is any :)

Daniel,

The approach is pretty solid, with the exception that I do not think we'd save much if we allocate every axis data separately (as I mentioned in one of my earlier mails).

Coudl you please take a look at the following patches and let me know if you see something wrong.

Thanks!

Signature · 17 lines
Dmitry


Input: add static inline accessors for ABS properties

From: Daniel Mack <[email protected]>

In preparation for dynamically allocated ABS axis, introduce a number of
sttaic inline access helpers. This should make the transition less
painful.

Signed-off-by: Daniel Mack <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---

 include/linux/input.h |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
include/linux/input.h +30 -0
index 339d043..4a55311 100644
@@ -1469,6 +1469,36 @@ static inline void input_set_abs_params(struct input_dev *dev, int axis, int min
 	dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
 }
 
+#define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)			\
+static inline int input_abs_get_##_suffix(struct input_dev *dev,	\
+					  unsigned int axis)		\
+{									\
+	return dev->abs##_item[axis];					\
+}									\
+									\
+static inline void input_abs_set_##_suffix(struct input_dev *dev,	\
+					   unsigned int axis, int val)	\
+{									\
+	dev->abs##_item[axis] = val;					\
+}
+
+INPUT_GENERATE_ABS_ACCESSORS(min, min)
+INPUT_GENERATE_ABS_ACCESSORS(max, max)
+INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz)
+INPUT_GENERATE_ABS_ACCESSORS(flat, flat)
+INPUT_GENERATE_ABS_ACCESSORS(res, res)
+
+static inline int input_abs_get_val(struct input_dev *dev, unsigned int axis)
+{
+	return dev->abs[axis];
+}
+
+static inline void input_abs_set_val(struct input_dev *dev,
+				     unsigned int axis, int val)
+{
+	dev->abs[axis] = val;
+}
+
 int input_get_keycode(struct input_dev *dev,
 		      unsigned int scancode, unsigned int *keycode);
 int input_set_keycode(struct input_dev *dev,
maintainer
#11 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

Input: switch to input_abs_*() access functions

From: Daniel Mack <[email protected]>

Change all call sites in drivers/input to not access the ABS axis information directly anymore. Make them use the access helpers instead.

Also use input_set_abs_params() when possible.
Did some code refactoring as I was on it.

---

 drivers/hid/hid-wacom.c             |   49 +++++++++++++++++------------------
 drivers/input/evdev.c               |   26 +++++++++----------
 drivers/input/input.c               |    4 +--
 drivers/input/joydev.c              |   31 +++++++++++-----------
 drivers/input/joystick/a3d.c        |    3 +-
 drivers/input/joystick/adi.c        |    2 +
 drivers/input/joystick/amijoy.c     |    4 +--
 drivers/input/joystick/gf2k.c       |   20 +++++++-------
 drivers/input/joystick/interact.c   |   14 ++++------
 drivers/input/joystick/sidewinder.c |   18 ++++++++-----
 drivers/input/keyboard/hil_kbd.c    |   21 +++++++++------
 drivers/input/misc/uinput.c         |   29 ++++++++++++---------
 drivers/input/mouse/pc110pad.c      |    4 +--
 drivers/input/mouse/synaptics.c     |    4 +--
 drivers/input/mousedev.c            |   44 +++++++++++++++++++------------
 drivers/input/tablet/aiptek.c       |   15 ++++-------
 drivers/input/tablet/wacom_wac.c    |    4 +--
 17 files changed, 153 insertions(+), 139 deletions(-)
drivers/hid/hid-wacom.c +24 -25
index 1e051f1..1c4b4ca 100644
@@ -230,7 +230,7 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
 				input_report_key(input, BTN_RIGHT, 0);
 				input_report_key(input, BTN_MIDDLE, 0);
 				input_report_abs(input, ABS_DISTANCE,
-						input->absmax[ABS_DISTANCE]);
+					input_abs_get_max(input, ABS_DISTANCE));
 			} else {
 				input_report_key(input, BTN_TOUCH, 0);
 				input_report_key(input, BTN_STYLUS, 0);
@@ -383,38 +383,37 @@ move_on:
 
 	/* Basics */
 	input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
-	input->absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) |
-		BIT(ABS_PRESSURE) | BIT(ABS_DISTANCE);
-	input->relbit[0] |= BIT(REL_WHEEL);
-	set_bit(BTN_TOOL_PEN, input->keybit);
-	set_bit(BTN_TOUCH, input->keybit);
-	set_bit(BTN_STYLUS, input->keybit);
-	set_bit(BTN_STYLUS2, input->keybit);
-	set_bit(BTN_LEFT, input->keybit);
-	set_bit(BTN_RIGHT, input->keybit);
-	set_bit(BTN_MIDDLE, input->keybit);
+
+	__set_bit(REL_WHEEL, input->relbit);
+
+	__set_bit(BTN_TOOL_PEN, input->keybit);
+	__set_bit(BTN_TOUCH, input->keybit);
+	__set_bit(BTN_STYLUS, input->keybit);
+	__set_bit(BTN_STYLUS2, input->keybit);
+	__set_bit(BTN_LEFT, input->keybit);
+	__set_bit(BTN_RIGHT, input->keybit);
+	__set_bit(BTN_MIDDLE, input->keybit);
 
 	/* Pad */
 	input->evbit[0] |= BIT(EV_MSC);
-	input->mscbit[0] |= BIT(MSC_SERIAL);
-	set_bit(BTN_0, input->keybit);
-	set_bit(BTN_1, input->keybit);
-	set_bit(BTN_TOOL_FINGER, input->keybit);
 
-	/* Distance, rubber and mouse */
-	input->absbit[0] |= BIT(ABS_DISTANCE);
-	set_bit(BTN_TOOL_RUBBER, input->keybit);
-	set_bit(BTN_TOOL_MOUSE, input->keybit);
+	__set_bit(MSC_SERIAL, input->mscbit);
 
-	input->absmax[ABS_PRESSURE] = 511;
-	input->absmax[ABS_DISTANCE] = 32;
+	__set_bit(BTN_0, input->keybit);
+	__set_bit(BTN_1, input->keybit);
+	__set_bit(BTN_TOOL_FINGER, input->keybit);
 
-	input->absmax[ABS_X] = 16704;
-	input->absmax[ABS_Y] = 12064;
-	input->absfuzz[ABS_X] = 4;
-	input->absfuzz[ABS_Y] = 4;
+	/* Distance, rubber and mouse */
+	__set_bit(BTN_TOOL_RUBBER, input->keybit);
+	__set_bit(BTN_TOOL_MOUSE, input->keybit);
+
+	input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
+	input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
+	input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
+	input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
 
 	return 0;
+
 err_free:
 	kfree(wdata);
 	return ret;
drivers/input/evdev.c +13 -13
index 054edf3..9807c8f 100644
@@ -650,12 +650,12 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 
 				t = _IOC_NR(cmd) & ABS_MAX;
 
-				abs.value = dev->abs[t];
-				abs.minimum = dev->absmin[t];
-				abs.maximum = dev->absmax[t];
-				abs.fuzz = dev->absfuzz[t];
-				abs.flat = dev->absflat[t];
-				abs.resolution = dev->absres[t];
+				abs.value = input_abs_get_val(dev, t);
+				abs.minimum = input_abs_get_min(dev, t);
+				abs.maximum = input_abs_get_max(dev, t);
+				abs.fuzz = input_abs_get_fuzz(dev, t);
+				abs.flat = input_abs_get_flat(dev, t);
+				abs.resolution = input_abs_get_res(dev, t);
 
 				if (copy_to_user(p, &abs, min_t(size_t,
 								_IOC_SIZE(cmd),
@@ -702,13 +702,13 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 				 */
 				spin_lock_irq(&dev->event_lock);
 
-				dev->abs[t] = abs.value;
-				dev->absmin[t] = abs.minimum;
-				dev->absmax[t] = abs.maximum;
-				dev->absfuzz[t] = abs.fuzz;
-				dev->absflat[t] = abs.flat;
-				dev->absres[t] = _IOC_SIZE(cmd) < sizeof(struct input_absinfo) ?
-							0 : abs.resolution;
+				input_abs_set_val(dev, t, abs.value);
+				input_abs_set_min(dev, t, abs.minimum);
+				input_abs_set_max(dev, t, abs.maximum);
+				input_abs_set_fuzz(dev, t, abs.fuzz);
+				input_abs_set_flat(dev, t, abs.flat);
+				input_abs_set_res(dev, t, _IOC_SIZE(cmd) < sizeof(struct input_absinfo) ?
+								0 : abs.resolution);
 
 				spin_unlock_irq(&dev->event_lock);
 
drivers/input/input.c +2 -2
index e1243b4..7259adb 100644
@@ -204,8 +204,8 @@ static int input_handle_abs_event(struct input_dev *dev,
 	}
 
 	/* Flush pending "slot" event */
-	if (is_mt_event && dev->slot != dev->abs[ABS_MT_SLOT]) {
-		dev->abs[ABS_MT_SLOT] = dev->slot;
+	if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
+		input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
 		input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot);
 	}
 
drivers/input/joydev.c +16 -15
index 6383458..d85bd8a 100644
@@ -530,7 +530,7 @@ static int joydev_ioctl_common(struct joydev *joydev,
 {
 	struct input_dev *dev = joydev->handle.dev;
 	size_t len;
-	int i, j;
+	int i;
 	const char *name;
 
 	/* Process fixed-sized commands. */
@@ -562,12 +562,11 @@ static int joydev_ioctl_common(struct joydev *joydev,
 	case JSIOCSCORR:
 		if (copy_from_user(joydev->corr, argp,
 			      sizeof(joydev->corr[0]) * joydev->nabs))
-		    return -EFAULT;
+			return -EFAULT;
 
 		for (i = 0; i < joydev->nabs; i++) {
-			j = joydev->abspam[i];
-			joydev->abs[i] = joydev_correct(dev->abs[j],
-							&joydev->corr[i]);
+			int val = input_abs_get_val(dev, joydev->abspam[i]);
+			joydev->abs[i] = joydev_correct(val, &joydev->corr[i]);
 		}
 		return 0;
 
@@ -848,25 +847,27 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
 
 	for (i = 0; i < joydev->nabs; i++) {
 		j = joydev->abspam[i];
-		if (dev->absmax[j] == dev->absmin[j]) {
+		if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) {
 			joydev->corr[i].type = JS_CORR_NONE;
-			joydev->abs[i] = dev->abs[j];
+			joydev->abs[i] = input_abs_get_val(dev, j);
 			continue;
 		}
 		joydev->corr[i].type = JS_CORR_BROKEN;
-		joydev->corr[i].prec = dev->absfuzz[j];
-		joydev->corr[i].coef[0] =
-			(dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j];
-		joydev->corr[i].coef[1] =
-			(dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j];
+		joydev->corr[i].prec = input_abs_get_fuzz(dev, j);
+
+		t = (input_abs_get_max(dev, j) + input_abs_get_min(dev, j)) / 2;
+		joydev->corr[i].coef[0] = t - input_abs_get_flat(dev, j);
+		joydev->corr[i].coef[1] = t + input_abs_get_flat(dev, j);
 
-		t = (dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j];
+		t = (input_abs_get_max(dev, j) - input_abs_get_min(dev, j)) / 2
+			- 2 * input_abs_get_flat(dev, j);
 		if (t) {
 			joydev->corr[i].coef[2] = (1 << 29) / t;
 			joydev->corr[i].coef[3] = (1 << 29) / t;
 
-			joydev->abs[i] = joydev_correct(dev->abs[j],
-							joydev->corr + i);
+			joydev->abs[i] =
+				joydev_correct(input_abs_get_val(dev, j),
+					       joydev->corr + i);
 		}
 	}
 
drivers/input/joystick/a3d.c +2 -1
index 6489f40..d259b41 100644
@@ -342,7 +342,8 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 		for (i = 0; i < 4; i++) {
 			if (i < 2)
-				input_set_abs_params(input_dev, axes[i], 48, input_dev->abs[axes[i]] * 2 - 48, 0, 8);
+				input_set_abs_params(input_dev, axes[i],
+					48, input_abs_get_val(input_dev, axes[i]) * 2 - 48, 0, 8);
 			else
 				input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0);
 			input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
drivers/input/joystick/adi.c +1 -1
index 89c4c08..b992fbf 100644
@@ -452,7 +452,7 @@ static void adi_init_center(struct adi *adi)
 	for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
 
 		t = adi->abs[i];
-		x = adi->dev->abs[t];
+		x = input_abs_get_val(adi->dev, t);
 
 		if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
 			x = i < adi->axes10 ? 512 : 128;
drivers/input/joystick/amijoy.c +2 -2
index 05022f0..e90694f 100644
@@ -139,8 +139,8 @@ static int __init amijoy_init(void)
 		amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
 			BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
 		for (j = 0; j < 2; j++) {
-			amijoy_dev[i]->absmin[ABS_X + j] = -1;
-			amijoy_dev[i]->absmax[ABS_X + j] = 1;
+			XXinput_set_abs_params(amijoy_dev[i], ABS_X + j,
+					     -1, 1, 0, 0);
 		}
 
 		err = input_register_device(amijoy_dev[i]);
drivers/input/joystick/gf2k.c +10 -10
index 45ac70e..0536b1b 100644
@@ -318,11 +318,8 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
 	for (i = 0; i < gf2k_axes[gf2k->id]; i++)
 		set_bit(gf2k_abs[i], input_dev->absbit);
 
-	for (i = 0; i < gf2k_hats[gf2k->id]; i++) {
-		set_bit(ABS_HAT0X + i, input_dev->absbit);
-		input_dev->absmin[ABS_HAT0X + i] = -1;
-		input_dev->absmax[ABS_HAT0X + i] = 1;
-	}
+	for (i = 0; i < gf2k_hats[gf2k->id]; i++)
+		input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
 
 	for (i = 0; i < gf2k_joys[gf2k->id]; i++)
 		set_bit(gf2k_btn_joy[i], input_dev->keybit);
@@ -334,11 +331,14 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
 	gf2k_read(gf2k, data);
 
 	for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
-		input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 :
-			  input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32;
-		input_dev->absmin[gf2k_abs[i]] = 32;
-		input_dev->absfuzz[gf2k_abs[i]] = 8;
-		input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
+		int max = i < 2 ?
+			input_abs_get_val(input_dev, gf2k_abs[i]) * 2 :
+			input_abs_get_val(input_dev, gf2k_abs[0]) +
+				input_abs_get_val(input_dev, gf2k_abs[1]);
+		int flat = i < 2 ? 24 : 0;
+
+		input_set_abs_params(input_dev, gf2k_abs[i],
+				     32, max - 32, 8, flat);
 	}
 
 	err = input_register_device(gf2k->dev);
drivers/input/joystick/interact.c +5 -9
index 2478289..16fb19d 100644
@@ -270,18 +270,14 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
 
 	for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
-		set_bit(t, input_dev->absbit);
-		if (i < interact_type[interact->type].b8) {
-			input_dev->absmin[t] = 0;
-			input_dev->absmax[t] = 255;
-		} else {
-			input_dev->absmin[t] = -1;
-			input_dev->absmax[t] = 1;
-		}
+		if (i < interact_type[interact->type].b8)
+			input_set_abs_params(input_dev, t, 0, 255, 0, 0);
+		else
+			input_set_abs_params(input_dev, t, -1, 1, 0, 0);
 	}
 
 	for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
-		set_bit(t, input_dev->keybit);
+		__set_bit(t, input_dev->keybit);
 
 	err = input_register_device(interact->dev);
 	if (err)
drivers/input/joystick/sidewinder.c +11 -7
index ca13a6b..b8d8611 100644
@@ -761,17 +761,21 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
 		input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
 
 		for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
+			int min, max, fuzz, flat;
+
 			code = sw_abs[sw->type][j];
-			set_bit(code, input_dev->absbit);
-			input_dev->absmax[code] = (1 << bits) - 1;
-			input_dev->absmin[code] = (bits == 1) ? -1 : 0;
-			input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0;
-			if (code != ABS_THROTTLE)
-				input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0;
+			min = bits == 1 ? -1 : 0;
+			max = (1 << bits) - 1;
+			fuzz = (bits >> 1) >= 2 ? 1 << ((bits >> 1) - 2) : 0;
+			flat = code == ABS_THROTTLE || bits < 5 ?
+				0 : 1 << (bits - 5);
+
+			input_set_abs_params(input_dev, code,
+					     min, max, fuzz, flat);
 		}
 
 		for (j = 0; (code = sw_btn[sw->type][j]); j++)
-			set_bit(code, input_dev->keybit);
+			__set_bit(code, input_dev->keybit);
 
 		dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
 
drivers/input/keyboard/hil_kbd.c +12 -9
index c83f4b2..ddd5afd 100644
@@ -232,15 +232,16 @@ static void hil_dev_handle_ptr_events(struct hil_dev *ptr)
 		if (absdev) {
 			val = lo + (hi << 8);
 #ifdef TABLET_AUTOADJUST
-			if (val < dev->absmin[ABS_X + i])
-				dev->absmin[ABS_X + i] = val;
-			if (val > dev->absmax[ABS_X + i])
-				dev->absmax[ABS_X + i] = val;
+			if (val < input_abs_min(dev, ABS_X + i))
+				input_abs_set_min(dev, ABS_X + i, val);
+			if (val > input_abs_max(dev, ABS_X + i))
+				XXinput_abs_set_max(dev, ABS_X + i, val);
 #endif
-			if (i%3) val = dev->absmax[ABS_X + i] - val;
+			if (i % 3)
+				val = input_abs_max(dev, ABS_X + i) - val;
 			input_report_abs(dev, ABS_X + i, val);
 		} else {
-			val = (int) (((int8_t)lo) | ((int8_t)hi << 8));
+			val = (int) (((int8_t) lo) | ((int8_t) hi << 8));
 			if (i % 3)
 				val *= -1;
 			input_report_rel(dev, REL_X + i, val);
@@ -387,9 +388,11 @@ static void hil_dev_pointer_setup(struct hil_dev *ptr)
 
 #ifdef TABLET_AUTOADJUST
 		for (i = 0; i < ABS_MAX; i++) {
-			int diff = input_dev->absmax[ABS_X + i] / 10;
-			input_dev->absmin[ABS_X + i] += diff;
-			input_dev->absmax[ABS_X + i] -= diff;
+			int diff = input_abs_max(input_dev, ABS_X + i) / 10;
+			input_abs_set_min(input_dev, ABS_X + i,
+				input_abs_min(input_dev, ABS_X + i) + diff)
+			XXinput_abs_set_max(input_dev, ABS_X + i,
+				input_abs_max(input_dev, ABS_X + i) - diff)
 		}
 #endif
 
drivers/input/misc/uinput.c +17 -12
index b71eb55..bb53fd3 100644
@@ -304,21 +304,25 @@ static int uinput_validate_absbits(struct input_dev *dev)
 		if (!test_bit(cnt, dev->absbit))
 			continue;
 
-		if ((dev->absmax[cnt] <= dev->absmin[cnt])) {
+		if (input_abs_get_max(dev, cnt) <= input_abs_get_min(dev, cnt)) {
 			printk(KERN_DEBUG
 				"%s: invalid abs[%02x] min:%d max:%d\n",
 				UINPUT_NAME, cnt,
-				dev->absmin[cnt], dev->absmax[cnt]);
+				input_abs_get_min(dev, cnt),
+				input_abs_get_max(dev, cnt));
 			retval = -EINVAL;
 			break;
 		}
 
-		if (dev->absflat[cnt] > (dev->absmax[cnt] - dev->absmin[cnt])) {
+		if (input_abs_get_flat(dev, cnt) >
+		    input_abs_get_max(dev, cnt) - input_abs_get_min(dev, cnt)) {
 			printk(KERN_DEBUG
-				"%s: absflat[%02x] out of range: %d "
+				"%s: abs_flat #%02x out of range: %d "
 				"(min:%d/max:%d)\n",
-				UINPUT_NAME, cnt, dev->absflat[cnt],
-				dev->absmin[cnt], dev->absmax[cnt]);
+				UINPUT_NAME, cnt,
+				input_abs_get_flat(dev, cnt),
+				input_abs_get_min(dev, cnt),
+				input_abs_get_max(dev, cnt));
 			retval = -EINVAL;
 			break;
 		}
@@ -343,7 +347,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
 	struct uinput_user_dev	*user_dev;
 	struct input_dev	*dev;
 	char			*name;
-	int			size;
+	int			i, size;
 	int			retval;
 
 	if (count != sizeof(struct uinput_user_dev))
@@ -387,11 +391,12 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
 	dev->id.product	= user_dev->id.product;
 	dev->id.version	= user_dev->id.version;
 
-	size = sizeof(int) * ABS_CNT;
-	memcpy(dev->absmax, user_dev->absmax, size);
-	memcpy(dev->absmin, user_dev->absmin, size);
-	memcpy(dev->absfuzz, user_dev->absfuzz, size);
-	memcpy(dev->absflat, user_dev->absflat, size);
+	for (i = 0; i < ABS_CNT; i++) {
+		input_abs_set_max(dev, i, user_dev->absmax[i]);
+		input_abs_set_min(dev, i, user_dev->absmin[i]);
+		input_abs_set_fuzz(dev, i, user_dev->absfuzz[i]);
+		input_abs_set_flat(dev, i, user_dev->absflat[i]);
+	}
 
 	/* check if absmin/absmax/absfuzz/absflat are filled as
 	 * told in Documentation/input/input-programming.txt */
drivers/input/mouse/pc110pad.c +2 -2
index 3941f97..7b02b65 100644
@@ -145,8 +145,8 @@ static int __init pc110pad_init(void)
 	pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
 	pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
 
-	pc110pad_dev->absmax[ABS_X] = 0x1ff;
-	pc110pad_dev->absmax[ABS_Y] = 0x0ff;
+	input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
+	input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
 
 	pc110pad_dev->open = pc110pad_open;
 	pc110pad_dev->close = pc110pad_close;
drivers/input/mouse/synaptics.c +2 -2
index b980d8b..9ce607e 100644
@@ -630,8 +630,8 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
 	__clear_bit(REL_X, dev->relbit);
 	__clear_bit(REL_Y, dev->relbit);
 
-	dev->absres[ABS_X] = priv->x_res;
-	dev->absres[ABS_Y] = priv->y_res;
+	input_abs_set_res(dev, ABS_X, priv->x_res);
+	input_abs_set_res(dev, ABS_Y, priv->y_res);
 
 	if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
 		/* Clickpads report only left button */
drivers/input/mousedev.c +26 -18

86 lines not on this page · raw message

drivers/input/tablet/aiptek.c +6 -9
index 51b80b0..57b25b8 100644
@@ -987,20 +987,17 @@ static int aiptek_program_tablet(struct aiptek *aiptek)
 	/* Query getXextension */
 	if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
 		return ret;
-	aiptek->inputdev->absmin[ABS_X] = 0;
-	aiptek->inputdev->absmax[ABS_X] = ret - 1;
+	input_set_abs_params(aiptek->inputdev, ABS_X, 0, ret - 1, 0, 0);
 
 	/* Query getYextension */
 	if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
 		return ret;
-	aiptek->inputdev->absmin[ABS_Y] = 0;
-	aiptek->inputdev->absmax[ABS_Y] = ret - 1;
+	input_set_abs_params(aiptek->inputdev, ABS_Y, 0, ret - 1, 0, 0);
 
 	/* Query getPressureLevels */
 	if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
 		return ret;
-	aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
-	aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
+	input_set_abs_params(aiptek->inputdev, ABS_PRESSURE, 0, ret - 1, 0, 0);
 
 	/* Depending on whether we are in absolute or relative mode, we will
 	 * do a switchToTablet(absolute) or switchToMouse(relative) command.
@@ -1054,8 +1051,8 @@ static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr
 	struct aiptek *aiptek = dev_get_drvdata(dev);
 
 	return snprintf(buf, PAGE_SIZE, "%dx%d\n",
-			aiptek->inputdev->absmax[ABS_X] + 1,
-			aiptek->inputdev->absmax[ABS_Y] + 1);
+			input_abs_get_max(aiptek->inputdev, ABS_X) + 1,
+			input_abs_get_max(aiptek->inputdev, ABS_Y) + 1);
 }
 
 /* These structs define the sysfs files, param #1 is the name of the
@@ -1843,7 +1840,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
 		aiptek->curSetting.programmableDelay = speeds[i];
 		(void)aiptek_program_tablet(aiptek);
-		if (aiptek->inputdev->absmax[ABS_X] > 0) {
+		if (input_abs_get_max(aiptek->inputdev, ABS_X) > 0) {
 			dev_info(&intf->dev,
 				 "Aiptek using %d ms programming speed\n",
 				 aiptek->curSetting.programmableDelay);
drivers/input/tablet/wacom_wac.c +2 -2
index ce0b460..40d77ba 100644
@@ -687,10 +687,10 @@ static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx)
 	 * protocol.
 	 */
 	if (wacom->last_finger != finger) {
-		if (x == input->abs[ABS_X])
+		if (x == input_abs_get_val(input, ABS_X))
 			x++;
 
-		if (y == input->abs[ABS_Y])
+		if (y == input_abs_get_val(input, ABS_Y))
 			y++;
 	}
 
maintainer
#12 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

Input: dynamically allocate ABS information

From: Daniel Mack <[email protected]>

As all callers are now changed to only use the input_abs_*() access helpers, switching over to dynamically allocated ABS information is easy.

---

 drivers/input/evdev.c |   13 +++--------
 drivers/input/input.c |   42 ++++++++++++++++++++++++++++++++++--
 include/linux/input.h |   57 +++++++++++++++----------------------------------
 3 files changed, 62 insertions(+), 50 deletions(-)
drivers/input/evdev.c +4 -9
index 9807c8f..251f142 100644
@@ -691,6 +691,9 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 								  sizeof(struct input_absinfo))))
 					return -EFAULT;
 
+				if (_IOC_SIZE(cmd) < sizeof(struct input_absinfo))
+					abs.resolution = 0;
+
 				/* We can't change number of reserved MT slots */
 				if (t == ABS_MT_SLOT)
 					return -EINVAL;
@@ -701,15 +704,7 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 				 * of event.
 				 */
 				spin_lock_irq(&dev->event_lock);
-
-				input_abs_set_val(dev, t, abs.value);
-				input_abs_set_min(dev, t, abs.minimum);
-				input_abs_set_max(dev, t, abs.maximum);
-				input_abs_set_fuzz(dev, t, abs.fuzz);
-				input_abs_set_flat(dev, t, abs.flat);
-				input_abs_set_res(dev, t, _IOC_SIZE(cmd) < sizeof(struct input_absinfo) ?
-								0 : abs.resolution);
-
+				dev->absinfo[t] = abs;
 				spin_unlock_irq(&dev->event_lock);
 
 				return 0;
drivers/input/input.c +40 -2

66 lines not on this page · raw message

include/linux/input.h +18 -39

114 lines not on this page · raw message

#13 lore raw

RE: [PATCH 4/4] input: dynamically allocate ABS information

A tiny tiny nit...

From: Dmitry Torokhov [[email protected]]
...
+void input_alloc_absinfo(struct input_dev *dev)
+{
+ if (!dev->absinfo)
+ dev->absinfo = kcalloc(ABS_CNT, sizeof(struct input_absinfo),
+ GFP_KERNEL);
+
+ WARN(!dev->absinfo, "%s(): kzalloc() failed?\n", __func__);

kcalloc failed, not kzalloc.

Phil

#14 lore raw

RE: [PATCH 4/4] input: dynamically allocate ABS information

Quoted 12 lines · On Wed, 2010-07-21 at 11:22 +0200, [email protected] wrote:

A tiny tiny nit...

From: Dmitry Torokhov [[email protected]]
...

drivers/input/input.c +7 -0
+void input_alloc_absinfo(struct input_dev *dev)
+{
+       if (!dev->absinfo)
+               dev->absinfo = kcalloc(ABS_CNT, sizeof(struct input_absinfo),
+                                       GFP_KERNEL);
+
+       WARN(!dev->absinfo, "%s(): kzalloc() failed?\n", __func__);
Quoted 1 line

kcalloc failed, not kzalloc.

kmalloc and friends already print a warning with a stack dump when they fail, unless this is overrided with __GFP_NOWARN, which is not the case here. So in usually we do not print messages/warnigns when we fail to allocate.

Signature · 7 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

In reply to Dmitry Torokhov

Hi Dmitry,

sorry for the late reply on this, I guess I haven't been much help around here lately.

Quoted 3 lines · Dmitry Torokhov

The approach is pretty solid, with the exception that I do not think we'd save much if we allocate every axis data separately (as I mentioned in one of my earlier mails).

Agreed. We at least save the memory for all input devices that don't have absolute axis at all.

Quoted 2 lines

Coudl you please take a look at the following patches and let me know if you see something wrong.

I checked the patches and tried them locally on my desktop, and I can't see any breakage, but we might need more coverage for testing.

Will you push them to the .36 merge window or is it too late for this?

Many thanks for your help :)

Daniel

maintainer
#18 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

Quoted 13 lines · Daniel Mack

Hi Dmitry,

sorry for the late reply on this, I guess I haven't been much help around here lately.

Quoted 3 lines · Dmitry Torokhov

The approach is pretty solid, with the exception that I do not think we'd save much if we allocate every axis data separately (as I mentioned in one of my earlier mails).

Agreed. We at least save the memory for all input devices that don't have absolute axis at all.

Quoted 8 lines
Quoted 2 lines

Coudl you please take a look at the following patches and let me know if you see something wrong.

I checked the patches and tried them locally on my desktop, and I can't see any breakage, but we might need more coverage for testing.

Will you push them to the .36 merge window or is it too late for this?

Yep, it in mainline now. Thank you for working on this.

-
Dmitry

#15 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 7 lines · Dmitry Torokhov

Input: switch to input_abs_*() access functions

From: Daniel Mack <[email protected]>

Change all call sites in drivers/input to not access the ABS axis information directly anymore. Make them use the access helpers instead.

Quoted 6 lines

Also use input_set_abs_params() when possible.
Did some code refactoring as I was on it.

Hmm, there are three locations where some mysterious 'XX' characters were introduced.

drivers/input/joystick/amijoy.c static int __init amijoy_init(void) · line 142

Quoted 11 lines
drivers/input/joystick/amijoy.c +1 -2
index 05022f0..e90694f 100644
@@ -139,8 +139,8 @@ static int __init amijoy_init(void)
 		amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
 			BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
 		for (j = 0; j < 2; j++) {
-			amijoy_dev[i]->absmin[ABS_X + j] = -1;
-			amijoy_dev[i]->absmax[ABS_X + j] = 1;
+			XXinput_set_abs_params(amijoy_dev[i], ABS_X + j,
                        ^^

[..]

Quoted 6 lines
drivers/input/keyboard/hil_kbd.c +0 -0
index c83f4b2..ddd5afd 100644
@@ -232,15 +232,16 @@ static void hil_dev_handle_ptr_events(struct hil_dev *ptr)
 		if (absdev) {

drivers/input/keyboard/hil_kbd.c static void hil_dev_handle_ptr_events(struct hil_dev *ptr) · line 238

Quoted 10 lines
drivers/input/keyboard/hil_kbd.c +4 -4
 			val = lo + (hi << 8);
 #ifdef TABLET_AUTOADJUST
-			if (val < dev->absmin[ABS_X + i])
-				dev->absmin[ABS_X + i] = val;
-			if (val > dev->absmax[ABS_X + i])
-				dev->absmax[ABS_X + i] = val;
+			if (val < input_abs_min(dev, ABS_X + i))
+				input_abs_set_min(dev, ABS_X + i, val);
+			if (val > input_abs_max(dev, ABS_X + i))
+				XXinput_abs_set_max(dev, ABS_X + i, val);
                                ^^
Quoted 12 lines
drivers/input/keyboard/hil_kbd.c +3 -2
 #endif
-			if (i%3) val = dev->absmax[ABS_X + i] - val;
+			if (i % 3)
+				val = input_abs_max(dev, ABS_X + i) - val;
 			input_report_abs(dev, ABS_X + i, val);
 		} else {
-			val = (int) (((int8_t)lo) | ((int8_t)hi << 8));
+			val = (int) (((int8_t) lo) | ((int8_t) hi << 8));
 			if (i % 3)
 				val *= -1;
 			input_report_rel(dev, REL_X + i, val);

drivers/input/keyboard/hil_kbd.c static void hil_dev_pointer_setup(struct hil_dev *ptr) · line 394

Quoted 10 lines
drivers/input/keyboard/hil_kbd.c +4 -3
@@ -387,9 +388,11 @@ static void hil_dev_pointer_setup(struct hil_dev *ptr)
 
 #ifdef TABLET_AUTOADJUST
 		for (i = 0; i < ABS_MAX; i++) {
-			int diff = input_dev->absmax[ABS_X + i] / 10;
-			input_dev->absmin[ABS_X + i] += diff;
-			input_dev->absmax[ABS_X + i] -= diff;
+			int diff = input_abs_max(input_dev, ABS_X + i) / 10;
+			input_abs_set_min(input_dev, ABS_X + i,
+				input_abs_min(input_dev, ABS_X + i) + diff)
+			XXinput_abs_set_max(input_dev, ABS_X + i,
                        ^^

I have no clue how they made it there, but they don't look right, unless I miss some essential information.

Below is a patch to fix it up.

Thanks,
Daniel

Quoted 1 line

From 939d842964c8fd764a84702672be927a79d73e8f Mon Sep 17 00:00:00 2001

From: Daniel Mack <[email protected]>
Date: Wed, 11 Aug 2010 08:59:53 +0200
Subject: [PATCH] drivers/input: fix faulty XXinput_* calls

They've been introduced by 987a6c02 ("Input: switch to input_abs_*() access functions") and they appear to be some kind of debug left-over.

Cc Dmitry Torokhov <[email protected]>
---
 drivers/input/joystick/amijoy.c  |    2 +-
 drivers/input/keyboard/hil_kbd.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/input/joystick/amijoy.c +1 -1
index e90694f..0bc8620 100644
@@ -139,7 +139,7 @@ static int __init amijoy_init(void)
 		amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
 			BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
 		for (j = 0; j < 2; j++) {
-			XXinput_set_abs_params(amijoy_dev[i], ABS_X + j,
+			input_set_abs_params(amijoy_dev[i], ABS_X + j,
 					     -1, 1, 0, 0);
 		}
 
drivers/input/keyboard/hil_kbd.c +2 -2
index ddd5afd..dcc86b9 100644
@@ -235,7 +235,7 @@ static void hil_dev_handle_ptr_events(struct hil_dev *ptr)
 			if (val < input_abs_min(dev, ABS_X + i))
 				input_abs_set_min(dev, ABS_X + i, val);
 			if (val > input_abs_max(dev, ABS_X + i))
-				XXinput_abs_set_max(dev, ABS_X + i, val);
+				input_abs_set_max(dev, ABS_X + i, val);
 #endif
 			if (i % 3)
 				val = input_abs_max(dev, ABS_X + i) - val;
@@ -391,7 +391,7 @@ static void hil_dev_pointer_setup(struct hil_dev *ptr)
 			int diff = input_abs_max(input_dev, ABS_X + i) / 10;
 			input_abs_set_min(input_dev, ABS_X + i,
 				input_abs_min(input_dev, ABS_X + i) + diff)
-			XXinput_abs_set_max(input_dev, ABS_X + i,
+			input_abs_set_max(input_dev, ABS_X + i,
 				input_abs_max(input_dev, ABS_X + i) - diff)
 		}
 #endif
Signature · 1 line
1.7.0.4
maintainer
#16 lore raw

Re: [PATCH 4/4] input: dynamically allocate ABS information

Quoted 13 lines · Daniel Mack

Hi Dmitry,

Quoted 10 lines · Dmitry Torokhov

Input: switch to input_abs_*() access functions

From: Daniel Mack <[email protected]>

Change all call sites in drivers/input to not access the ABS axis information directly anymore. Make them use the access helpers instead.

Also use input_set_abs_params() when possible.
Did some code refactoring as I was on it.

Quoted 7 lines
Quoted 3 lines

Hmm, there are three locations where some mysterious 'XX' characters were introduced.

Gah, it is all my fault, I was marking stuff that I want to review but missed these 2 drivers.

I sent it on to Linus, hopefully he'll apply it.

Signature · 1 line
Dmitry