Commit 8d3cefa
i2c: core: Lock address during client device instantiation
Krzysztof reported an issue [0] which is caused by parallel attempts to
instantiate the same I2C client device. This can happen if driver
supports auto-detection, but certain devices are also instantiated
explicitly.
The original change isn't actually wrong, it just revealed that I2C core
isn't prepared yet to handle this scenario.
Calls to i2c_new_client_device() can be nested, therefore we can't use a
simple mutex here. Parallel instantiation of devices at different addresses
is ok, so we just have to prevent parallel instantiation at the same address.
We can use a bitmap with one bit per 7-bit I2C client address, and atomic
bit operations to set/check/clear bits.
Now a parallel attempt to instantiate a device at the same address will
result in -EBUSY being returned, avoiding the "sysfs: cannot create duplicate
filename" splash.
Note: This patch version includes small cosmetic changes to the Tested-by
version, only functional change is that address locking is supported
for slave addresses too.
[0] https://lore.kernel.org/linux-i2c/[email protected]/T/#m12706546e8e2414d8f1a0dc61c53393f731685cc
Fixes: caba40e ("eeprom: at24: Probe for DDR3 thermal sensor in the SPD case")
Cc: [email protected]
Tested-by: Krzysztof Piotr Oledzki <[email protected]>
Signed-off-by: Heiner Kallweit <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>1 parent 3d16973 commit 8d3cefa
2 files changed
+31
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
915 | 915 | | |
916 | 916 | | |
917 | 917 | | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
918 | 939 | | |
919 | 940 | | |
920 | 941 | | |
| |||
962 | 983 | | |
963 | 984 | | |
964 | 985 | | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
965 | 990 | | |
966 | 991 | | |
967 | 992 | | |
| |||
993 | 1018 | | |
994 | 1019 | | |
995 | 1020 | | |
| 1021 | + | |
| 1022 | + | |
996 | 1023 | | |
997 | 1024 | | |
998 | 1025 | | |
| |||
1004 | 1031 | | |
1005 | 1032 | | |
1006 | 1033 | | |
| 1034 | + | |
1007 | 1035 | | |
1008 | 1036 | | |
1009 | 1037 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
761 | 761 | | |
762 | 762 | | |
763 | 763 | | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
764 | 767 | | |
765 | 768 | | |
766 | 769 | | |
| |||
0 commit comments