counter: Standardize to ERANGE for limit exceeded errors
authorWilliam Breathitt Gray <vilhelm.gray@gmail.com>
Tue, 3 Aug 2021 12:06:13 +0000 (21:06 +0900)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 9 Aug 2021 19:17:36 +0000 (20:17 +0100)
ERANGE is a semantically better error code to return when an argument
value falls outside the supported limit range of a device.

Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Acked-by: Syed Nayyar Waris <syednwaris@gmail.com>
Reviewed-by: David Lechner <david@lechnology.com>
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Link: https://lore.kernel.org/r/ae8d3b20b8b02c96b1c9898ffa2f9fa5d99edc81.1627990337.git.vilhelm.gray@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/counter/104-quad-8.c
drivers/counter/intel-qep.c
drivers/counter/interrupt-cnt.c
drivers/counter/stm32-lptimer-cnt.c

index b358b2b..d54efdb 100644 (file)
@@ -154,7 +154,7 @@ static int quad8_count_write(struct counter_device *counter,
 
        /* Only 24-bit values are supported */
        if (val > 0xFFFFFF)
-               return -EINVAL;
+               return -ERANGE;
 
        mutex_lock(&priv->lock);
 
@@ -669,7 +669,7 @@ static ssize_t quad8_count_preset_write(struct counter_device *counter,
 
        /* Only 24-bit values are supported */
        if (preset > 0xFFFFFF)
-               return -EINVAL;
+               return -ERANGE;
 
        mutex_lock(&priv->lock);
 
@@ -714,7 +714,7 @@ static ssize_t quad8_count_ceiling_write(struct counter_device *counter,
 
        /* Only 24-bit values are supported */
        if (ceiling > 0xFFFFFF)
-               return -EINVAL;
+               return -ERANGE;
 
        mutex_lock(&priv->lock);
 
index 1a9512e..204f945 100644 (file)
@@ -319,7 +319,7 @@ static ssize_t spike_filter_ns_write(struct counter_device *counter,
        }
 
        if (length > INTEL_QEPFLT_MAX_COUNT(length))
-               return -EINVAL;
+               return -ERANGE;
 
        mutex_lock(&qep->lock);
        if (qep->enabled) {
index 5df7cd1..66cac49 100644 (file)
@@ -107,6 +107,9 @@ static int interrupt_cnt_write(struct counter_device *counter,
 {
        struct interrupt_cnt_priv *priv = counter->priv;
 
+       if (val != (typeof(priv->count.counter))val)
+               return -ERANGE;
+
        atomic_set(&priv->count, val);
 
        return 0;
index 78f383b..49aeb9e 100644 (file)
@@ -283,7 +283,7 @@ static ssize_t stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
                return ret;
 
        if (ceiling > STM32_LPTIM_MAX_ARR)
-               return -EINVAL;
+               return -ERANGE;
 
        priv->ceiling = ceiling;