Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: stmpe: Check return value of stmpe_reg_read in stmpe_gpio_irq_sync_unlock

The stmpe_reg_read function can fail, but its return value is not checked
in stmpe_gpio_irq_sync_unlock. This can lead to silent failures and
incorrect behavior if the hardware access fails.

This patch adds checks for the return value of stmpe_reg_read. If the
function fails, an error message is logged and the function returns
early to avoid further issues.

Fixes: b888fb6f2a27 ("gpio: stmpe: i2c transfer are forbiden in atomic context")
Cc: stable@vger.kernel.org # 4.16+
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Link: https://lore.kernel.org/r/20250212021849.275-1-vulab@iscas.ac.cn
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Wentao Liang and committed by
Bartosz Golaszewski
b9644fbf 8743d669

+12 -3
+12 -3
drivers/gpio/gpio-stmpe.c
··· 191 191 [REG_IE][CSB] = STMPE_IDX_IEGPIOR_CSB, 192 192 [REG_IE][MSB] = STMPE_IDX_IEGPIOR_MSB, 193 193 }; 194 - int i, j; 194 + int ret, i, j; 195 195 196 196 /* 197 197 * STMPE1600: to be able to get IRQ from pins, ··· 199 199 * GPSR or GPCR registers 200 200 */ 201 201 if (stmpe->partnum == STMPE1600) { 202 - stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_LSB]); 203 - stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_CSB]); 202 + ret = stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_LSB]); 203 + if (ret < 0) { 204 + dev_err(stmpe->dev, "Failed to read GPMR_LSB: %d\n", ret); 205 + goto err; 206 + } 207 + ret = stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_CSB]); 208 + if (ret < 0) { 209 + dev_err(stmpe->dev, "Failed to read GPMR_CSB: %d\n", ret); 210 + goto err; 211 + } 204 212 } 205 213 206 214 for (i = 0; i < CACHE_NR_REGS; i++) { ··· 230 222 } 231 223 } 232 224 225 + err: 233 226 mutex_unlock(&stmpe_gpio->irq_lock); 234 227 } 235 228