diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2024-09-09 12:14:50 +0200 |
---|---|---|
committer | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2024-10-08 10:15:42 +0200 |
commit | 6b238b3c45eb67d3083d55dc17463d1f43e002a7 (patch) | |
tree | 4ffe52653646a715f17067c6bdfe09aef8a2b0ff | |
parent | 8cf0b93919e13d1e8d4466eb4080a4c4d9d66d7b (diff) |
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>
-rw-r--r-- | drivers/i2c/i2c-slave-testunit.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-slave-testunit.c b/drivers/i2c/i2c-slave-testunit.c index 9fe3150378e8..0d6fbaa48248 100644 --- a/drivers/i2c/i2c-slave-testunit.c +++ b/drivers/i2c/i2c-slave-testunit.c @@ -183,6 +183,10 @@ static void i2c_slave_testunit_work(struct work_struct *work) break; case TU_CMD_SMBUS_ALERT_REQUEST: + if (!tu->gpio) { + ret = -ENOENT; + break; + } i2c_slave_unregister(tu->client); orig_addr = tu->client->addr; tu->client->addr = 0x0c; @@ -232,6 +236,9 @@ static int i2c_slave_testunit_probe(struct i2c_client *client) INIT_DELAYED_WORK(&tu->worker, i2c_slave_testunit_work); tu->gpio = devm_gpiod_get_index_optional(&client->dev, NULL, 0, GPIOD_OUT_LOW); + if (IS_ERR(tu->gpio)) + return PTR_ERR(tu->gpio); + if (gpiod_cansleep(tu->gpio)) { dev_err(&client->dev, "GPIO access which may sleep is not allowed\n"); return -EDEADLK; |