esp/mcpwm: fix unpaired spin lock

N/A

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an 2024-12-11 09:46:08 +08:00 committed by Xiang Xiao
parent f3ec1bd60c
commit 4eeb6546ec
2 changed files with 16 additions and 0 deletions

View file

@ -427,6 +427,7 @@ static int esp_motor_setup(struct motor_lowerhalf_s *dev)
if ((priv->state.state == MOTOR_STATE_FAULT) ||
(priv->state.state == MOTOR_STATE_CRITICAL))
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor is in fault state. Clear faults first\n");
return ERROR;
}
@ -553,6 +554,7 @@ static int esp_motor_stop(struct motor_lowerhalf_s *dev)
if (priv->state.state == MOTOR_STATE_IDLE)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor already stopped\n");
return -EPERM;
}
@ -569,6 +571,7 @@ static int esp_motor_stop(struct motor_lowerhalf_s *dev)
ret = esp_motor_set_duty_cycle(priv, 0.0);
if (ret < 0)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Failed setting duty cycle to 0 on stop: %d\n", ret);
return ret;
}
@ -622,6 +625,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
flags = spin_lock_irqsave(&g_mcpwm_common.mcpwm_spinlock);
if (priv->state.state == MOTOR_STATE_RUN)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor already running\n");
return -EINVAL;
}
@ -629,6 +633,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
if ((priv->state.state == MOTOR_STATE_CRITICAL) ||
(priv->state.state == MOTOR_STATE_FAULT))
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor is in fault state\n");
return -EINVAL;
}
@ -636,6 +641,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
ret = esp_motor_pwm_config(priv);
if (ret < 0)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Failed setting PWM configuration\n");
return ret;
}
@ -655,6 +661,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
ret = esp_motor_set_duty_cycle(priv, duty);
if (ret < 0)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Failed starting motor\n");
return ret;
}
@ -1022,6 +1029,7 @@ static int esp_motor_fault_configure(struct mcpwm_motor_lowerhalf_s *lower,
flags = spin_lock_irqsave(&g_mcpwm_common.mcpwm_spinlock);
if (!enable)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mcpwm_ll_fault_enable_detection(hal->dev, lower->fault_id, false);
mcpwm_ll_intr_enable(hal->dev,
MCPWM_LL_EVENT_FAULT_ENTER(lower->fault_id),

View file

@ -454,6 +454,7 @@ static int esp_motor_setup(struct motor_lowerhalf_s *dev)
if ((priv->state.state == MOTOR_STATE_FAULT) ||
(priv->state.state == MOTOR_STATE_CRITICAL))
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor is in fault state. Clear faults first\n");
return ERROR;
}
@ -579,6 +580,7 @@ static int esp_motor_stop(struct motor_lowerhalf_s *dev)
flags = spin_lock_irqsave(&g_mcpwm_common.mcpwm_spinlock);
if (priv->state.state == MOTOR_STATE_IDLE)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor already stopped\n");
return -EPERM;
}
@ -595,6 +597,7 @@ static int esp_motor_stop(struct motor_lowerhalf_s *dev)
ret = esp_motor_set_duty_cycle(priv, 0.0);
if (ret < 0)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Failed setting duty cycle to 0 on stop: %d\n", ret);
return ret;
}
@ -649,6 +652,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
flags = spin_lock_irqsave(&g_mcpwm_common.mcpwm_spinlock);
if (priv->state.state == MOTOR_STATE_RUN)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor already running\n");
return -EINVAL;
}
@ -656,6 +660,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
if ((priv->state.state == MOTOR_STATE_CRITICAL) ||
(priv->state.state == MOTOR_STATE_FAULT))
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Motor is in fault state\n");
return -EINVAL;
}
@ -663,6 +668,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
ret = esp_motor_pwm_config(priv);
if (ret < 0)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Failed setting PWM configuration\n");
return ret;
}
@ -682,6 +688,7 @@ static int esp_motor_start(struct motor_lowerhalf_s *dev)
ret = esp_motor_set_duty_cycle(priv, duty);
if (ret < 0)
{
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
mtrerr("Failed starting motor\n");
return ret;
}
@ -1056,6 +1063,7 @@ static int esp_motor_fault_configure(struct mcpwm_motor_lowerhalf_s *lower,
mcpwm_ll_intr_enable(hal->dev,
MCPWM_LL_EVENT_FAULT_EXIT(lower->fault_id),
false);
spin_unlock_irqrestore(&g_mcpwm_common.mcpwm_spinlock, flags);
return OK;
}