[PATCH xf86-input-synaptics 04/10] Allocate priv->hwState

Chase Douglas chase.douglas at canonical.com
Wed Feb 8 18:35:13 PST 2012


This is needed for when SynapticsHwState can't be allocated on the stack.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 src/synaptics.c    |   28 +++++++++++++++++++---------
 src/synapticsstr.h |    2 +-
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/synaptics.c b/src/synaptics.c
index 3326aef..058ed55 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -645,12 +645,12 @@ static float SynapticsAccelerationProfile(DeviceIntPtr dev,
 	int maxZ = para->press_motion_max_z;
 	double minFctr = para->press_motion_min_factor;
 	double maxFctr = para->press_motion_max_factor;
-	if (priv->hwState.z <= minZ) {
+	if (priv->hwState->z <= minZ) {
 	    accelfct *= minFctr;
-	} else if (priv->hwState.z >= maxZ) {
+	} else if (priv->hwState->z >= maxZ) {
 	    accelfct *= maxFctr;
 	} else {
-	    accelfct *= minFctr + (priv->hwState.z - minZ) * (maxFctr - minFctr) / (maxZ - minZ);
+	    accelfct *= minFctr + (priv->hwState->z - minZ) * (maxFctr - minFctr) / (maxZ - minZ);
 	}
     }
 
@@ -934,6 +934,8 @@ DeviceClose(DeviceIntPtr dev)
     TimerFree(priv->timer);
     priv->timer = NULL;
     free_shm_data(priv);
+    SynapticsHwStateFree(priv->hwState);
+    priv->hwState = NULL;
     SynapticsHwStateFree(priv->local_hw_state);
     priv->local_hw_state = NULL;
     SynapticsHwStateFree(priv->comm.hwState);
@@ -1183,15 +1185,23 @@ no_touch:
 
     free(axes_labels);
 
+    priv->hwState = SynapticsHwStateAlloc(priv);
+    if (!priv->hwState)
+        return !Success;
+
     priv->local_hw_state = SynapticsHwStateAlloc(priv);
     if (!priv->local_hw_state)
+    {
+	free(priv->hwState);
 	return !Success;
+    }
 
     priv->comm.hwState = SynapticsHwStateAlloc(priv);
 
     if (!alloc_shm_data(pInfo))
     {
 	free(priv->local_hw_state);
+	free(priv->hwState);
 	return !Success;
     }
 
@@ -1329,8 +1339,8 @@ timerFunc(OsTimerPtr timer, CARD32 now, pointer arg)
 
     sigstate = xf86BlockSIGIO();
 
-    priv->hwState.millis += now - priv->timer_time;
-    *hw = priv->hwState;
+    priv->hwState->millis += now - priv->timer_time;
+    *hw = *priv->hwState;
     delay = HandleState(pInfo, hw, hw->millis, TRUE);
 
     priv->timer_time = now;
@@ -1371,7 +1381,7 @@ ReadInput(InputInfoPtr pInfo)
     Bool newDelay = FALSE;
 
     while (SynapticsGetHwState(pInfo, priv, hw)) {
-	priv->hwState = *hw;
+	*priv->hwState = *hw;
 	delay = HandleState(pInfo, hw, hw->millis, FALSE);
 	newDelay = TRUE;
     }
@@ -1614,11 +1624,11 @@ static void
 SetMovingState(SynapticsPrivate *priv, enum MovingState moving_state, CARD32 millis)
 {
     DBG(7, "SetMovingState - %d -> %d center at %d/%d (millis:%d)\n", priv->moving_state,
-		  moving_state,priv->hwState.x, priv->hwState.y, millis);
+		  moving_state,priv->hwState->x, priv->hwState->y, millis);
 
     if (moving_state == MS_TRACKSTICK) {
-	priv->trackstick_neutral_x = priv->hwState.x;
-	priv->trackstick_neutral_y = priv->hwState.y;
+	priv->trackstick_neutral_x = priv->hwState->x;
+	priv->trackstick_neutral_y = priv->hwState->y;
     }
     priv->moving_state = moving_state;
 }
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index fff159c..9a11816 100644
--- a/src/synapticsstr.h
+++ b/src/synapticsstr.h
@@ -191,7 +191,7 @@ typedef struct _SynapticsPrivateRec
     struct SynapticsProtocolOperations* proto_ops;
     void *proto_data;			/* protocol-specific data */
 
-    struct SynapticsHwState hwState;
+    struct SynapticsHwState *hwState;
 
     const char *device;			/* device node */
     Bool shm_config;			/* True when shared memory area allocated */
-- 
1.7.8.3



More information about the xorg-devel mailing list