Repository navigation
Commit eaa7995
regulator: core: avoid regulator_resolve_supply() race condition
The final step in regulator_register() is to call
regulator_resolve_supply() for each registered regulator
(including the one in the process of being registered). The
regulator_resolve_supply() function first checks if rdev->supply
is NULL, then it performs various steps to try to find the supply.
If successful, rdev->supply is set inside of set_supply().
This procedure can encounter a race condition if two concurrent
tasks call regulator_register() near to each other on separate CPUs
and one of the regulators has rdev->supply_name specified. There
is currently nothing guaranteeing atomicity between the rdev->supply
check and set steps. Thus, both tasks can observe rdev->supply==NULL
in their regulator_resolve_supply() calls. This then results in
both creating a struct regulator for the supply. One ends up
actually stored in rdev->supply and the other is lost (though still
present in the supply's consumer_list).
Here is a kernel log snippet showing the issue:
[ 12.421768] gpu_cc_gx_gdsc: supplied by pm8350_s5_level
[ 12.425854] gpu_cc_gx_gdsc: supplied by pm8350_s5_level
[ 12.429064] debugfs: Directory 'regulator.4-SUPPLY' with parent
'17a00000.rsc:rpmh-regulator-gfxlvl-pm8350_s5_level'
already present!
Avoid this race condition by holding the rdev->mutex lock inside
of regulator_resolve_supply() while checking and setting
rdev->supply.
Signed-off-by: David Collins <collinsd@codeaurora.org>
Link: https://lore.kernel.org/r/1610068562-4410-1-git-send-email-collinsd@codeaurora.org
Signed-off-by: Mark Brown <broonie@kernel.org>1 parent 36836f5 commit eaa7995
1 file changed
Lines changed: 28 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1813 | 1813 | | |
1814 | 1814 | | |
1815 | 1815 | | |
1816 | | - | |
| 1816 | + | |
1817 | 1817 | | |
1818 | 1818 | | |
1819 | 1819 | | |
1820 | 1820 | | |
1821 | 1821 | | |
1822 | | - | |
| 1822 | + | |
1823 | 1823 | | |
1824 | 1824 | | |
1825 | 1825 | | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
1826 | 1837 | | |
1827 | 1838 | | |
1828 | 1839 | | |
1829 | 1840 | | |
1830 | 1841 | | |
1831 | 1842 | | |
1832 | | - | |
| 1843 | + | |
1833 | 1844 | | |
1834 | 1845 | | |
1835 | 1846 | | |
1836 | 1847 | | |
1837 | 1848 | | |
1838 | 1849 | | |
1839 | 1850 | | |
1840 | | - | |
| 1851 | + | |
| 1852 | + | |
1841 | 1853 | | |
1842 | 1854 | | |
1843 | 1855 | | |
1844 | 1856 | | |
1845 | 1857 | | |
1846 | 1858 | | |
1847 | | - | |
1848 | | - | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
1849 | 1863 | | |
1850 | 1864 | | |
1851 | 1865 | | |
| |||
1859 | 1873 | | |
1860 | 1874 | | |
1861 | 1875 | | |
1862 | | - | |
| 1876 | + | |
| 1877 | + | |
1863 | 1878 | | |
1864 | 1879 | | |
1865 | 1880 | | |
1866 | 1881 | | |
1867 | 1882 | | |
1868 | 1883 | | |
1869 | 1884 | | |
1870 | | - | |
| 1885 | + | |
1871 | 1886 | | |
1872 | 1887 | | |
1873 | 1888 | | |
1874 | 1889 | | |
1875 | 1890 | | |
1876 | | - | |
| 1891 | + | |
1877 | 1892 | | |
1878 | 1893 | | |
1879 | 1894 | | |
| |||
1886 | 1901 | | |
1887 | 1902 | | |
1888 | 1903 | | |
1889 | | - | |
| 1904 | + | |
1890 | 1905 | | |
1891 | 1906 | | |
1892 | 1907 | | |
1893 | | - | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
1894 | 1911 | | |
1895 | 1912 | | |
1896 | 1913 | | |
| |||
0 commit comments