From patchwork Fri Oct 4 13:46:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13822390 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19A7E212EED for ; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049617; cv=none; b=hMvSzV/2CvKRCp8YbZGVXNUnyHfz3Ya0o31q0s+a0HUXRVCtin+bXmb4KseEGI+2TvRtcclgr3qcuMAEBtfI0muR2ojGJ8CYYXArqBLq/BE69ItprMEPDXq8RJi7X3SUUDD9f7DgudhW8ynqyU+SSsLSkaE9d5jUPKQkDD06Ncw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049617; c=relaxed/simple; bh=TQdzT5fj4fjsb2m8teEep4deAsU9fDFo0MkGzTSzU98=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rr0cMvE/zG/88Jb7P34MXw+tIM/1K53SvitAxaSc5QVhxC+T/EOWhNFRFXPnBQP1nejqvL5yzemLoUI706flc/R1rTVnEytANGhKeUPmORaNWCq4N18Xs1w5EaboxQPkksSk7zBcj4GMRfE0pxf/R7gTwoD9v2kIHHikJF4waEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KlmHvPb+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KlmHvPb+" Received: by smtp.kernel.org (Postfix) with ESMTPS id B617AC4CEC7; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728049616; bh=TQdzT5fj4fjsb2m8teEep4deAsU9fDFo0MkGzTSzU98=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=KlmHvPb+EJDaj1y+5j0FbhA71QtFcK+L88dlKmMbrwxE9m0GvkykYHjnmlymdLxPX 19v3ajKmgZjmhstfVxaSMjgIb6KZFuQ/+pwkbIgCwEgw4QYZqoFwqpwZH+IhGChwOz STkaPcX0W+dtsUfsEJcAXvYhptAwB1Zu1+yzKHXS8aY8b3rJW4+mQsvHkk17Ujc+0y 2Ryz7qCJKAfxTgD6ljOkCxJUxB6OVYzkJb3+1GHu8kD7X4hgt7VFlivxfCKkELglvq dsK6+3tzsQrdCBu3zmHSGohrViMI4XQam5SY0x7OneN9k/J6rHvnA30S769m7ddDo/ 24dC+eCwIArCw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7D4ACFA775; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 04 Oct 2024 15:46:50 +0200 Subject: [PATCH v2 1/3] Input: adp5588-keys: bail on returned error Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-fix-adp5588-read-refactor-v2-1-275a093758ae@analog.com> References: <20241004-fix-adp5588-read-refactor-v2-0-275a093758ae@analog.com> In-Reply-To: <20241004-fix-adp5588-read-refactor-v2-0-275a093758ae@analog.com> To: Michael Hennerich , Dmitry Torokhov Cc: linux-input@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728049615; l=5780; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=r9TnP/wtMiKjVNaniVP8bwQshEJ/XoHAR/uMSqI/NPU=; b=H+p3w+hWRJutVKmRAEmUQrPdCVdGSIULKIFYhn88kmLnJujnm+oWAvXNQgiaf9xZildevoG+6 d7rc+V9WtsUCUNAo3hRQiFQV5kbyX2x4CnvKy7HCdSc8oPB5MZlrJSk X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa Bail out in case adp5588_read() return an error code. Not doing so is asking for problems. In order to making it easier (as some values we want to read are unsigned), adp5588_read() now either returns 0 or an error code and the value to read is passed as an argument to the function. While at it, did a small refactor in adp5588_gpio_get_value() to make it easier to handle checking the return value. Suggested-by: Dmitry Torokhov Signed-off-by: Nuno Sa --- drivers/input/keyboard/adp5588-keys.c | 84 +++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c index d25d63a807f23..11a70ee184825 100644 --- a/drivers/input/keyboard/adp5588-keys.c +++ b/drivers/input/keyboard/adp5588-keys.c @@ -200,14 +200,17 @@ struct adp5588_kpad { u8 pull_dis[3]; }; -static int adp5588_read(struct i2c_client *client, u8 reg) +static int adp5588_read(struct i2c_client *client, u8 reg, u8 *val) { int ret = i2c_smbus_read_byte_data(client, reg); - if (ret < 0) + if (ret < 0) { dev_err(&client->dev, "Read Error\n"); + return ret; + } - return ret; + *val = ret; + return 0; } static int adp5588_write(struct i2c_client *client, u8 reg, u8 val) @@ -220,14 +223,17 @@ static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned int off) struct adp5588_kpad *kpad = gpiochip_get_data(chip); unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); - int val; + int error; + u8 val; guard(mutex)(&kpad->gpio_lock); if (kpad->dir[bank] & bit) - val = kpad->dat_out[bank]; - else - val = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank); + return !!(kpad->dat_out[bank] & bit); + + error = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank, &val); + if (error) + return error; return !!(val & bit); } @@ -453,10 +459,20 @@ static int adp5588_gpio_add(struct adp5588_kpad *kpad) } for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) { - kpad->dat_out[i] = adp5588_read(kpad->client, - GPIO_DAT_OUT1 + i); - kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i); - kpad->pull_dis[i] = adp5588_read(kpad->client, GPIO_PULL1 + i); + error = adp5588_read(kpad->client, + GPIO_DAT_OUT1 + i, &kpad->dat_out[i]); + if (error) + return error; + + error = adp5588_read(kpad->client, GPIO_DIR1 + i, + &kpad->dir[i]); + if (error) + return error; + + error = adp5588_read(kpad->client, GPIO_PULL1 + i, + &kpad->pull_dis[i]); + if (error) + return error; } return 0; @@ -519,9 +535,15 @@ static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt) int i; for (i = 0; i < ev_cnt; i++) { - int key = adp5588_read(kpad->client, KEY_EVENTA + i); - int key_val = key & KEY_EV_MASK; - int key_press = key & KEY_EV_PRESSED; + u8 key, key_val, key_press; + int error; + + error = adp5588_read(kpad->client, KEY_EVENTA + i, &key); + if (error) + return; + + key_val = key & KEY_EV_MASK; + key_press = key & KEY_EV_PRESSED; if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END) { /* gpio line used as IRQ source */ @@ -556,7 +578,8 @@ static irqreturn_t adp5588_thread_irq(int irq, void *handle) struct i2c_client *client = kpad->client; ktime_t target_time, now; unsigned long delay; - int status, ev_cnt; + u8 status, ev_cnt; + int error; /* * Readout needs to wait for at least 25ms after the notification @@ -571,19 +594,23 @@ static irqreturn_t adp5588_thread_irq(int irq, void *handle) } } - status = adp5588_read(client, INT_STAT); + error = adp5588_read(client, INT_STAT, &status); + if (error) + return IRQ_HANDLED; if (status & ADP5588_OVR_FLOW_INT) /* Unlikely and should never happen */ dev_err(&client->dev, "Event Overflow Error\n"); if (status & ADP5588_KE_INT) { - ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & ADP5588_KEC; - if (ev_cnt) { - adp5588_report_events(kpad, ev_cnt); - input_sync(kpad->input); - } + error = adp5588_read(client, KEY_LCK_EC_STAT, &ev_cnt); + if (error || !(ev_cnt & ADP5588_KEC)) + goto out_irq; + + adp5588_report_events(kpad, ev_cnt & ADP5588_KEC); + input_sync(kpad->input); } +out_irq: adp5588_write(client, INT_STAT, status); /* Status is W1C */ return IRQ_HANDLED; @@ -593,6 +620,7 @@ static int adp5588_setup(struct adp5588_kpad *kpad) { struct i2c_client *client = kpad->client; int i, ret; + u8 dummy; ret = adp5588_write(client, KP_GPIO1, KP_SEL(kpad->rows)); if (ret) @@ -619,8 +647,8 @@ static int adp5588_setup(struct adp5588_kpad *kpad) } for (i = 0; i < KEYP_MAX_EVENT; i++) { - ret = adp5588_read(client, KEY_EVENTA); - if (ret < 0) + ret = adp5588_read(client, KEY_EVENTA, &dummy); + if (ret) return ret; } @@ -724,8 +752,8 @@ static int adp5588_probe(struct i2c_client *client) struct input_dev *input; struct gpio_desc *gpio; unsigned int revid; - int ret; int error; + u8 id; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { @@ -762,11 +790,11 @@ static int adp5588_probe(struct i2c_client *client) fsleep(60); } - ret = adp5588_read(client, DEV_ID); - if (ret < 0) - return ret; + error = adp5588_read(client, DEV_ID, &id); + if (error) + return error; - revid = ret & ADP5588_DEVICE_ID_MASK; + revid = id & ADP5588_DEVICE_ID_MASK; if (WA_DELAYED_READOUT_REVID(revid)) kpad->delay = msecs_to_jiffies(WA_DELAYED_READOUT_TIME); From patchwork Fri Oct 4 13:46:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13822389 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19A1C212EE8 for ; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049617; cv=none; b=saIphcqt8bCHOHNTATVuhv13ephqiR8I8+G6qzMO75ZbFcx8qdd8bRzEz1QUBOaWOqqpM3zXZ8Kv4FavjdK2LAAXmoMfWVGM6kHcQKF7l///Zq3ZrJhPkm5nDBtHQjEW75LhidSDYMTgpkGK7f+wF0rSBsAsd0yti0HdIJAsLWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049617; c=relaxed/simple; bh=kU9RMwVK7tK5tGrD9ncs9Bo5tDjNxEdbyC+uGRc5nuU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NAQ5cQjRAGrZqyRD0y5sHqzYmWsMg5acl2fj9pWWQU25WkKGkoAxX5v+8YgxrAFcEc/2rx5Dpc9xil157CTg6BVTZ+GHQ7Jjvp9vehegKF7WIuIfFP+Sb1Jx/8sXXuFI96huDquP0Bomyc2x1xm6AEFIOVqXyG4qGy4mPGm3B5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fQ0ZwCSu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fQ0ZwCSu" Received: by smtp.kernel.org (Postfix) with ESMTPS id C9CE6C4CECE; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728049616; bh=kU9RMwVK7tK5tGrD9ncs9Bo5tDjNxEdbyC+uGRc5nuU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fQ0ZwCSulZ/ZS74vxP1Qhd0L4JArmpfJQZOYxEmcE177MOHP/1UA2qNrzHfklaon1 M6zw+RnUMgiiAN5XmainvoBAWNFN/pAn1zfJMWEk5AD6eJt9/W3b0wxcxuyIAFc9n0 AU1B1Sg0QYLBafmH3FycceDoQhPXUWaDr28RD05m80leAipJjAsCvbO07fukI0HR+H 57uCn9Rf71XOUYc43ln4IRZvjeWcTx2LypN3mb2vf1CNiH+M35qJ7jesyeIptMvp4z STRfxfSbEAcXgaqOjHP1QKaBDvr2hn/oaRCRh3UsFAAQtQIx/2oi1UEV8WdM/kZ5PW 32zRMghaPv1Ig== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFF84CFA779; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 04 Oct 2024 15:46:51 +0200 Subject: [PATCH v2 2/3] Input: adp5588-keys: error out if no IRQ is given Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-fix-adp5588-read-refactor-v2-2-275a093758ae@analog.com> References: <20241004-fix-adp5588-read-refactor-v2-0-275a093758ae@analog.com> In-Reply-To: <20241004-fix-adp5588-read-refactor-v2-0-275a093758ae@analog.com> To: Michael Hennerich , Dmitry Torokhov Cc: linux-input@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728049615; l=956; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=Oyv6w1vVB0WsBBnLrEoR1/r+BQ9oW4zFkMd7v+3aoJg=; b=Fs81b3fJ5aOuuyMiSMYuhAbB6WFlTgIXVDF9IqQ/Hmv4MmfUO35qAse6aO2Xx0mjI01B3yVTb JSF+J+yuNOUA6O2PenI8BS4wpmYpwEylfSdLu1A6/o9mhFQtwyyTngE X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa If the keypad is configured, it also depends on the presence of an interrupt. With commit dc748812fca0 ("Input: adp5588-keys - add support for pure gpio"), having an interrupt is no longer mandatory so better check for it when it is indeed mandatory. Signed-off-by: Nuno Sa --- drivers/input/keyboard/adp5588-keys.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c index 11a70ee18482..0152e4fa088c 100644 --- a/drivers/input/keyboard/adp5588-keys.c +++ b/drivers/input/keyboard/adp5588-keys.c @@ -680,6 +680,11 @@ static int adp5588_fw_parse(struct adp5588_kpad *kpad) return 0; } + if (!client->irq) { + dev_err(&client->dev, "Keypad configured but no IRQ present\n"); + return -EINVAL; + } + ret = matrix_keypad_parse_properties(&client->dev, &kpad->rows, &kpad->cols); if (ret) From patchwork Fri Oct 4 13:46:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13822391 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52A7E212EF5 for ; Fri, 4 Oct 2024 13:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049617; cv=none; b=RmsJON4h8du5hjikKwnPvcvv5jenZp7rQ05k6zbDg61pyjIXhqfERldQitvhwyVlAXWVLXTOWyLYzTDglhtTbPfyiUrd9caN1BN6hSCrps/OFh1+St9kNnttn508ZrSQIo2opvbH/RwAOWHX7u0KxNcuDmikwW91qDaXs8gygsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728049617; c=relaxed/simple; bh=GaGVBlUAZAzixzMPjr2GKd8qLJQJTfvw7fhOCSOmZbc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hhpu5Mcg21KDSuVdah3V8bHxOs9A1bvcNmDftpxZLCucvf0Ui0p4bWtEMZLm9A+tVp7ijMDPO9HlSuHinzl7Q9+Bx4w/GMy5wqkCRSV2N9ZAa4MtH9rUCW/GZ6fnNRNwWFcKAIAAoYiLkbjROMJ00cklfWjzSl8Dd+GHHVh/bCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bidOoLtR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bidOoLtR" Received: by smtp.kernel.org (Postfix) with ESMTPS id DC557C4CECF; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728049616; bh=GaGVBlUAZAzixzMPjr2GKd8qLJQJTfvw7fhOCSOmZbc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bidOoLtRJsexYyg3ZsTsv8KZaq2UiDPzlIb5UfOAaeB64y3ju4TLoYA7vM76SSVGT VAchmtTPYH+wR255Rl3M7RIVTs3gHbmxD2ddtvLCq3rVcBqim/HKvbves3kiuxyDEC aZuQfWpjxmZmLM71lVw5u3191Q1Nsc7mrY7zm4IrPYMi87db97W/RuTSkdq3C9gRYN +DmkeQ6ftQJMmjrfpP6X1JJWefwOP72iCoixuN2ihjVq17hHX7sNvS8FqpTKwexaW9 SkvGGjPvo2r4Esv/hJwpmbaaQ1ygOpZwgmHVDzQl5Z0xOtpxpMyj+OwQFPn5v9TpKT n1B68FdGIE7FA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1E1FCFA77F; Fri, 4 Oct 2024 13:46:56 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 04 Oct 2024 15:46:52 +0200 Subject: [PATCH v2 3/3] Input: adp5588-keys: make use of dev_err_probe() Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-fix-adp5588-read-refactor-v2-3-275a093758ae@analog.com> References: <20241004-fix-adp5588-read-refactor-v2-0-275a093758ae@analog.com> In-Reply-To: <20241004-fix-adp5588-read-refactor-v2-0-275a093758ae@analog.com> To: Michael Hennerich , Dmitry Torokhov Cc: linux-input@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728049615; l=5144; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=gt3jhPKFLDsBuarU+NtzbRqk71V3bunZcxmUsG25ZIQ=; b=0zjhhTtwyPOawLFp+Or7GywbXi577wNF/msX2A0anWmqpASw+FALS8e+MEo/CLiqfnE2pjXSh yc7C14dMxcnAaqUXVZ28wYOlVixJmwkoUinMjBIx95RDVsrca8XX8ma X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa Simplify the probe error path by using dev_err_probe(). Signed-off-by: Nuno Sa --- drivers/input/keyboard/adp5588-keys.c | 70 +++++++++++++++-------------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c index 0152e4fa088c..60a7cb040af7 100644 --- a/drivers/input/keyboard/adp5588-keys.c +++ b/drivers/input/keyboard/adp5588-keys.c @@ -439,10 +439,9 @@ static int adp5588_gpio_add(struct adp5588_kpad *kpad) kpad->gc.owner = THIS_MODULE; if (device_property_present(dev, "interrupt-controller")) { - if (!kpad->client->irq) { - dev_err(dev, "Unable to serve as interrupt controller without interrupt"); - return -EINVAL; - } + if (!kpad->client->irq) + return dev_err_probe(dev, -EINVAL, + "Unable to serve as interrupt controller without interrupt"); girq = &kpad->gc.irq; gpio_irq_chip_set_chip(girq, &adp5588_irq_chip); @@ -453,10 +452,8 @@ static int adp5588_gpio_add(struct adp5588_kpad *kpad) mutex_init(&kpad->gpio_lock); error = devm_gpiochip_add_data(dev, &kpad->gc, kpad); - if (error) { - dev_err(dev, "gpiochip_add failed: %d\n", error); - return error; - } + if (error) + return dev_err_probe(dev, error, "gpiochip_add failed\n"); for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) { error = adp5588_read(kpad->client, @@ -680,21 +677,19 @@ static int adp5588_fw_parse(struct adp5588_kpad *kpad) return 0; } - if (!client->irq) { - dev_err(&client->dev, "Keypad configured but no IRQ present\n"); - return -EINVAL; - } + if (!client->irq) + return dev_err_probe(&client->dev, -EINVAL, + "Keypad configured but no IRQ present\n"); ret = matrix_keypad_parse_properties(&client->dev, &kpad->rows, &kpad->cols); if (ret) return ret; - if (kpad->rows > ADP5588_ROWS_MAX || kpad->cols > ADP5588_COLS_MAX) { - dev_err(&client->dev, "Invalid nr of rows(%u) or cols(%u)\n", - kpad->rows, kpad->cols); - return -EINVAL; - } + if (kpad->rows > ADP5588_ROWS_MAX || kpad->cols > ADP5588_COLS_MAX) + return dev_err_probe(&client->dev, -EINVAL, + "Invalid nr of rows(%u) or cols(%u)\n", + kpad->rows, kpad->cols); ret = matrix_keypad_build_keymap(NULL, NULL, kpad->rows, kpad->cols, kpad->keycode, kpad->input); @@ -714,11 +709,10 @@ static int adp5588_fw_parse(struct adp5588_kpad *kpad) return 0; } - if (kpad->nkeys_unlock > ARRAY_SIZE(kpad->unlock_keys)) { - dev_err(&client->dev, "number of unlock keys(%d) > (%zu)\n", - kpad->nkeys_unlock, ARRAY_SIZE(kpad->unlock_keys)); - return -EINVAL; - } + if (kpad->nkeys_unlock > ARRAY_SIZE(kpad->unlock_keys)) + return dev_err_probe(&client->dev, -EINVAL, + "number of unlock keys(%d) > (%zu)\n", + kpad->nkeys_unlock, ARRAY_SIZE(kpad->unlock_keys)); ret = device_property_read_u32_array(&client->dev, "adi,unlock-keys", kpad->unlock_keys, @@ -735,11 +729,10 @@ static int adp5588_fw_parse(struct adp5588_kpad *kpad) * part of keypad matrix to be used and if a reliable way of * using GPIs is found, this condition can be removed/lightened. */ - if (kpad->unlock_keys[i] >= kpad->cols * kpad->rows) { - dev_err(&client->dev, "Invalid unlock key(%d)\n", - kpad->unlock_keys[i]); - return -EINVAL; - } + if (kpad->unlock_keys[i] >= kpad->cols * kpad->rows) + return dev_err_probe(&client->dev, -EINVAL, + "Invalid unlock key(%d)\n", + kpad->unlock_keys[i]); /* * Firmware properties keys start from 0 but on the device they @@ -761,10 +754,9 @@ static int adp5588_probe(struct i2c_client *client) u8 id; if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA)) { - dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); - return -EIO; - } + I2C_FUNC_SMBUS_BYTE_DATA)) + return dev_err_probe(&client->dev, -EIO, + "SMBUS Byte Data not Supported\n"); kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL); if (!kpad) @@ -814,11 +806,9 @@ static int adp5588_probe(struct i2c_client *client) input->id.version = revid; error = input_register_device(input); - if (error) { - dev_err(&client->dev, "unable to register input device: %d\n", - error); - return error; - } + if (error) + return dev_err_probe(&client->dev, error, + "unable to register input device\n"); error = adp5588_setup(kpad); if (error) @@ -833,11 +823,9 @@ static int adp5588_probe(struct i2c_client *client) adp5588_hard_irq, adp5588_thread_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, client->dev.driver->name, kpad); - if (error) { - dev_err(&client->dev, "failed to request irq %d: %d\n", - client->irq, error); - return error; - } + if (error) + return dev_err_probe(&client->dev, error, + "failed to request irq %d\n", client->irq); } dev_info(&client->dev, "Rev.%d controller\n", revid);