Commit 58a3a4e8 authored by Christian Hoff's avatar Christian Hoff Committed by Greg Kroah-Hartman

Input: matrix_keypad - check for errors from of_get_named_gpio()

commit d55bda1b upstream.

"of_get_named_gpio()" returns a negative error value if it fails
and drivers should check for this. This missing check was now
added to the matrix_keypad driver.

In my case "of_get_named_gpio()" returned -EPROBE_DEFER because
the referenced GPIOs belong to an I/O expander, which was not yet
probed at the point in time when the matrix_keypad driver was
loading. Because the driver did not check for errors from the
"of_get_named_gpio()" routine, it was assuming that "-EPROBE_DEFER"
is actually a GPIO number and continued as usual, which led to further
errors like this later on:

WARNING: CPU: 3 PID: 167 at drivers/gpio/gpiolib.c:114
gpio_to_desc+0xc8/0xd0
invalid GPIO -517

Note that the "GPIO number" -517 in the error message above is
actually "-EPROBE_DEFER".

As part of the patch a misleading error message "no platform data defined"
was also removed. This does not lead to information loss because the other
error paths in matrix_keypad_parse_dt() already print an error.
Signed-off-by: default avatarChristian Hoff <christian_hoff@gmx.net>
Suggested-by: default avatarSebastian Reichel <sre@kernel.org>
Reviewed-by: default avatarSebastian Reichel <sre@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6dc574d0
...@@ -407,7 +407,7 @@ matrix_keypad_parse_dt(struct device *dev) ...@@ -407,7 +407,7 @@ matrix_keypad_parse_dt(struct device *dev)
struct matrix_keypad_platform_data *pdata; struct matrix_keypad_platform_data *pdata;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
unsigned int *gpios; unsigned int *gpios;
int i, nrow, ncol; int ret, i, nrow, ncol;
if (!np) { if (!np) {
dev_err(dev, "device lacks DT data\n"); dev_err(dev, "device lacks DT data\n");
...@@ -452,12 +452,19 @@ matrix_keypad_parse_dt(struct device *dev) ...@@ -452,12 +452,19 @@ matrix_keypad_parse_dt(struct device *dev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
for (i = 0; i < pdata->num_row_gpios; i++) for (i = 0; i < nrow; i++) {
gpios[i] = of_get_named_gpio(np, "row-gpios", i); ret = of_get_named_gpio(np, "row-gpios", i);
if (ret < 0)
return ERR_PTR(ret);
gpios[i] = ret;
}
for (i = 0; i < pdata->num_col_gpios; i++) for (i = 0; i < ncol; i++) {
gpios[pdata->num_row_gpios + i] = ret = of_get_named_gpio(np, "col-gpios", i);
of_get_named_gpio(np, "col-gpios", i); if (ret < 0)
return ERR_PTR(ret);
gpios[nrow + i] = ret;
}
pdata->row_gpios = gpios; pdata->row_gpios = gpios;
pdata->col_gpios = &gpios[pdata->num_row_gpios]; pdata->col_gpios = &gpios[pdata->num_row_gpios];
...@@ -484,10 +491,8 @@ static int matrix_keypad_probe(struct platform_device *pdev) ...@@ -484,10 +491,8 @@ static int matrix_keypad_probe(struct platform_device *pdev)
pdata = dev_get_platdata(&pdev->dev); pdata = dev_get_platdata(&pdev->dev);
if (!pdata) { if (!pdata) {
pdata = matrix_keypad_parse_dt(&pdev->dev); pdata = matrix_keypad_parse_dt(&pdev->dev);
if (IS_ERR(pdata)) { if (IS_ERR(pdata))
dev_err(&pdev->dev, "no platform data defined\n");
return PTR_ERR(pdata); return PTR_ERR(pdata);
}
} else if (!pdata->keymap_data) { } else if (!pdata->keymap_data) {
dev_err(&pdev->dev, "no keymap data defined\n"); dev_err(&pdev->dev, "no keymap data defined\n");
return -EINVAL; return -EINVAL;
......
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