Skip to content

Commit 611e12e

Browse files
Vladimir ZapolskiyWolfram Sang
authored andcommitted
i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter
In addition to module_get()/module_put() add get_device()/put_device() calls into i2c_get_adapter()/i2c_put_adapter() exported interfaces. This is done to lock I2C bus device, if it is in use by a client. Signed-off-by: Vladimir Zapolskiy <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 141124e commit 611e12e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/i2c/i2c-core.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,18 +2413,27 @@ struct i2c_adapter *i2c_get_adapter(int nr)
24132413

24142414
mutex_lock(&core_lock);
24152415
adapter = idr_find(&i2c_adapter_idr, nr);
2416-
if (adapter && !try_module_get(adapter->owner))
2416+
if (!adapter)
2417+
goto exit;
2418+
2419+
if (try_module_get(adapter->owner))
2420+
get_device(&adapter->dev);
2421+
else
24172422
adapter = NULL;
24182423

2424+
exit:
24192425
mutex_unlock(&core_lock);
24202426
return adapter;
24212427
}
24222428
EXPORT_SYMBOL(i2c_get_adapter);
24232429

24242430
void i2c_put_adapter(struct i2c_adapter *adap)
24252431
{
2426-
if (adap)
2427-
module_put(adap->owner);
2432+
if (!adap)
2433+
return;
2434+
2435+
put_device(&adap->dev);
2436+
module_put(adap->owner);
24282437
}
24292438
EXPORT_SYMBOL(i2c_put_adapter);
24302439

0 commit comments

Comments
 (0)