• Douglas Anderson's avatar
    nvmem: Don't let a NULL cell_id for nvmem_cell_get() crash us · 87ed1405
    Douglas Anderson authored
    In commit ca04d9d3 ("phy: qcom-qusb2: New driver for QUSB2 PHY on
    Qcom chips") you can see a call like:
      devm_nvmem_cell_get(dev, NULL);
    Note that the cell ID passed to the function is NULL.  This is because
    the qcom-qusb2 driver is expected to work only on systems where the
    PHY node is hooked up via device-tree and is nameless.
    This works OK for the most part.  The first thing nvmem_cell_get()
    does is to call of_nvmem_cell_get() and there it's documented that a
    NULL name is fine.  The problem happens when the call to
    of_nvmem_cell_get() returns -EINVAL.  In such a case we'll fall back
    to nvmem_cell_get_from_list() and eventually might (if nvmem_cells
    isn't an empty list) crash with something that looks like:
    There are several different ways we could fix this problem:
    One could argue that perhaps the qcom-qusb2 driver should be changed
    to use of_nvmem_cell_get() which is allowed to have a NULL name.  In
    that case, we'd need to add a patche to introduce
    devm_of_nvmem_cell_get() since the qcom-qusb2 driver is using devm
    managed resources.
    One could also argue that perhaps we could just add a name to
    qcom-qusb2.  That would be OK but I believe it effectively changes the
    device tree bindings, so maybe it's a no-go.
    In this patch I have chosen to fix the problem by simply not crashing
    when a NULL cell_id is passed to nvmem_cell_get().
    NOTE: that for the qcom-qusb2 driver the "nvmem-cells" property is
    defined to be optional and thus it's expected to be a common case that
    we would hit this crash and this is more than just a theoretical fix.
    Fixes: ca04d9d3 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
    Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
    Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Last commit
Last update
Kconfig Loading commit data...
Makefile Loading commit data...
bcm-ocotp.c Loading commit data...
core.c Loading commit data...
imx-iim.c Loading commit data...
imx-ocotp.c Loading commit data...
lpc18xx_eeprom.c Loading commit data...
lpc18xx_otp.c Loading commit data...
meson-efuse.c Loading commit data...
meson-mx-efuse.c Loading commit data...
mtk-efuse.c Loading commit data...
mxs-ocotp.c Loading commit data...
qfprom.c Loading commit data...
rave-sp-eeprom.c Loading commit data...
rockchip-efuse.c Loading commit data...
snvs_lpgpr.c Loading commit data...
sunxi_sid.c Loading commit data...
uniphier-efuse.c Loading commit data...
vf610-ocotp.c Loading commit data...