Skip to content

Commit 8397744

Browse files
David Rivshinlinusw
authored andcommitted
gpio: omap: return error if requested debounce time is not possible
omap_gpio_debounce() does not validate that the requested debounce is within a range it can handle. Instead it lets the register value wrap silently, and always returns success. This can lead to all sorts of unexpected behavior, such as gpio_keys asking for a too-long debounce, but getting a very short debounce in practice. Fix this by returning -EINVAL if the requested value does not fit into the register field. If there is no debounce clock available at all, return -ENOTSUPP. Fixes: e85ec6c ("gpio: omap: fix omap2_set_gpio_debounce") Cc: <stable@vger.kernel.org> # 4.3+ Signed-off-by: David Rivshin <drivshin@allworx.com> Acked-by: Grygorii Strashko <grygorii.strashko@ti.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 9384793 commit 8397744

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

drivers/gpio/gpio-omap.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,24 @@ static inline void omap_gpio_dbck_disable(struct gpio_bank *bank)
208208
* OMAP's debounce time is in 31us steps
209209
* <debounce time> = (GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) x 31
210210
* so we need to convert and round up to the closest unit.
211+
*
212+
* Return: 0 on success, negative error otherwise.
211213
*/
212-
static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
213-
unsigned debounce)
214+
static int omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
215+
unsigned debounce)
214216
{
215217
void __iomem *reg;
216218
u32 val;
217219
u32 l;
218220
bool enable = !!debounce;
219221

220222
if (!bank->dbck_flag)
221-
return;
223+
return -ENOTSUPP;
222224

223225
if (enable) {
224226
debounce = DIV_ROUND_UP(debounce, 31) - 1;
225-
debounce &= OMAP4_GPIO_DEBOUNCINGTIME_MASK;
227+
if ((debounce & OMAP4_GPIO_DEBOUNCINGTIME_MASK) != debounce)
228+
return -EINVAL;
226229
}
227230

228231
l = BIT(offset);
@@ -255,6 +258,8 @@ static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
255258
bank->context.debounce = debounce;
256259
bank->context.debounce_en = val;
257260
}
261+
262+
return 0;
258263
}
259264

260265
/**
@@ -964,14 +969,20 @@ static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset,
964969
{
965970
struct gpio_bank *bank;
966971
unsigned long flags;
972+
int ret;
967973

968974
bank = gpiochip_get_data(chip);
969975

970976
raw_spin_lock_irqsave(&bank->lock, flags);
971-
omap2_set_gpio_debounce(bank, offset, debounce);
977+
ret = omap2_set_gpio_debounce(bank, offset, debounce);
972978
raw_spin_unlock_irqrestore(&bank->lock, flags);
973979

974-
return 0;
980+
if (ret)
981+
dev_info(chip->parent,
982+
"Could not set line %u debounce to %u microseconds (%d)",
983+
offset, debounce, ret);
984+
985+
return ret;
975986
}
976987

977988
static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset,

0 commit comments

Comments
 (0)