[PATCH v3] Input: raydium_i2c_ts - use a fixed-size report buffer
From: Pooyan Azad
Date: Tue Nov 24 2026 - 15:43:30 EST
A firmware update can change the touch report size. The driver keeps
its original packet and report sizes while updating the contact size
and data bank address. The IRQ handler can then read and parse reports
using parameters from different firmware versions.
Embed a buffer large enough for any value of the u8 packet size. The
managed IRQ is requested after the driver state is allocated, so devres
releases the IRQ before freeing the buffer. An embedded buffer also
lets a controller that probed in bootloader mode accept reports after
a successful firmware update.
Stage the firmware information and report parameters locally. Publish
them together after validation and after all reads succeed.
Fixes: 48a2b783483b ("Input: add Raydium I2C touchscreen driver")
Suggested-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
Link: https://lore.kernel.org/linux-input/3e575d6e2eb90d4a3707319d37134c1a@xxxxxxxxx/
Assisted-by: Codex:gpt-6-luna
Signed-off-by: Pooyan Azad <pooyan.azadparvar@xxxxxxxxx>
---
Changes in v3
- Dmitry already applied v2 patch 1 to for-linus.
- Combine v2 patches 2 and 3 into one patch.
- Replace dynamic report buffer allocation with an embedded fixed-size array.
- Address Dmitry's devres concern by tying the buffer to the driver state,
which outlives the managed IRQ.
Testing
- x86-64 Raydium driver object built with W=1 using GCC 11.4.0.
- Seven mocked cases passed, covering report size limits, query failures,
firmware updates, bootloader recovery, and IRQ handling.
- No physical Raydium hardware was tested.
drivers/input/touchscreen/raydium_i2c_ts.c | 43 +++++++---------------
1 file changed, 14 insertions(+), 29 deletions(-)
diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c b/drivers/input/touchscreen/raydium_i2c_ts.c
index 68ada037f694..fa6e93bec9d2 100644
--- a/drivers/input/touchscreen/raydium_i2c_ts.c
+++ b/drivers/input/touchscreen/raydium_i2c_ts.c
@@ -19,6 +19,7 @@
#include <linux/input.h>
#include <linux/input/mt.h>
#include <linux/interrupt.h>
+#include <linux/limits.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/overflow.h>
@@ -129,14 +130,13 @@ struct raydium_data {
struct mutex sysfs_mutex;
- u8 *report_data;
-
u32 data_bank_addr;
u8 report_size;
u8 contact_size;
u8 pkg_size;
enum raydium_boot_mode boot_mode;
+ u8 report_data[U8_MAX];
};
/*
@@ -333,6 +333,7 @@ static int raydium_i2c_query_ts_info(struct raydium_data *ts)
{
struct i2c_client *client = ts->client;
struct raydium_data_info data_info;
+ struct raydium_info info;
__le32 query_bank_addr;
u8 report_size;
@@ -355,27 +356,6 @@ static int raydium_i2c_query_ts_info(struct raydium_data *ts)
return -EINVAL;
}
- /*
- * Warn user if we already allocated memory for reports and
- * then the size changed (due to firmware update?) and keep
- * old size instead.
- */
- if (ts->report_data && ts->pkg_size != data_info.pkg_size) {
- dev_warn(&client->dev,
- "report size changes, was: %d, new: %d\n",
- ts->pkg_size, data_info.pkg_size);
- } else {
- ts->pkg_size = data_info.pkg_size;
- ts->report_size = report_size;
- }
-
- ts->contact_size = data_info.tp_info_size;
- ts->data_bank_addr = le32_to_cpu(data_info.data_bank_addr);
-
- dev_dbg(&client->dev,
- "data_bank_addr: %#08x, report_size: %d, contact_size: %d\n",
- ts->data_bank_addr, ts->report_size, ts->contact_size);
-
error = raydium_i2c_read(client, RM_CMD_QUERY_BANK,
&query_bank_addr,
sizeof(query_bank_addr));
@@ -383,10 +363,20 @@ static int raydium_i2c_query_ts_info(struct raydium_data *ts)
continue;
error = raydium_i2c_read(client, le32_to_cpu(query_bank_addr),
- &ts->info, sizeof(ts->info));
+ &info, sizeof(info));
if (error)
continue;
+ ts->info = info;
+ ts->pkg_size = data_info.pkg_size;
+ ts->report_size = report_size;
+ ts->contact_size = data_info.tp_info_size;
+ ts->data_bank_addr = le32_to_cpu(data_info.data_bank_addr);
+
+ dev_dbg(&client->dev,
+ "data_bank_addr: %#08x, report_size: %d, contact_size: %d\n",
+ ts->data_bank_addr, ts->report_size, ts->contact_size);
+
return 0;
}
@@ -1130,11 +1120,6 @@ static int raydium_i2c_probe(struct i2c_client *client)
return error;
}
- ts->report_data = devm_kmalloc(&client->dev,
- ts->pkg_size, GFP_KERNEL);
- if (!ts->report_data)
- return -ENOMEM;
-
ts->input = devm_input_allocate_device(&client->dev);
if (!ts->input) {
dev_err(&client->dev, "Failed to allocate input device\n");
base-commit: a74c1c7406d06839d0eb15b69bca344e62e729fc
--
2.34.1