Skip to content

Commit

Permalink
i2c: core: apply 'is_suspended' check for SMBus, too
Browse files Browse the repository at this point in the history
We checked I2C calls, but not SMBus. Refactor the helper to an inline
function and use it for both, I2C and SMBus.

Fixes: 9ac6cb5 ("i2c: add suspended flag and accessors for i2c adapters")
Reported-by: Peter Rosin <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
Wolfram Sang authored and Wolfram Sang committed May 3, 2019
1 parent 4db61c2 commit 5d75611
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 4 additions & 5 deletions drivers/i2c/i2c-core-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1867,11 +1867,10 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)

if (WARN_ON(!msgs || num < 1))
return -EINVAL;
if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) {
if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags))
dev_WARN(&adap->dev, "Transfer while suspended\n");
return -ESHUTDOWN;
}

ret = __i2c_check_suspended(adap);
if (ret)
return ret;

if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
return -EOPNOTSUPP;
Expand Down
4 changes: 4 additions & 0 deletions drivers/i2c/i2c-core-smbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
int try;
s32 res;

res = __i2c_check_suspended(adapter);
if (res)
return res;

/* If enabled, the following two tracepoints are conditional on
* read_write and protocol.
*/
Expand Down
11 changes: 11 additions & 0 deletions drivers/i2c/i2c-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
return ret;
}

static inline int __i2c_check_suspended(struct i2c_adapter *adap)
{
if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) {
if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags))
dev_WARN(&adap->dev, "Transfer while suspended\n");
return -ESHUTDOWN;
}

return 0;
}

#ifdef CONFIG_ACPI
const struct acpi_device_id *
i2c_acpi_match_device(const struct acpi_device_id *matches,
Expand Down

0 comments on commit 5d75611

Please sign in to comment.