Commit 708d9893 authored by Syed Nayyar Waris's avatar Syed Nayyar Waris Committed by Jonathan Cameron

counter: 104-quad-8: Add lock guards - differential encoder

Add lock protection from race conditions to 104-quad-8 counter driver
for differential encoder status code changes. Mutex lock calls used for
protection.
Signed-off-by: default avatarSyed Nayyar Waris <syednwaris@gmail.com>
Fixes: 954ab5cc ("counter: 104-quad-8: Support Differential Encoder Cable Status")
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 25f02d32
...@@ -1274,18 +1274,26 @@ static ssize_t quad8_signal_cable_fault_read(struct counter_device *counter, ...@@ -1274,18 +1274,26 @@ static ssize_t quad8_signal_cable_fault_read(struct counter_device *counter,
struct counter_signal *signal, struct counter_signal *signal,
void *private, char *buf) void *private, char *buf)
{ {
const struct quad8_iio *const priv = counter->priv; struct quad8_iio *const priv = counter->priv;
const size_t channel_id = signal->id / 2; const size_t channel_id = signal->id / 2;
const bool disabled = !(priv->cable_fault_enable & BIT(channel_id)); bool disabled;
unsigned int status; unsigned int status;
unsigned int fault; unsigned int fault;
if (disabled) mutex_lock(&priv->lock);
disabled = !(priv->cable_fault_enable & BIT(channel_id));
if (disabled) {
mutex_unlock(&priv->lock);
return -EINVAL; return -EINVAL;
}
/* Logic 0 = cable fault */ /* Logic 0 = cable fault */
status = inb(priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS); status = inb(priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
mutex_unlock(&priv->lock);
/* Mask respective channel and invert logic */ /* Mask respective channel and invert logic */
fault = !(status & BIT(channel_id)); fault = !(status & BIT(channel_id));
...@@ -1317,6 +1325,8 @@ static ssize_t quad8_signal_cable_fault_enable_write( ...@@ -1317,6 +1325,8 @@ static ssize_t quad8_signal_cable_fault_enable_write(
if (ret) if (ret)
return ret; return ret;
mutex_lock(&priv->lock);
if (enable) if (enable)
priv->cable_fault_enable |= BIT(channel_id); priv->cable_fault_enable |= BIT(channel_id);
else else
...@@ -1327,6 +1337,8 @@ static ssize_t quad8_signal_cable_fault_enable_write( ...@@ -1327,6 +1337,8 @@ static ssize_t quad8_signal_cable_fault_enable_write(
outb(cable_fault_enable, priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS); outb(cable_fault_enable, priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
mutex_unlock(&priv->lock);
return len; return len;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment