From patchwork Sun Jun 9 23:51:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 802840 Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D5311CF9B; Sun, 9 Jun 2024 23:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717977100; cv=none; b=WiHmUJw7jIVu/EhyE6eM4lfN8LWprCOy/7kxgsHUf0TXQhC+QBAw6EMECaSDfgZQWiAlHLX6G1NLsJ1HEQFaM9/1GTJ7xUWsJXyAcWP/3zc3y2YqLzCkMG92PyjRdqaekv04ttGcU4ypj1SFnPn12pz6CqrH4u4ay8PTbuQHrpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717977100; c=relaxed/simple; bh=QfJXZWN1aAAuPSN6rqBZFArPNWvXGjthvGQVIq1WSnQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hG+6M+z7UgcZH5sWv59Ez33lFzOTFGLhwdEGKzk3RM1GU1fuy/+B8nGaPHm3qeovy9XmcMt0AQAwgxAIUq9PCcHsWud/36OsJDVy/NvbZ4+HwMaj38VGealpvDPdnV/Am24v5M1GdCz+ecwSDAY3iOUDOrjoC9UmdAeSWwqv02s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aM8Vn4FJ; arc=none smtp.client-ip=209.85.160.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aM8Vn4FJ" Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-250ca14422aso2091727fac.0; Sun, 09 Jun 2024 16:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717977098; x=1718581898; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SVIaAx3x412TkipycxEGUU2uFvDryTHNfZAKZgr8qfg=; b=aM8Vn4FJ8cwu9AE+EQ5qNaAri799xhMLRvHMck7uizyTUgfiPtgsK2UUJXcNRqhoyG CqlSDZLDA/701zjThO38AEMBfxUNhBAwotbSHgXIP8+DYz2l6+1OLGLKWP6K/5Z+Jay+ duBDLInnn7JDMmIp5dOopTF63elVoxfVBU7jZfTChK7usDL/VuJb9b4Ag6qvyik4dCdd PC0xfMWbeVtmUoG+DeUTYe0gjLNtRnoZ/eV+uPhTKgiQK4B/wdTmA9XWMmrnROB1jckj Ae33sPUBNSBh7lETs0YmK3bXuUdXf2+pwf9WYs8x9+/HLQdPXDZWpjgsEgMY93Juyh6/ hknA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717977098; x=1718581898; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SVIaAx3x412TkipycxEGUU2uFvDryTHNfZAKZgr8qfg=; b=up0Gdhe/y+hY4zrZLsde1lmhmsTvFT8Q+8gqmQugPqpW31Q3mOURsyr8t4DvuuK0Jl gj5ChDJCbScfLXJho5nXc6aaEKIFBFVB1K1NzsKHTH+plCjxtPcUFP4/OdilaLW4NeWh w+cIBwKY4itcvB/76du+TTAWGifR0kVe8cu2/C5R3AFSJrvlHnup4FeMD1Fu6RZ22UBI arD1nBIyTlNgctcA4zYc5RAXcRxmEVzMsEyooWOPL1h+Fvpfd1+sPqMnQcNL141RTROH Z7FTfTgVLWG83mtyChRB2nTlWOo+JrWnU5mcNyEmL+RSXGs4JmHDrUs1abgHbaDp2EjL oINw== X-Gm-Message-State: AOJu0YwMUEQ6KhYDplkBI6qFiMrshjbThOf2L7fMnE6jtxOSWwYA6zvl Ie6HrlWVVZbN8PApAAZRdSHx4tprGWI4Yfa2JwuzAgSnyjcz1BIHhjHt/w== X-Google-Smtp-Source: AGHT+IGpmI1jNSVXx0xYJ+Mp5swmpw+ohybJ87ulQdMuFT4BkypTUae5IK5FSbUpW6qhawe1DnCbYg== X-Received: by 2002:a05:6870:3122:b0:24f:ee90:4556 with SMTP id 586e51a60fabf-25463f50643mr9673618fac.0.1717977098037; Sun, 09 Jun 2024 16:51:38 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:55a9:13e9:dec7:f9d3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7042f37f33asm2090356b3a.3.2024.06.09.16.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 16:51:37 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/3] Input: rohm_bu21023 - factor out settings update code Date: Sun, 9 Jun 2024 16:51:30 -0700 Message-ID: <20240609235134.614592-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The code to toggle axis swapping and inversion is repetitive and can be factored out. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/rohm_bu21023.c | 77 +++++++++--------------- 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/drivers/input/touchscreen/rohm_bu21023.c b/drivers/input/touchscreen/rohm_bu21023.c index 06fa3a19d266..c432ed682d31 100644 --- a/drivers/input/touchscreen/rohm_bu21023.c +++ b/drivers/input/touchscreen/rohm_bu21023.c @@ -727,6 +727,29 @@ static int rohm_ts_load_firmware(struct i2c_client *client, return error ? error : error2; } +static int rohm_ts_update_setting(struct rohm_ts_data *ts, + unsigned int setting_bit, bool on) +{ + int error; + + error = mutex_lock_interruptible(&ts->input->mutex); + if (error) + return error; + + if (on) + ts->setup2 |= setting_bit; + else + ts->setup2 &= ~setting_bit; + + if (ts->initialized) + error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, + ts->setup2); + + mutex_unlock(&ts->input->mutex); + + return error; +} + static ssize_t swap_xy_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -748,22 +771,8 @@ static ssize_t swap_xy_store(struct device *dev, struct device_attribute *attr, if (error) return error; - error = mutex_lock_interruptible(&ts->input->mutex); - if (error) - return error; - - if (val) - ts->setup2 |= SWAP_XY; - else - ts->setup2 &= ~SWAP_XY; - - if (ts->initialized) - error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, - ts->setup2); - - mutex_unlock(&ts->input->mutex); - - return error ? error : count; + error = rohm_ts_update_setting(ts, SWAP_XY, val); + return error ?: count; } static ssize_t inv_x_show(struct device *dev, struct device_attribute *attr, @@ -787,22 +796,8 @@ static ssize_t inv_x_store(struct device *dev, struct device_attribute *attr, if (error) return error; - error = mutex_lock_interruptible(&ts->input->mutex); - if (error) - return error; - - if (val) - ts->setup2 |= INV_X; - else - ts->setup2 &= ~INV_X; - - if (ts->initialized) - error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, - ts->setup2); - - mutex_unlock(&ts->input->mutex); - - return error ? error : count; + error = rohm_ts_update_setting(ts, INV_X, val); + return error ?: count; } static ssize_t inv_y_show(struct device *dev, struct device_attribute *attr, @@ -826,22 +821,8 @@ static ssize_t inv_y_store(struct device *dev, struct device_attribute *attr, if (error) return error; - error = mutex_lock_interruptible(&ts->input->mutex); - if (error) - return error; - - if (val) - ts->setup2 |= INV_Y; - else - ts->setup2 &= ~INV_Y; - - if (ts->initialized) - error = i2c_smbus_write_byte_data(client, COMMON_SETUP2, - ts->setup2); - - mutex_unlock(&ts->input->mutex); - - return error ? error : count; + error = rohm_ts_update_setting(ts, INV_Y, val); + return error ?: count; } static DEVICE_ATTR_RW(swap_xy); From patchwork Sun Jun 9 23:47:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 802841 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A466C50289; Sun, 9 Jun 2024 23:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717976884; cv=none; b=XQyE1+HSQGX8j3uZXFmZ0MCra2YkHHuBoHqc9KNhFqV4XeBanxtzNcF8KpR3kc9EvvUtzOMV7UlspoeBHXhJHhyz4PkcOAxosoCQqkT3FAlVJ89zwg3wsUPmH8rFWebmz8OzQW/IR57NG/X1RGQPkCXBH0PN3pGy/d5liUn+zu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717976884; c=relaxed/simple; bh=DKv2KSUbajbBeFk/+WvtEMr49I8AUG8C5TkTqgVTMAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ieB+PcIz6SmUZVOmS2pUJvei9dAu1WWpLAP1cJOnIKGVJjdR8VLtmXhUSQ1/DgQRUFncNo4XaJWwR3DSuJyxAP+E/4D57ogs0z/vHFNkfoos9F4+W5ZVQGnwHQgqnL7du1tL5mZyR6wr7AB7dvYY5F4c1mX1oQhPy4A37+RkzU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cnlcAc7u; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cnlcAc7u" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f4c7b022f8so35780945ad.1; Sun, 09 Jun 2024 16:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717976881; x=1718581681; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=deffonCeETpFm3O0n+cl1BVpvVddVOwXMXSA9gXMWms=; b=cnlcAc7ub55YOcCQrK0E6khdunNNaFJudkdDTiIXM7EAkEAy/FnDCeemlhA0lpu4MF nxCGmQXeRgVTzn/QaXUsbI5y5Qwjfsj9C5aGOo8HT1y5wOS8FDjkoOZCPu6anYhuJvj+ 43DYZZ+otHZD4FC5pJ/1xZ628ssMDO/M/GhUN+7qFnK4OQWtwh1XtJyIuD04YJEQ8/Lm hPNG+4T0CB9Gybxuw2Fs3yUpj9p3ekstNB96b+2PPJT79ItB5dwCNMHNwvU5ohSjMzoG hY02TXBlhOzXuLJIZqFrBKPBE/s5HL5uJoLCxEr5M/gfR4x9jONZdD6xEHuKUIKk9g6j q7Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717976881; x=1718581681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=deffonCeETpFm3O0n+cl1BVpvVddVOwXMXSA9gXMWms=; b=emE6It/bMFbbYmEE/PZrs5I64IcuMho3c7axZ3VYlyOTnxf2qbsFjUJny1+44VYmOK 3BWf1Sgt43MrhrDEH/V2mlLnLpgSTLm5QXl7GluY4RbyVTdrsKJaRH8/c4ja1f/HZ6Yx 1z3NvT5OyTSdVsXmpY3wABxeB7ZcJODLYxgOiI96MrhFC0Z7c9ZK3ZexHipgHuLzsWKo NanrHE68E2cCngQtth9X1Ba7Gg1X3Dj0gnhcOW4idTI/RUtp4qu1UAW/+bR1w/D4mj2d inEfgbTavbNQ71zPsiN0ROmBMlv82i078xD22wTIXCU+WzsTOLpDThdyQdSdtGqokdDz tNLg== X-Forwarded-Encrypted: i=1; AJvYcCW36ZJNq7ZYsJO4j5rIaqdLizojA5v0U3VFxKDnL2LeQrmsXjf3dPsJ2UqD7p9F3rbVfv4vb3WXPoT/z6h4xxfjxCYj1KzA0y5jOwNQ X-Gm-Message-State: AOJu0Yyb4iwfIeAeHo3owsEkA7cLlvTNFsxaR6ScFQXvn1jYzoDa0edR T36zNK7Q9ZnP1wgYW+RFRyqn3GHy3lSq949ZodkcKvvhgoPY2wTW3cr7AA== X-Google-Smtp-Source: AGHT+IGpm4F316SUSMV4HmInbnf0ogSh228MLzAggNIQoCuaRWW0lxQ7QG2QyfsLFD1LOdd3eXRzNA== X-Received: by 2002:a17:903:234b:b0:1f6:3596:7c61 with SMTP id d9443c01a7336-1f6d02bff64mr99228015ad.2.1717976881210; Sun, 09 Jun 2024 16:48:01 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:55a9:13e9:dec7:f9d3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6f84dac28sm27503285ad.158.2024.06.09.16.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 16:48:00 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: John Keeping , Marek Vasut , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] Input: ili210x - switch to using cleanup functions in firmware code Date: Sun, 9 Jun 2024 16:47:54 -0700 Message-ID: <20240609234757.610273-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog In-Reply-To: <20240609234757.610273-1-dmitry.torokhov@gmail.com> References: <20240609234757.610273-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Start using __free() attributes to simplify the code and error handling. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/ili210x.c | 123 ++++++++++++++-------------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index f3c3ad70244f..55f3852c8dae 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -582,14 +582,12 @@ static ssize_t ili210x_calibrate(struct device *dev, } static DEVICE_ATTR(calibrate, S_IWUSR, NULL, ili210x_calibrate); -static int ili251x_firmware_to_buffer(const struct firmware *fw, - u8 **buf, u16 *ac_end, u16 *df_end) +static const u8 *ili251x_firmware_to_buffer(const struct firmware *fw, + u16 *ac_end, u16 *df_end) { const struct ihex_binrec *rec; u32 fw_addr, fw_last_addr = 0; u16 fw_len; - u8 *fw_buf; - int error; /* * The firmware ihex blob can never be bigger than 64 kiB, so make this @@ -597,9 +595,9 @@ static int ili251x_firmware_to_buffer(const struct firmware *fw, * once, copy them all into this buffer at the right locations, and then * do all operations on this linear buffer. */ - fw_buf = kvmalloc(SZ_64K, GFP_KERNEL); + u8* fw_buf __free(kvfree) = kvmalloc(SZ_64K, GFP_KERNEL); if (!fw_buf) - return -ENOMEM; + return ERR_PTR(-ENOMEM); rec = (const struct ihex_binrec *)fw->data; while (rec) { @@ -607,10 +605,8 @@ static int ili251x_firmware_to_buffer(const struct firmware *fw, fw_len = be16_to_cpu(rec->len); /* The last 32 Byte firmware block can be 0xffe0 */ - if (fw_addr + fw_len > SZ_64K || fw_addr > SZ_64K - 32) { - error = -EFBIG; - goto err_big; - } + if (fw_addr + fw_len > SZ_64K || fw_addr > SZ_64K - 32) + return ERR_PTR(-EFBIG); /* Find the last address before DF start address, that is AC end */ if (fw_addr == 0xf000) @@ -623,12 +619,8 @@ static int ili251x_firmware_to_buffer(const struct firmware *fw, /* DF end address is the last address in the firmware blob */ *df_end = fw_addr + fw_len; - *buf = fw_buf; - return 0; -err_big: - kvfree(fw_buf); - return error; + return_ptr(fw_buf); } /* Switch mode between Application and BootLoader */ @@ -691,7 +683,7 @@ static int ili251x_firmware_busy(struct i2c_client *client) return 0; } -static int ili251x_firmware_write_to_ic(struct device *dev, u8 *fwbuf, +static int ili251x_firmware_write_to_ic(struct device *dev, const u8 *fwbuf, u16 start, u16 end, u8 dataflash) { struct i2c_client *client = to_i2c_client(dev); @@ -776,47 +768,17 @@ static void ili210x_hardware_reset(struct gpio_desc *reset_gpio) msleep(300); } -static ssize_t ili210x_firmware_update_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int ili210x_do_firmware_update(struct ili210x *priv, + const u8 *fwbuf, u16 ac_end, u16 df_end) { - struct i2c_client *client = to_i2c_client(dev); - struct ili210x *priv = i2c_get_clientdata(client); - const char *fwname = ILI251X_FW_FILENAME; - const struct firmware *fw; - u16 ac_end, df_end; - u8 *fwbuf; + struct i2c_client *client = priv->client; + struct device *dev = &client->dev; int error; int i; - error = request_ihex_firmware(&fw, fwname, dev); - if (error) { - dev_err(dev, "Failed to request firmware %s, error=%d\n", - fwname, error); - return error; - } - - error = ili251x_firmware_to_buffer(fw, &fwbuf, &ac_end, &df_end); - release_firmware(fw); - if (error) - return error; - - /* - * Disable touchscreen IRQ, so that we would not get spurious touch - * interrupt during firmware update, and so that the IRQ handler won't - * trigger and interfere with the firmware update. There is no bit in - * the touch controller to disable the IRQs during update, so we have - * to do it this way here. - */ - disable_irq(client->irq); - - dev_dbg(dev, "Firmware update started, firmware=%s\n", fwname); - - ili210x_hardware_reset(priv->reset_gpio); - error = ili251x_firmware_reset(client); if (error) - goto exit; + return error; /* This may not succeed on first try, so re-try a few times. */ for (i = 0; i < 5; i++) { @@ -826,7 +788,7 @@ static ssize_t ili210x_firmware_update_store(struct device *dev, } if (error) - goto exit; + return error; dev_dbg(dev, "IC is now in BootLoader mode\n"); @@ -835,7 +797,7 @@ static ssize_t ili210x_firmware_update_store(struct device *dev, error = ili251x_firmware_write_to_ic(dev, fwbuf, 0xf000, df_end, 1); if (error) { dev_err(dev, "DF firmware update failed, error=%d\n", error); - goto exit; + return error; } dev_dbg(dev, "DataFlash firmware written\n"); @@ -843,7 +805,7 @@ static ssize_t ili210x_firmware_update_store(struct device *dev, error = ili251x_firmware_write_to_ic(dev, fwbuf, 0x2000, ac_end, 0); if (error) { dev_err(dev, "AC firmware update failed, error=%d\n", error); - goto exit; + return error; } dev_dbg(dev, "Application firmware written\n"); @@ -856,22 +818,63 @@ static ssize_t ili210x_firmware_update_store(struct device *dev, } if (error) - goto exit; + return error; dev_dbg(dev, "IC is now in Application mode\n"); error = ili251x_firmware_update_cached_state(dev); if (error) - goto exit; + return error; - error = count; + return 0; +} + +static ssize_t ili210x_firmware_update_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct ili210x *priv = i2c_get_clientdata(client); + const char *fwname = ILI251X_FW_FILENAME; + u16 ac_end, df_end; + int error; + + const struct firmware *fw __free(firmware) = NULL; + error = request_ihex_firmware(&fw, fwname, dev); + if (error) { + dev_err(dev, "Failed to request firmware %s, error=%d\n", + fwname, error); + return error; + } + + const u8* fwbuf __free(kvfree) = + ili251x_firmware_to_buffer(fw, &ac_end, &df_end); + error = PTR_ERR_OR_ZERO(fwbuf); + if (error) + return error; + + /* + * Disable touchscreen IRQ, so that we would not get spurious touch + * interrupt during firmware update, and so that the IRQ handler won't + * trigger and interfere with the firmware update. There is no bit in + * the touch controller to disable the IRQs during update, so we have + * to do it this way here. + */ + disable_irq(client->irq); + + dev_dbg(dev, "Firmware update started, firmware=%s\n", fwname); + + ili210x_hardware_reset(priv->reset_gpio); + + error = ili210x_do_firmware_update(priv, fwbuf, ac_end, df_end); -exit: ili210x_hardware_reset(priv->reset_gpio); + dev_dbg(dev, "Firmware update ended, error=%i\n", error); + enable_irq(client->irq); - kvfree(fwbuf); - return error; + + return error ?: count; } static DEVICE_ATTR(firmware_update, 0200, NULL, ili210x_firmware_update_store); From patchwork Sun Jun 9 23:51:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 802839 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5D8355886; Sun, 9 Jun 2024 23:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717977103; cv=none; b=pbisXA5CPg8CJnlYJACZ0s5dM4c3o5iUdEw4EvxvtpVZEk6ekJXCE+2D59VQVBAZY2fRjyVSV7zRAwrPXop1cMamnfNgaQ98sut3WrHWt9Ep1Qdyw/os852N16YhEma7TYBc2WfkhOWb82kFBcPrFC8osdjdpPT72gxjqnQrRTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717977103; c=relaxed/simple; bh=0lppzMbonYaTycDosjLPC5k12ImJsX4Aq5tla2baO1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MpLkymnqoXUl9NU3TvihOLTzKevWJgVKeyoiPKDw5mT4U2D4WunH1cYBr9v5ql9DQQXwNJEYjDifcF+xhl1MZDMPu//diZ9Ubkst+06q4Qip2Rg3mlli34UJKLz0+/Du5GMgF9gWyYkjrCQNxrt7xZplOidNVDIpu1w7idpCXLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UEG8Q7Si; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UEG8Q7Si" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-681ad26f4a5so2031425a12.2; Sun, 09 Jun 2024 16:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717977101; x=1718581901; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bIG6qm6SXhSjHzB7ApreedS7McRlGp65PmXhg91i/aE=; b=UEG8Q7SinucMaaHXw7v1jZnD3IDLtGgYqug+vCwb3vqchrvbg0hIm+pDJWLgCgRyRe b/G/6Y+zvRE3B+/9Bgatcx1u68OIaTDZmihz9iHy52AHPMhIQdmwrTLJoSn8R+0s4A4S wxlBrtENbUs5aYHdvkS2uVBv+P7Oen+EQkY5I9h+FzObb9L+oDP+OGmLjY9NOQDKdJ33 p9CkQhzABdSxjhdQHb1aknPsWrDFy41Pq5ruy5iAA5Z/QxLeKtwYNrVB7+UUASPTtXKa eDmEOaxa3il7NSYMEgW9D6FyJMcPUhFL0/qmuHuTkvyiIG6UhF4J0xCxR+DuaUnDibYf bAHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717977101; x=1718581901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bIG6qm6SXhSjHzB7ApreedS7McRlGp65PmXhg91i/aE=; b=FD8GqzWTzinIIOxEfw7Xq9RENoxAhXSb+Yu+Snnw1UeUxc0uUWDkizbsWYeoroSf3i 8w6uw77e47l0Mmz6gPUBDF8gkWRhQY4D+B2H9e/5eoqHD3EnGm9iZ8iPCypjnWKMddPJ tXFv+3IvTKgURqYd8YHkW1Xa6l6WmPcqIE+73B5n3tyZjFl4EaI5SxYqx1az3UwFB/7C guq2to/Mdwf5xNQ1xF4pss5KAmte4vdpzbP/Ri0JMR43vPIAcWJmvU+fvVsAdeU6aWKn QgFbarCefKuqXs33QGUbAQoMojPUzeyGwE2otEGAtFnY5+XWZiLwZGHj43QKpPWs3UtA JB0w== X-Gm-Message-State: AOJu0Yx0POZQEqSLVMS05cp/ZlghQUDq8iTishawUgQYceaEvtR6Gpw7 A2JFpBFB3SvV5wydba9L91DBfF8YEhue9SkQ5s12dwJsmRyqM0eF4ypoxg== X-Google-Smtp-Source: AGHT+IHyF10GmfEKuNSGPDcTWv3EHNkxNkdiTaMa8rFbknktjJmNWE8N7Q0YQW1HlnSdoiqY0vUtqg== X-Received: by 2002:a05:6a20:734c:b0:1b6:1ed4:e916 with SMTP id adf61e73a8af0-1b61ed4eb55mr3092482637.35.1717977100596; Sun, 09 Jun 2024 16:51:40 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:55a9:13e9:dec7:f9d3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7042f37f33asm2090356b3a.3.2024.06.09.16.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 16:51:39 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/3] Input: rohm_bu21023 - switch to using cleanup functions Date: Sun, 9 Jun 2024 16:51:32 -0700 Message-ID: <20240609235134.614592-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog In-Reply-To: <20240609235134.614592-1-dmitry.torokhov@gmail.com> References: <20240609235134.614592-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Start using __free() and guard() primitives to simplify the code and error handling. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/rohm_bu21023.c | 40 +++++++++++------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/input/touchscreen/rohm_bu21023.c b/drivers/input/touchscreen/rohm_bu21023.c index 7be2549fde85..0e5cc9fbad17 100644 --- a/drivers/input/touchscreen/rohm_bu21023.c +++ b/drivers/input/touchscreen/rohm_bu21023.c @@ -643,12 +643,12 @@ static int rohm_ts_load_firmware(struct i2c_client *client, const char *firmware_name) { struct device *dev = &client->dev; - const struct firmware *fw; s32 status; unsigned int offset, len, xfer_len; unsigned int retry = 0; int error, error2; + const struct firmware *fw __free(firmware) = NULL; error = request_firmware(&fw, firmware_name, dev); if (error) { dev_err(dev, "unable to retrieve firmware %s: %d\n", @@ -722,8 +722,6 @@ static int rohm_ts_load_firmware(struct i2c_client *client, out: error2 = i2c_smbus_write_byte_data(client, INT_MASK, INT_ALL); - release_firmware(fw); - return error ? error : error2; } @@ -732,22 +730,22 @@ static int rohm_ts_update_setting(struct rohm_ts_data *ts, { int error; - error = mutex_lock_interruptible(&ts->input->mutex); - if (error) - return error; - - if (on) - ts->setup2 |= setting_bit; - else - ts->setup2 &= ~setting_bit; + scoped_cond_guard(mutex_intr, return -EINTR, &ts->input->mutex) { + if (on) + ts->setup2 |= setting_bit; + else + ts->setup2 &= ~setting_bit; - if (ts->initialized) - error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2, - ts->setup2); - - mutex_unlock(&ts->input->mutex); + if (ts->initialized) { + error = i2c_smbus_write_byte_data(ts->client, + COMMON_SETUP2, + ts->setup2); + if (error) + return error; + } + } - return error; + return 0; } static ssize_t swap_xy_show(struct device *dev, struct device_attribute *attr, @@ -842,7 +840,7 @@ static int rohm_ts_device_init(struct i2c_client *client, u8 setup2) struct device *dev = &client->dev; int error; - disable_irq(client->irq); + guard(disable_irq)(&client->irq); /* * Wait 200usec for reset @@ -1017,10 +1015,10 @@ static int rohm_ts_device_init(struct i2c_client *client, u8 setup2) /* controller CPU power on */ error = i2c_smbus_write_byte_data(client, SYSTEM, ANALOG_POWER_ON | CPU_POWER_ON); + if (error) + return error; - enable_irq(client->irq); - - return error; + return 0; } static int rohm_ts_power_off(struct i2c_client *client)