diff options
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 2f0bc9529376..d16b4998c4c2 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -419,8 +419,7 @@ int i2c_attach_client(struct i2c_client *client) | |||
419 | } | 419 | } |
420 | } | 420 | } |
421 | 421 | ||
422 | if (client->flags & I2C_CLIENT_ALLOW_USE) | 422 | client->usage_count = 0; |
423 | client->usage_count = 0; | ||
424 | 423 | ||
425 | client->dev.parent = &client->adapter->dev; | 424 | client->dev.parent = &client->adapter->dev; |
426 | client->dev.driver = &client->driver->driver; | 425 | client->dev.driver = &client->driver->driver; |
@@ -443,8 +442,7 @@ int i2c_detach_client(struct i2c_client *client) | |||
443 | struct i2c_adapter *adapter = client->adapter; | 442 | struct i2c_adapter *adapter = client->adapter; |
444 | int res = 0; | 443 | int res = 0; |
445 | 444 | ||
446 | if ((client->flags & I2C_CLIENT_ALLOW_USE) | 445 | if (client->usage_count > 0) { |
447 | && (client->usage_count > 0)) { | ||
448 | dev_warn(&client->dev, "Client [%s] still busy, " | 446 | dev_warn(&client->dev, "Client [%s] still busy, " |
449 | "can't detach\n", client->name); | 447 | "can't detach\n", client->name); |
450 | return -EBUSY; | 448 | return -EBUSY; |
@@ -499,12 +497,9 @@ int i2c_use_client(struct i2c_client *client) | |||
499 | if (ret) | 497 | if (ret) |
500 | return ret; | 498 | return ret; |
501 | 499 | ||
502 | if (client->flags & I2C_CLIENT_ALLOW_USE) { | 500 | if (client->usage_count > 0) |
503 | if (client->usage_count > 0) | 501 | goto busy; |
504 | goto busy; | 502 | client->usage_count++; |
505 | else | ||
506 | client->usage_count++; | ||
507 | } | ||
508 | 503 | ||
509 | return 0; | 504 | return 0; |
510 | busy: | 505 | busy: |
@@ -514,16 +509,13 @@ int i2c_use_client(struct i2c_client *client) | |||
514 | 509 | ||
515 | int i2c_release_client(struct i2c_client *client) | 510 | int i2c_release_client(struct i2c_client *client) |
516 | { | 511 | { |
517 | if(client->flags & I2C_CLIENT_ALLOW_USE) { | 512 | if (!client->usage_count) { |
518 | if(client->usage_count>0) | 513 | pr_debug("i2c-core: %s used one too many times\n", |
519 | client->usage_count--; | 514 | __FUNCTION__); |
520 | else { | 515 | return -EPERM; |
521 | pr_debug("i2c-core: %s used one too many times\n", | ||
522 | __FUNCTION__); | ||
523 | return -EPERM; | ||
524 | } | ||
525 | } | 516 | } |
526 | 517 | ||
518 | client->usage_count--; | ||
527 | i2c_dec_use_client(client); | 519 | i2c_dec_use_client(client); |
528 | 520 | ||
529 | return 0; | 521 | return 0; |