Skip to content

Commit 6b238b3

Browse files
author
Wolfram Sang
committed
i2c: testunit: improve error handling for GPIO
Bail out in probe if getting the optional GPIO returns an error. Bail out in the test early if the optional GPIO is not present, otherwise the timeout errno is misleading. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent 8cf0b93 commit 6b238b3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/i2c/i2c-slave-testunit.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ static void i2c_slave_testunit_work(struct work_struct *work)
183183
break;
184184

185185
case TU_CMD_SMBUS_ALERT_REQUEST:
186+
if (!tu->gpio) {
187+
ret = -ENOENT;
188+
break;
189+
}
186190
i2c_slave_unregister(tu->client);
187191
orig_addr = tu->client->addr;
188192
tu->client->addr = 0x0c;
@@ -232,6 +236,9 @@ static int i2c_slave_testunit_probe(struct i2c_client *client)
232236
INIT_DELAYED_WORK(&tu->worker, i2c_slave_testunit_work);
233237

234238
tu->gpio = devm_gpiod_get_index_optional(&client->dev, NULL, 0, GPIOD_OUT_LOW);
239+
if (IS_ERR(tu->gpio))
240+
return PTR_ERR(tu->gpio);
241+
235242
if (gpiod_cansleep(tu->gpio)) {
236243
dev_err(&client->dev, "GPIO access which may sleep is not allowed\n");
237244
return -EDEADLK;

0 commit comments

Comments
 (0)