• Johan Hovold's avatar
    mfd: qcom-spmi-pmic: Fix reference leaks in revid helper · a0fa44c2
    Johan Hovold authored
    The Qualcomm SPMI PMIC revid implementation is broken in multiple ways.
    
    First, it totally ignores struct device_node reference counting and
    leaks references to the parent bus node as well as each child it
    iterates over using an open-coded for_each_child_of_node().
    
    Second, it leaks references to each spmi device on the bus that it
    iterates over by failing to drop the reference taken by the
    spmi_device_from_of() helper.
    
    Fix the struct device_node leaks by reimplementing the lookup using
    for_each_child_of_node() and adding the missing reference count
    decrements. Fix the sibling struct device leaks by dropping the
    unnecessary lookups of devices with the wrong USID.
    
    Note that this still leaves one struct device reference leak in case a
    base device is found but it is not the parent of the device used for the
    lookup. This will be addressed in a follow-on patch.
    
    Fixes: e9c11c6e ("mfd: qcom-spmi-pmic: expose the PMIC revid information to clients")
    Cc: stable@vger.kernel.org	# 6.0
    Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
    Acked-by: default avatarCaleb Connolly <caleb.connolly@linaro.org>
    Link: https://lore.kernel.org/r/20231003152927.15000-2-johan+linaro@kernel.orgSigned-off-by: default avatarLee Jones <lee@kernel.org>
    a0fa44c2
qcom-spmi-pmic.c 7.48 KB