From patchwork Sun Nov 11 20:44:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Hoff X-Patchwork-Id: 10677867 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 4825E15E9 for ; Sun, 11 Nov 2018 20:44:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2894A2A144 for ; Sun, 11 Nov 2018 20:44:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 189B72A146; Sun, 11 Nov 2018 20:44:37 +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 98D812A144 for ; Sun, 11 Nov 2018 20:44:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726832AbeKLGeK (ORCPT ); Mon, 12 Nov 2018 01:34:10 -0500 Received: from mout.gmx.net ([212.227.17.20]:35021 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726019AbeKLGeJ (ORCPT ); Mon, 12 Nov 2018 01:34:09 -0500 Received: from raspberrypi ([92.230.194.138]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MRjd7-1ftjYV09cH-00Ssmp; Sun, 11 Nov 2018 21:44:30 +0100 Date: Sun, 11 Nov 2018 21:44:28 +0100 From: Christian Hoff To: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com Cc: sre@kernel.org, christian_hoff@gmx.net Subject: [PATCH v2] Input: matrix_keypad - check for errors from of_get_named_gpio() Message-ID: <20181111204426.tvsatfeb2mam3tkm@raspberrypi> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:O0v00wQg50d1C+RfDAK0p0d39+2Crxo1EcqtFNnJqLuol0Rp9DF f+WQ6ymKyoTNL8Ue/swIwoy9ry0yGVRp43vjvEFimFkTboKeDmJGsQXCHKjsBs6TdpJNT8q tno18OW+I9MXkEOyuvRE48BFJrkaAdEbnQvhz9yKXJY7ISCVjJ0xFHwYe2hyxO7FEGhI1Uf EOduyVGhf+j7xSfAK+8Ag== X-UI-Out-Filterresults: notjunk:1;V01:K0:YVoBKtwZnbA=:pZpRIga978AUgKupY9lGJk MLnLsG33Wbg7RfofAyi7PIG+LIVcGbvAa7JyfOE5grhgrE/B1fTmqpua7r8cJEgXwlfmxqxvr Z1nuIZT6Gcq3tx9mIHpUVfvii/awWExF9uWLPmf5CP17FvOC6mBXxVMNtgq+v5HVwfB4BHK9m N/BgKiq2fb3ADpJlPbUUjJmjQgMCmya8Ptb9wR2PmEc1MyC9OQ1BG75hLFjl9EK84+Yv2FQnc KL9b3w3jyD+P7q3ki1XYoduaNPu9cRC7J6Gd5wphtrPBQUsAL9aelHNOfrEMW2E6oNRDe3ghW xvXjpd9lHhJtPVk0cI10SArlRTLx5if5WAu8JSzdbs6G7luwqthUVWqzYundc6bf2YMuWN9RR Zu6QNEXeJ1wFM5Sdi0gEet6PxywUMO65+T0mFWn8C/n/PQsfCs2KNGT4ODWuuU6I2/6Ev/3tw CMzSYayS3jRK0P9tusg4IlMk1YM1ElsnRMly6E1pl9c/Nphy7CckThUykx+YpimPYRzcKg5S9 kbbsj4wXMi5Q3Rqm/mvH0puK188fAazf8etjkM5TGGB9uuD91p9oK9qk9KglIMRvddwLuUBTc jAryMQALlQ8eLqel9ikPyeCwpHUvr4oeeOi9QsDzBH45rKRMm6ZjDBBf/b/ddnxo1IpxaSuPH 5ceL1h4LqSySRdM6t+AhXb0LST8M8LeNdOsXPuOnnBnTygUYgBsWJYMoE2hqJdhzPuXHo9I5L e0jnt6TQw+bD0eiDwpEIlEhiark73S1bPHbAnRFSX93Q2D61OQLFcCva1Dk4n9ZnhZoQ0K56+ YiBK3UICzkrIYrvcdrG0lYXFSmlrsK+xsxq219oK2/gtbe1j7YOfLMWkgxjJXJLzR4prUxKj8 k3o4RCcwC/GOoYvcDZXt6RFjkt0D/Pe03QePTaeWsBOAjVeY2WRSCZX6ucXxZm 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. This does not lead to information loss because the other error paths in matrix_keypad_parse_dt() already print an error. Signed-off-by: Christian Hoff Suggested-by: Sebastian Reichel Cc: stable@vger.kernel.org Reviewed-by: Sebastian Reichel --- drivers/input/keyboard/matrix_keypad.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index f51ae09596ef..403452ef00e6 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"); @@ -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]; @@ -484,10 +491,8 @@ static int matrix_keypad_probe(struct platform_device *pdev) pdata = dev_get_platdata(&pdev->dev); if (!pdata) { pdata = matrix_keypad_parse_dt(&pdev->dev); - if (IS_ERR(pdata)) { - dev_err(&pdev->dev, "no platform data defined\n"); + if (IS_ERR(pdata)) return PTR_ERR(pdata); - } } else if (!pdata->keymap_data) { dev_err(&pdev->dev, "no keymap data defined\n"); return -EINVAL;