* [PATCH] HID: mcp2221: Keep IIO initialization retries per device
@ 2026-11-13 1:40 tuhaowen
2026-11-13 1:45 ` sashiko-bot
2026-11-13 1:55 ` [PATCH v2] " Haowen Tu
0 siblings, 2 replies; 3+ messages in thread
From: tuhaowen @ 2026-11-13 1:40 UTC (permalink / raw)
To: gupt21; +Cc: jikos, bentiss, linux-i2c, linux-input, linux-kernel, tuhaowen
mcp_init_work() uses a static retry counter, so all MCP2221 devices share
the same retry budget. Initializing one device can exhaust the retries
available to another device, including a new instance after unplugging
and reconnecting the bridge.
When the counter reaches zero, the post-decrement also changes it to -1.
A subsequent instance that receives -EAGAIN will then keep rescheduling
its initialization work instead of stopping at the intended limit.
Different devices can also update the shared counter concurrently.
Store the retry budget in struct mcp2221 and initialize it before queuing
the IIO initialization work. Check for exhaustion before decrementing so
the counter stays at zero once the retry limit is reached.
Fixes: 960f9df7c620 ("HID: mcp2221: add ADC/DAC support via iio subsystem")
Signed-off-by: tuhaowen <tuhaowen@uniontech.com>
---
drivers/hid/hid-mcp2221.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 3f05d6e288f9..f8f4788ba935 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -136,6 +136,7 @@ struct mcp2221 {
u8 gpio_dir;
u8 mode[4];
#if IS_REACHABLE(CONFIG_IIO)
+ unsigned int iio_init_retries;
struct iio_chan_spec iio_channels[3];
u16 adc_values[3];
u8 adc_scale;
@@ -1190,7 +1191,6 @@ static void mcp_init_work(struct work_struct *work)
struct iio_dev *indio_dev;
struct mcp2221 *mcp = container_of(work, struct mcp2221, init_work.work);
struct mcp2221_iio *data;
- static int retries = 5;
int ret, num_channels;
hid_hw_power(mcp->hdev, PM_HINT_FULLON);
@@ -1238,8 +1238,9 @@ static void mcp_init_work(struct work_struct *work)
mutex_unlock(&mcp->lock);
hid_hw_power(mcp->hdev, PM_HINT_NORMAL);
- if (!retries--)
+ if (!mcp->iio_init_retries)
return;
+ mcp->iio_init_retries--;
/* Device is not ready to read SRAM or FLASH data, try again */
schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100));
@@ -1346,6 +1347,7 @@ static int mcp2221_probe(struct hid_device *hdev,
#endif
#if IS_REACHABLE(CONFIG_IIO)
+ mcp->iio_init_retries = 5;
INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work);
if (!gpio_mode_enforce)
schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100));
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: mcp2221: Keep IIO initialization retries per device
2026-11-13 1:40 [PATCH] HID: mcp2221: Keep IIO initialization retries per device tuhaowen
@ 2026-11-13 1:45 ` sashiko-bot
2026-11-13 1:55 ` [PATCH v2] " Haowen Tu
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-13 1:45 UTC (permalink / raw)
To: tuhaowen; +Cc: linux-input, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] HID: mcp2221: Signed-off-by and Author use account handle
instead of real name
--
commit 0750e741db2254c14f91e93fd256287b28060c69
Author: tuhaowen <tuhaowen@uniontech.com>
> HID: mcp2221: Keep IIO initialization retries per device
>
> mcp_init_work() uses a static retry counter, so all MCP2221 devices share
> the same retry budget. Initializing one device can exhaust the retries
> available to another device, including a new instance after unplugging
> and reconnecting the bridge.
>
> When the counter reaches zero, the post-decrement also changes it to -1.
> A subsequent instance that receives -EAGAIN will then keep rescheduling
> its initialization work instead of stopping at the intended limit.
> Different devices can also update the shared counter concurrently.
>
> Store the retry budget in struct mcp2221 and initialize it before queuing
> the IIO initialization work. Check for exhaustion before decrementing so
> the counter stays at zero once the retry limit is reached.
>
> Fixes: 960f9df7c620 ("HID: mcp2221: add ADC/DAC support via iio subsystem")
> Signed-off-by: tuhaowen <tuhaowen@uniontech.com>
[Severity: High]
The Author header and Signed-off-by trailer use the single-word account
handle "tuhaowen" instead of a full real name, which does not meet the
Developer's Certificate of Origin requirements in
Documentation/process/submitting-patches.rst.
--
Sashiko AI review · https://sashiko.dev/#/patchset/4861CDE55CCD8365+20261113014036.1430473-1-tuhaowen@uniontech.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] HID: mcp2221: Keep IIO initialization retries per device
2026-11-13 1:40 [PATCH] HID: mcp2221: Keep IIO initialization retries per device tuhaowen
2026-11-13 1:45 ` sashiko-bot
@ 2026-11-13 1:55 ` Haowen Tu
1 sibling, 0 replies; 3+ messages in thread
From: Haowen Tu @ 2026-11-13 1:55 UTC (permalink / raw)
To: gupt21
Cc: jikos, bentiss, dmitry.torokhov, linux-i2c, linux-input,
linux-kernel, Haowen Tu
mcp_init_work() uses a static retry counter, so all MCP2221 devices share
the same retry budget. Initializing one device can exhaust the retries
available to another device, including a new instance after unplugging
and reconnecting the bridge.
When the counter reaches zero, the post-decrement also changes it to -1.
A subsequent instance that receives -EAGAIN will then keep rescheduling
its initialization work instead of stopping at the intended limit.
Different devices can also update the shared counter concurrently.
Store the retry budget in struct mcp2221 and initialize it before queuing
the IIO initialization work. Check for exhaustion before decrementing so
the counter stays at zero once the retry limit is reached.
Fixes: 960f9df7c620 ("HID: mcp2221: add ADC/DAC support via iio subsystem")
Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
Changes in v2:
- Correct the author's name and Signed-off-by to Haowen Tu.
- No code changes.
v1: https://lore.kernel.org/all/4861CDE55CCD8365+20261113014036.1430473-1-tuhaowen@uniontech.com/
drivers/hid/hid-mcp2221.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 3f05d6e288f9..f8f4788ba935 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -136,6 +136,7 @@ struct mcp2221 {
u8 gpio_dir;
u8 mode[4];
#if IS_REACHABLE(CONFIG_IIO)
+ unsigned int iio_init_retries;
struct iio_chan_spec iio_channels[3];
u16 adc_values[3];
u8 adc_scale;
@@ -1190,7 +1191,6 @@ static void mcp_init_work(struct work_struct *work)
struct iio_dev *indio_dev;
struct mcp2221 *mcp = container_of(work, struct mcp2221, init_work.work);
struct mcp2221_iio *data;
- static int retries = 5;
int ret, num_channels;
hid_hw_power(mcp->hdev, PM_HINT_FULLON);
@@ -1238,8 +1238,9 @@ static void mcp_init_work(struct work_struct *work)
mutex_unlock(&mcp->lock);
hid_hw_power(mcp->hdev, PM_HINT_NORMAL);
- if (!retries--)
+ if (!mcp->iio_init_retries)
return;
+ mcp->iio_init_retries--;
/* Device is not ready to read SRAM or FLASH data, try again */
schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100));
@@ -1346,6 +1347,7 @@ static int mcp2221_probe(struct hid_device *hdev,
#endif
#if IS_REACHABLE(CONFIG_IIO)
+ mcp->iio_init_retries = 5;
INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work);
if (!gpio_mode_enforce)
schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100));
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-13 1:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 1:40 [PATCH] HID: mcp2221: Keep IIO initialization retries per device tuhaowen
2026-11-13 1:45 ` sashiko-bot
2026-11-13 1:55 ` [PATCH v2] " Haowen Tu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.