From patchwork Sun Nov 11 18:58:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Hoff X-Patchwork-Id: 10677757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7935214BD for ; Sun, 11 Nov 2018 18:58:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65E0E2A132 for ; Sun, 11 Nov 2018 18:58:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 516512A135; Sun, 11 Nov 2018 18:58:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D6602A132 for ; Sun, 11 Nov 2018 18:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726848AbeKLErx (ORCPT ); Sun, 11 Nov 2018 23:47:53 -0500 Received: from mout.gmx.net ([212.227.17.22]:54609 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729404AbeKLErx (ORCPT ); Sun, 11 Nov 2018 23:47:53 -0500 Received: from raspberrypi ([92.230.194.138]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0M4kfR-1fYjzk1PAL-00yyQe; Sun, 11 Nov 2018 19:58:29 +0100 Date: Sun, 11 Nov 2018 19:58:19 +0100 From: Christian Hoff To: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com Cc: sre@kernel.org Subject: [PATCH] Input: matrix_keypad - check for errors from of_get_named_gpio() Message-ID: <20181111185809.mqi5wev4cdzilghd@raspberrypi> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:/z53+2ZKys3fASZSrqsr8wFc9bpDH0OoXPkFhH1lOVjSe7jfCNz k96TmruyPvUExg+YEK7bSZXdbgqC+d59gvwBNfrRIY6NqC9Rrc3zGku6D5HR0UH0J5Hek/L nzEjwJXB6j6p7gFuq8yAyJ/6+0Nb6L5GDLRNitur7TgFwnSBBBq6C/MPgibZ0BRqI/WvX+d e9Di0braqoxeWEly8tZEQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:1MeQozUO4Po=:0ag2m2tbVL10w+uVBwh8n6 kFwO/Y+7wt9B1MrntXtZjP1Gx84kghFzL/N2gLamb+N/zvTxHIwf5JXSmRWnBuX7hxSw59bCR cXSWEqqkBikVQGH2PDK/eUhoFcNzZSymgYogZ0urtfRFdTtpC0HkEMttsYszMhHUOrI7Cp5LG 8ZOoxRXc2QP1AWsY87dpuR7/rPO3KrPovfZYOAcAKNams9uxC32SgVR2K2l8KeINxUaGmnfVm D4lVv0AGb7O84T25tuq0PZku29FhURbZwk8A+KAZ2498SiI5jYB1nmVJWDEiwKXUa9zf5l4Xm RCpWj+ynwnhR2LyGTdr5OrDklMZqBUh11gmGaUGf/VhvKt0lb1JGtLfn2jcsDQ/jK8Qbxb6Uc xbQ+4FB8WsYzs10vqLwTKndw5rpTlgMj7qiP8ZVHAuAAAjXsytJBjJSj8Yf+UGF9ZQyg+6vRR 9DNx5gRgUlSL18RfWCnGs5iJ5AjHxcNgeQB9japPcnjJord+67DZxi6P2uKmoJcOqKRYsweoF Y+ktbOYZPEXNNNDhgRsmIQlL9QKZuO2I+ZSPJTOu6BOJT5r0N1JJ5YEsT3y7yVwm35iFC/hJe vyWiNwbWnw5Jkxa2tMEUHjBJS5AWBxgyC5HhjNGJOhtvyujNTqra7CMFXz/QKDI+Pww51Qacb Rr6l68e0+4Vpv3WE/Pf4BJZgCadQTeISJX6d3q91HZdQNoelsUmBWdnntyvWMoueeeZDJ1F5o LBFQdJpsOiAbReOVWAYx866caNnKoXa8+I8AHRzb1quE0SGkeR0iLuk6HsRHa1rxTTfc4C8+X bwkHJyyuTpajXxHRwdd7i3XCyHCUWIif2OrlMO8WhjvCkErtIt6dpt1Ow7tz49a9TJpP6Jo1u mDFvesuerCaJK+jDpEK2qskP6Z41k+t133vnI+0jesx/+QjxCR+saQ3Cl98xNP Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "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. Thanks a lot to Sebastian Reichl for his analysis of the problem and for pointing me into the right direction on how to fix this issue! Signed-off-by: Christian Hoff Cc: stable@vger.kernel.org --- drivers/input/keyboard/matrix_keypad.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index f51ae09596ef..8a6be94b7838 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -407,7 +407,7 @@ matrix_keypad_parse_dt(struct device *dev) struct matrix_keypad_platform_data *pdata; struct device_node *np = dev->of_node; unsigned int *gpios; - int i, nrow, ncol; + int ret, i, nrow, ncol; if (!np) { dev_err(dev, "device lacks DT data\n"); @@ -444,7 +444,7 @@ matrix_keypad_parse_dt(struct device *dev) &pdata->col_scan_delay_us); gpios = devm_kcalloc(dev, - pdata->num_row_gpios + pdata->num_col_gpios, + nrow + ncol, sizeof(unsigned int), GFP_KERNEL); if (!gpios) { @@ -452,12 +452,19 @@ matrix_keypad_parse_dt(struct device *dev) return ERR_PTR(-ENOMEM); } - for (i = 0; i < pdata->num_row_gpios; i++) - gpios[i] = of_get_named_gpio(np, "row-gpios", i); + for (i = 0; i < nrow; 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++) - gpios[pdata->num_row_gpios + i] = - of_get_named_gpio(np, "col-gpios", i); + for (i = 0; i < ncol; i++) { + ret = of_get_named_gpio(np, "col-gpios", i); + if (ret < 0) + return ERR_PTR(ret); + gpios[nrow + i] = ret; + } pdata->row_gpios = gpios; pdata->col_gpios = &gpios[pdata->num_row_gpios]; @@ -485,7 +492,6 @@ static int matrix_keypad_probe(struct platform_device *pdev) if (!pdata) { pdata = matrix_keypad_parse_dt(&pdev->dev); if (IS_ERR(pdata)) { - dev_err(&pdev->dev, "no platform data defined\n"); return PTR_ERR(pdata); } } else if (!pdata->keymap_data) {