Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp904060imu; Tue, 11 Dec 2018 09:19:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/WXFhj9SuwnVjr0ljEFXow4QzxIC6in0kQtqhZhvUwqMRctVYsxptlRf8PW17FBBqcW0PKo X-Received: by 2002:a62:3a04:: with SMTP id h4mr16930221pfa.119.1544548759945; Tue, 11 Dec 2018 09:19:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548759; cv=none; d=google.com; s=arc-20160816; b=ljxiyR9umiOo02WKwLSBleJ62k++z2mUBXuNNkFbPtqLAhf50gHZO6WUm9EEahtRmf lWae7oGORnPsGy9i9rWiE5xD4GHU9ZcZaL6Z1C2RFYGoghQyHbwnOmJfgxC328iJronc AqBmBfs+kRahTP/hKPBxyeV0k43A6P7bwfSd6uCtsvR4oIHRefmImkDAWtyYq+lIXTIt 45XIUcoP32rIJmspz8MCRi+OLYuRFjOX5Bj82aEakrkAsxN6B+ZfXOOyaXHlko9T0Htn TrIhzi4/X87YnaAc5q4fCvOZh+8p9hbC4ifiIzY+0QVPCNMsOOg5YS4/fYzhyQedNHMD YMZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8/r//WSB+dTuUUpiADiRs8StSj3pJ86fUmywlzFhjVw=; b=cgzvgtjGwJ4vJ6Vi7fZF/g47sgKVN9l+cnz7Sa4myfQRCcWhnElKSu3zA+s1dMhHTh mu9AlgdNNQ3UB7i4IeZqLHR1w+6YbFHi3aIQms8JLjzym7tnDw3GJa8RyRTs0kyoM0Lf iaKe9Kz02w1ZnvVnICXLB7qwHbaLj3VHqV/JykHZ1fiNE8+yFWQb0s/e1CPlM2Fzco0g TGaCrFXLSKsPldhTuFVeBFbr89db7bn1fpm8oAApKOMnf/EiXvmM4/AYZ7w4aP09tCPC BCq7T28HfXbrdpbSs1B/0ifaeEOVVyn/un0KZ1YL93iZ7k20hZI3026sMwk2K7eeFuPY ECvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=obtR0t7L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n12si12377212pgb.563.2018.12.11.09.19.04; Tue, 11 Dec 2018 09:19:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=obtR0t7L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729011AbeLKQSX (ORCPT + 99 others); Tue, 11 Dec 2018 11:18:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:34946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbeLKPqc (ORCPT ); Tue, 11 Dec 2018 10:46:32 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0E4DF20870; Tue, 11 Dec 2018 15:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543191; bh=D7V2KyM2B8wU3qtJK3nEjjjoZupeDabQToKj2E9KfbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=obtR0t7LkVcfCZC6ZpnloGAvItDg6iFV4XL9N0yrKbmkIzrdOTFRcLIY9Af+DVu/N uAa9492tu+JJBLNsKH9NJPCgaHM1DGbHVCBLp1exVnrfCkHuZEqVKokIaLFqS8uUm9 ueHlmd1uD7gJxX0iFJVT01xTeIbNUTa+d9EUlUQU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Hoff , Sebastian Reichel , Dmitry Torokhov Subject: [PATCH 4.4 46/91] Input: matrix_keypad - check for errors from of_get_named_gpio() Date: Tue, 11 Dec 2018 16:41:05 +0100 Message-Id: <20181211151609.727774116@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Hoff commit d55bda1b3e7c5a87f10da54fdda866a9a9cef30b 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: Christian Hoff Suggested-by: Sebastian Reichel Reviewed-by: Sebastian Reichel Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/keyboard/matrix_keypad.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -405,7 +405,7 @@ matrix_keypad_parse_dt(struct device *de 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"); @@ -447,12 +447,19 @@ matrix_keypad_parse_dt(struct device *de 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]; @@ -479,10 +486,8 @@ static int matrix_keypad_probe(struct pl 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;