From: Dave Stevenson Date: Wed, 8 Sep 2021 13:21:38 +0000 (+0100) Subject: drm/panel/raspberrypi-touchscreen: Handle I2C errors. X-Git-Tag: accepted/tizen/unified/20230118.172025~1082 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5013c6f3d743ec5edc06a5dfa9c8727ca3c917d;p=platform%2Fkernel%2Flinux-rpi.git drm/panel/raspberrypi-touchscreen: Handle I2C errors. rpi_touchscreen_i2c_read returns any errors from i2c_transfer, or the 8 bit received value. Check for error values before trying to process the data as valid. Signed-off-by: Dave Stevenson --- diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c index bd15c2f2e247..329341bcfa50 100644 --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c @@ -296,13 +296,14 @@ static int rpi_touchscreen_noop(struct drm_panel *panel) static int rpi_touchscreen_prepare(struct drm_panel *panel) { struct rpi_touchscreen *ts = panel_to_ts(panel); - int i; + int i, data; rpi_touchscreen_i2c_write(ts, REG_POWERON, 1); usleep_range(20000, 25000); /* Wait for nPWRDWN to go low to indicate poweron is done. */ for (i = 0; i < 100; i++) { - if (rpi_touchscreen_i2c_read(ts, REG_PORTB) & 1) + data = rpi_touchscreen_i2c_read(ts, REG_PORTB); + if (data >= 0 && (data & 1)) break; }