Skip to content

Commit cc5117d

Browse files
andy-shevdtor
authored andcommitted
Input: of_touchscreen - explicitly choose axis
The 'axis + 1' calculation is implicit and potentially error prone. Moreover, few lines before the axis is set explicitly for both X and Y. Do the same when retrieving different properties for X and Y. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent b9a1c11 commit cc5117d

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

drivers/input/touchscreen/of_touchscreen.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,41 +66,42 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch,
6666
{
6767
struct device *dev = input->dev.parent;
6868
struct input_absinfo *absinfo;
69-
unsigned int axis;
69+
unsigned int axis, axis_x, axis_y;
7070
unsigned int minimum, maximum, fuzz;
7171
bool data_present;
7272

7373
input_alloc_absinfo(input);
7474
if (!input->absinfo)
7575
return;
7676

77-
axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
77+
axis_x = multitouch ? ABS_MT_POSITION_X : ABS_X;
78+
axis_y = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
79+
7880
data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x",
79-
input_abs_get_min(input, axis),
81+
input_abs_get_min(input, axis_x),
8082
&minimum) |
8183
touchscreen_get_prop_u32(dev, "touchscreen-size-x",
8284
input_abs_get_max(input,
83-
axis) + 1,
85+
axis_x) + 1,
8486
&maximum) |
8587
touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
86-
input_abs_get_fuzz(input, axis),
88+
input_abs_get_fuzz(input, axis_x),
8789
&fuzz);
8890
if (data_present)
89-
touchscreen_set_params(input, axis, minimum, maximum - 1, fuzz);
91+
touchscreen_set_params(input, axis_x, minimum, maximum - 1, fuzz);
9092

91-
axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
9293
data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-y",
93-
input_abs_get_min(input, axis),
94+
input_abs_get_min(input, axis_y),
9495
&minimum) |
9596
touchscreen_get_prop_u32(dev, "touchscreen-size-y",
9697
input_abs_get_max(input,
97-
axis) + 1,
98+
axis_y) + 1,
9899
&maximum) |
99100
touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
100-
input_abs_get_fuzz(input, axis),
101+
input_abs_get_fuzz(input, axis_y),
101102
&fuzz);
102103
if (data_present)
103-
touchscreen_set_params(input, axis, minimum, maximum - 1, fuzz);
104+
touchscreen_set_params(input, axis_y, minimum, maximum - 1, fuzz);
104105

105106
axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE;
106107
data_present = touchscreen_get_prop_u32(dev,
@@ -117,31 +118,29 @@ void touchscreen_parse_properties(struct input_dev *input, bool multitouch,
117118
if (!prop)
118119
return;
119120

120-
axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
121-
122-
prop->max_x = input_abs_get_max(input, axis);
123-
prop->max_y = input_abs_get_max(input, axis + 1);
121+
prop->max_x = input_abs_get_max(input, axis_x);
122+
prop->max_y = input_abs_get_max(input, axis_y);
124123

125124
prop->invert_x =
126125
device_property_read_bool(dev, "touchscreen-inverted-x");
127126
if (prop->invert_x) {
128-
absinfo = &input->absinfo[axis];
127+
absinfo = &input->absinfo[axis_x];
129128
absinfo->maximum -= absinfo->minimum;
130129
absinfo->minimum = 0;
131130
}
132131

133132
prop->invert_y =
134133
device_property_read_bool(dev, "touchscreen-inverted-y");
135134
if (prop->invert_y) {
136-
absinfo = &input->absinfo[axis + 1];
135+
absinfo = &input->absinfo[axis_y];
137136
absinfo->maximum -= absinfo->minimum;
138137
absinfo->minimum = 0;
139138
}
140139

141140
prop->swap_x_y =
142141
device_property_read_bool(dev, "touchscreen-swapped-x-y");
143142
if (prop->swap_x_y)
144-
swap(input->absinfo[axis], input->absinfo[axis + 1]);
143+
swap(input->absinfo[axis_x], input->absinfo[axis_y]);
145144
}
146145
EXPORT_SYMBOL(touchscreen_parse_properties);
147146

0 commit comments

Comments
 (0)