gsmi: fix null-deref in gsmi_get_variable
[platform/kernel/linux-starfive.git] / drivers / counter / microchip-tcb-capture.c
index f9dee15..e2d1dc6 100644 (file)
@@ -28,7 +28,6 @@ struct mchp_tc_data {
        int qdec_mode;
        int num_channels;
        int channel[2];
-       bool trig_inverted;
 };
 
 static const enum counter_function mchp_tc_count_functions[] = {
@@ -153,7 +152,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
 
        regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr);
 
-       if (priv->trig_inverted)
+       if (signal->id == 1)
                sigstatus = (sr & ATMEL_TC_MTIOB);
        else
                sigstatus = (sr & ATMEL_TC_MTIOA);
@@ -171,6 +170,17 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
        struct mchp_tc_data *const priv = counter_priv(counter);
        u32 cmr;
 
+       if (priv->qdec_mode) {
+               *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
+               return 0;
+       }
+
+       /* Only TIOA signal is evaluated in non-QDEC mode */
+       if (synapse->signal->id != 0) {
+               *action = COUNTER_SYNAPSE_ACTION_NONE;
+               return 0;
+       }
+
        regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
 
        switch (cmr & ATMEL_TC_ETRGEDG) {
@@ -199,8 +209,8 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
        struct mchp_tc_data *const priv = counter_priv(counter);
        u32 edge = ATMEL_TC_ETRGEDG_NONE;
 
-       /* QDEC mode is rising edge only */
-       if (priv->qdec_mode)
+       /* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */
+       if (priv->qdec_mode || synapse->signal->id != 0)
                return -EINVAL;
 
        switch (action) {