Variable scope reductions

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-synaptics/-/merge_requests/20>
This commit is contained in:
Alan Coopersmith
2024-12-04 16:19:31 -08:00
parent ca05a6034e
commit 3d1486dbe9
6 changed files with 36 additions and 70 deletions

View File

@@ -151,7 +151,6 @@ ALPS_process_packet(unsigned char *packet, struct SynapticsHwState *hw)
{
int x = 0, y = 0, z = 0;
int left = 0, right = 0, middle = 0;
int i;
hw->millis = GetTimeInMillis();
@@ -168,7 +167,7 @@ ALPS_process_packet(unsigned char *packet, struct SynapticsHwState *hw)
/* Handle normal packets */
hw->x = hw->y = hw->z = hw->numFingers = hw->fingerWidth = 0;
hw->left = hw->right = hw->up = hw->down = hw->middle = FALSE;
for (i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
hw->multi[i] = FALSE;
if (z > 0) {

View File

@@ -178,9 +178,7 @@ UninitializeTouch(InputInfoPtr pInfo)
return;
if (proto_data->last_mt_vals) {
int i;
for (i = 0; i < priv->num_slots; i++)
for (int i = 0; i < priv->num_slots; i++)
valuator_mask_free(&proto_data->last_mt_vals[i]);
free(proto_data->last_mt_vals);
proto_data->last_mt_vals = NULL;
@@ -195,7 +193,6 @@ InitializeTouch(InputInfoPtr pInfo)
SynapticsPrivate *priv = (SynapticsPrivate *) pInfo->private;
struct eventcomm_proto_data *proto_data =
(struct eventcomm_proto_data *) priv->proto_data;
int i;
if (!priv->has_touch)
return;
@@ -211,9 +208,7 @@ InitializeTouch(InputInfoPtr pInfo)
return;
}
for (i = 0; i < priv->num_slots; i++) {
int j;
for (int i = 0; i < priv->num_slots; i++) {
proto_data->last_mt_vals[i] = valuator_mask_new(4 + priv->num_mt_axes);
if (!proto_data->last_mt_vals[i]) {
xf86IDrvMsg(pInfo, X_WARNING,
@@ -226,7 +221,7 @@ InitializeTouch(InputInfoPtr pInfo)
* and Y. */
valuator_mask_set(proto_data->last_mt_vals[i], 0, 0);
valuator_mask_set(proto_data->last_mt_vals[i], 1, 0);
for (j = 0; j < priv->num_mt_axes; j++)
for (int j = 0; j < priv->num_mt_axes; j++)
valuator_mask_set(proto_data->last_mt_vals[i], 4 + j, 0);
}
}
@@ -586,9 +581,7 @@ SynapticsReadEvent(InputInfoPtr pInfo, struct input_event *ev)
static Bool
EventTouchSlotPreviouslyOpen(SynapticsPrivate * priv, int slot)
{
int i;
for (i = 0; i < priv->num_active_touches; i++)
for (int i = 0; i < priv->num_active_touches; i++)
if (priv->open_slots[i] == slot)
return TRUE;
@@ -837,7 +830,6 @@ event_query_touch(InputInfoPtr pInfo)
SynapticsParameters *para = &priv->synpara;
struct eventcomm_proto_data *proto_data = priv->proto_data;
struct libevdev *dev = proto_data->evdev;
int axis;
priv->max_touches = 0;
priv->num_mt_axes = 0;
@@ -862,7 +854,7 @@ event_query_touch(InputInfoPtr pInfo)
if (libevdev_has_event_code(dev, EV_ABS, ABS_MT_SLOT)) {
for (axis = ABS_MT_SLOT + 1; axis <= ABS_MT_MAX; axis++) {
for (int axis = ABS_MT_SLOT + 1; axis <= ABS_MT_MAX; axis++) {
if (!libevdev_has_event_code(dev, EV_ABS, axis))
continue;
@@ -912,7 +904,7 @@ event_query_touch(InputInfoPtr pInfo)
priv->has_mt_palm_detect = TRUE;
axnum = 0;
for (axis = ABS_MT_SLOT + 1; axis <= ABS_MT_MAX; axis++) {
for (int axis = ABS_MT_SLOT + 1; axis <= ABS_MT_MAX; axis++) {
int axis_idx = axis - ABS_MT_TOUCH_MAJOR;
if (!libevdev_has_event_code(dev, EV_ABS, axis))
@@ -962,12 +954,11 @@ EventReadDevDimensions(InputInfoPtr pInfo)
{
SynapticsPrivate *priv = (SynapticsPrivate *) pInfo->private;
struct eventcomm_proto_data *proto_data = priv->proto_data;
int i;
proto_data = EventProtoDataAlloc(pInfo->fd);
priv->proto_data = proto_data;
for (i = 0; i < ABS_MT_CNT; i++)
for (int i = 0; i < ABS_MT_CNT; i++)
proto_data->axis_map[i] = -1;
proto_data->cur_slot = -1;
@@ -1033,12 +1024,11 @@ EventAutoDevProbe(InputInfoPtr pInfo, const char *device)
}
while (i--) {
char fname[PATH_MAX];
int fd = -1;
if (!touchpad_found) {
int fd = -1;
int rc;
struct libevdev *evdev;
char fname[PATH_MAX];
snprintf(fname, sizeof(fname), "%s/%s",
DEV_INPUT_EVENT, namelist[i]->d_name);

View File

@@ -100,14 +100,13 @@ static Atom
InitTypedAtom(DeviceIntPtr dev, const char *name, Atom type, int format,
int nvalues, int *values)
{
int i;
Atom atom;
uint8_t val_8[9]; /* we never have more than 9 values in an atom */
uint16_t val_16[9];
uint32_t val_32[9];
pointer converted;
for (i = 0; i < nvalues; i++) {
for (int i = 0; i < nvalues; i++) {
switch (format) {
case 8:
val_8[i] = values[i];
@@ -632,7 +631,6 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
para->locked_drag_time = *(INT32 *) prop->data;
}
else if (property == prop_tapaction) {
int i;
CARD8 *action;
if (prop->size > MAX_TAP || prop->format != 8 ||
@@ -641,11 +639,10 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
action = (CARD8 *) prop->data;
for (i = 0; i < MAX_TAP; i++)
for (int i = 0; i < MAX_TAP; i++)
para->tap_action[i] = action[i];
}
else if (property == prop_clickaction) {
int i;
CARD8 *action;
if (prop->size > MAX_CLICK || prop->format != 8 ||
@@ -654,7 +651,7 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
action = (CARD8 *) prop->data;
for (i = 0; i < MAX_CLICK; i++)
for (int i = 0; i < MAX_CLICK; i++)
para->click_action[i] = action[i];
}
else if (property == prop_circscroll) {

View File

@@ -137,14 +137,12 @@ ps2_putbyte(int fd, byte b)
static Bool
ps2_special_cmd(int fd, byte cmd)
{
int i;
/* initialize with 'inert' command */
if (!ps2_putbyte(fd, PS2_CMD_SET_SCALING_1_1))
return FALSE;
/* send 4x 2-bits with set resolution command */
for (i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++) {
if (!ps2_putbyte(fd, PS2_CMD_SET_RESOLUTION) ||
!ps2_putbyte(fd, (cmd >> 6) & 0x3))
return FALSE;
@@ -313,9 +311,7 @@ static Bool
ps2_query_is_synaptics(InputInfoPtr pInfo, int fd,
struct PS2SynapticsHwInfo *synhw)
{
int i;
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
if (ps2_synaptics_disable_device(fd))
break;
}
@@ -462,10 +458,9 @@ ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
{
int count = 0;
int c;
unsigned char u;
while ((c = XisbRead(comm->buffer)) >= 0) {
u = (unsigned char) c;
unsigned char u = (unsigned char) c;
/* test if there is a reset sequence received */
if ((c == 0x00) && (comm->lastByte == 0xAA)) {
@@ -491,9 +486,7 @@ ps2_synaptics_get_packet(InputInfoPtr pInfo, struct PS2SynapticsHwInfo *synhw,
so we throw away the first byte in the packet. */
if (comm->protoBufTail >= 6) {
if (!ps2_packet_ok(synhw, comm)) {
int i;
for (i = 0; i < comm->protoBufTail - 1; i++)
for (int i = 0; i < comm->protoBufTail - 1; i++)
comm->protoBuf[i] = comm->protoBuf[i + 1];
comm->protoBufTail--;
comm->outOfSync++;
@@ -530,7 +523,7 @@ PS2ReadHwStateProto(InputInfoPtr pInfo,
SynapticsParameters *para = &priv->synpara;
struct PS2SynapticsHwInfo *synhw;
int newabs;
int w, i;
int w;
synhw = (struct PS2SynapticsHwInfo *) priv->proto_data;
if (!synhw) {
@@ -547,7 +540,7 @@ PS2ReadHwStateProto(InputInfoPtr pInfo,
/* Handle normal packets */
hw->x = hw->y = hw->z = hw->numFingers = hw->fingerWidth = 0;
hw->left = hw->right = hw->up = hw->down = hw->middle = FALSE;
for (i = 0; i < 8; i++)
for (int i = 0; i < 8; i++)
hw->multi[i] = FALSE;
if (newabs) { /* newer protos... */

View File

@@ -1039,8 +1039,6 @@ error:
static void
SynapticsReset(SynapticsPrivate * priv)
{
int i;
SynapticsResetHwState(priv->hwState);
SynapticsResetHwState(priv->local_hw_state);
SynapticsResetHwState(priv->comm.hwState);
@@ -1071,7 +1069,7 @@ SynapticsReset(SynapticsPrivate * priv)
priv->prevFingers = 0;
priv->num_active_touches = 0;
for (i = 0; i < priv->num_slots; i++)
for (int i = 0; i < priv->num_slots; i++)
priv->open_slots[i] = -1;
}
@@ -1123,8 +1121,6 @@ DeviceClose(DeviceIntPtr dev)
static void
InitAxesLabels(Atom *labels, int nlabels, const SynapticsPrivate * priv)
{
int i;
memset(labels, 0, nlabels * sizeof(Atom));
switch (nlabels) {
default:
@@ -1142,7 +1138,7 @@ InitAxesLabels(Atom *labels, int nlabels, const SynapticsPrivate * priv)
break;
}
for (i = 0; i < priv->num_mt_axes; i++) {
for (int i = 0; i < priv->num_mt_axes; i++) {
SynapticsTouchAxisRec *axis = &priv->touch_axes[i];
int axnum = nlabels - priv->num_mt_axes + i;
@@ -2632,7 +2628,6 @@ clickpad_guess_clickfingers(SynapticsPrivate * priv,
{
int nfingers = 0;
uint32_t close_point = 0; /* 1 bit for each point close to another one */
int i, j;
if (hw->num_mt_mask > sizeof(close_point) * 8) {
ErrorFSigSafe("BUG: synaptics: hw->num_mt_mask too big %d\n", hw->num_mt_mask);
@@ -2640,7 +2635,7 @@ clickpad_guess_clickfingers(SynapticsPrivate * priv,
return 0;
}
for (i = 0; i < hw->num_mt_mask - 1; i++) {
for (int i = 0; i < hw->num_mt_mask - 1; i++) {
ValuatorMask *f1;
if (hw->slot_state[i] == SLOTSTATE_EMPTY ||
@@ -2649,7 +2644,7 @@ clickpad_guess_clickfingers(SynapticsPrivate * priv,
f1 = hw->mt_mask[i];
for (j = i + 1; j < hw->num_mt_mask; j++) {
for (int j = i + 1; j < hw->num_mt_mask; j++) {
ValuatorMask *f2;
double x1, x2, y1, y2;
@@ -2873,7 +2868,7 @@ repeat_scrollbuttons(const InputInfoPtr pInfo,
{
SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
SynapticsParameters *para = &priv->synpara;
int repeat_delay, timeleft;
int repeat_delay;
int rep_buttons = 0;
if (para->updown_button_repeat)
@@ -2898,15 +2893,16 @@ repeat_scrollbuttons(const InputInfoPtr pInfo,
}
if (priv->repeatButtons) {
timeleft = TIME_DIFF(priv->nextRepeat, now);
int timeleft = TIME_DIFF(priv->nextRepeat, now);
if (timeleft > 0)
delay = MIN(delay, timeleft);
if (timeleft <= 0) {
int change, id;
int change;
change = priv->repeatButtons;
while (change) {
id = ffs(change);
int id = ffs(change);
change &= ~(1 << (id - 1));
if (id == 4)
priv->scroll.delta_y -= para->scroll_dist_vert;
@@ -2931,9 +2927,8 @@ static void
UpdateTouchState(InputInfoPtr pInfo, struct SynapticsHwState *hw)
{
SynapticsPrivate *priv = (SynapticsPrivate *) pInfo->private;
int i;
for (i = 0; i < hw->num_mt_mask; i++) {
for (int i = 0; i < hw->num_mt_mask; i++) {
if (hw->slot_state[i] == SLOTSTATE_OPEN) {
priv->open_slots[priv->num_active_touches] = i;
priv->num_active_touches++;
@@ -2946,9 +2941,8 @@ UpdateTouchState(InputInfoPtr pInfo, struct SynapticsHwState *hw)
}
else if (hw->slot_state[i] == SLOTSTATE_CLOSE) {
Bool found = FALSE;
int j;
for (j = 0; j < priv->num_active_touches - 1; j++) {
for (int j = 0; j < priv->num_active_touches - 1; j++) {
if (priv->open_slots[j] == i)
found = TRUE;
@@ -3007,7 +3001,7 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
SynapticsParameters *para = &priv->synpara;
enum FingerState finger = FS_UNTOUCHED;
int dx = 0, dy = 0, buttons, id;
int dx = 0, dy = 0, buttons;
enum EdgeType edge = NO_EDGE;
int change;
int double_click = FALSE;
@@ -3139,7 +3133,7 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
change = buttons ^ priv->lastButtons;
while (change) {
id = ffs(change); /* number of first set bit 1..32 is returned */
int id = ffs(change); /* number of first set bit 1..32 is returned */
change &= ~(1 << (id - 1));
xf86PostButtonEvent(pInfo->dev, FALSE, id, (buttons & (1 << (id - 1))),
0, 0);

View File

@@ -79,13 +79,11 @@ SynapticsHwStateAlloc(SynapticsPrivate * priv)
void
SynapticsHwStateFree(struct SynapticsHwState **hw)
{
int i;
if (!*hw)
return;
free((*hw)->slot_state);
for (i = 0; i < (*hw)->num_mt_mask; i++)
for (int i = 0; i < (*hw)->num_mt_mask; i++)
valuator_mask_free(&(*hw)->mt_mask[i]);
free((*hw)->mt_mask);
@@ -97,8 +95,6 @@ void
SynapticsCopyHwState(struct SynapticsHwState *dst,
const struct SynapticsHwState *src)
{
int i;
dst->millis = src->millis;
dst->x = src->x;
dst->y = src->y;
@@ -113,7 +109,7 @@ SynapticsCopyHwState(struct SynapticsHwState *dst,
dst->down = src->down;
memcpy(dst->multi, src->multi, sizeof(dst->multi));
dst->middle = src->middle & BTN_EMULATED_FLAG ? 0 : src->middle;
for (i = 0; i < dst->num_mt_mask && i < src->num_mt_mask; i++)
for (int i = 0; i < dst->num_mt_mask && i < src->num_mt_mask; i++)
valuator_mask_copy(dst->mt_mask[i], src->mt_mask[i]);
memcpy(dst->slot_state, src->slot_state,
dst->num_mt_mask * sizeof(enum SynapticsSlotState));
@@ -145,13 +141,10 @@ SynapticsResetHwState(struct SynapticsHwState *hw)
void
SynapticsResetTouchHwState(struct SynapticsHwState *hw, Bool set_slot_empty)
{
int i;
for (i = 0; i < hw->num_mt_mask; i++) {
int j;
for (int i = 0; i < hw->num_mt_mask; i++) {
/* Leave x and y valuators in case we need to restart touch */
for (j = 2; j < valuator_mask_num_valuators(hw->mt_mask[i]); j++)
for (int j = 2; j < valuator_mask_num_valuators(hw->mt_mask[i]); j++)
valuator_mask_unset(hw->mt_mask[i], j);
switch (hw->slot_state[i]) {