1
0
Fork 0
remarkable-linux/drivers/nvmem
Douglas Anderson 1b8f1ab088 nvmem: Don't let a NULL cell_id for nvmem_cell_get() crash us
[ Upstream commit 87ed1405ef ]

In commit ca04d9d3e1 ("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:

 strcmp
 nvmem_find_cell
 __nvmem_device_get
 nvmem_cell_get_from_list
 nvmem_cell_get
 devm_nvmem_cell_get
 qusb2_phy_probe

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: ca04d9d3e1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-08-24 13:09:14 +02:00
..
Kconfig nvmem: Add driver for the i.MX IIM 2017-04-08 17:51:48 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
bcm-ocotp.c nvmem: correct Broadcom OTP controller driver writes 2017-06-09 12:08:27 +02:00
core.c nvmem: Don't let a NULL cell_id for nvmem_cell_get() crash us 2018-08-24 13:09:14 +02:00
imx-iim.c nvmem: Add driver for the i.MX IIM 2017-04-08 17:51:48 +02:00
imx-ocotp.c nvmem: imx-ocotp: add write support 2017-04-08 17:51:48 +02:00
lpc18xx_eeprom.c nvmem: lpc18xx-eeprom: explicitly request exclusive reset control 2017-08-28 17:33:22 +02:00
lpc18xx_otp.c nvmem: add NXP LPC18xx OTP driver 2016-11-10 15:34:55 +01:00
meson-efuse.c firmware: meson-sm: Check for buffer output size 2017-03-23 12:22:32 -07:00
mtk-efuse.c nvmem: mtk-efuse: remove nvmem regmap dependency 2016-06-25 07:42:55 -07:00
mxs-ocotp.c nvmem: mxs-ocotp: remove nvmem regmap dependency 2016-06-25 07:42:55 -07:00
qfprom.c nvmem: qfprom: Allow single byte accesses for read/write 2017-01-04 18:22:47 +01:00
rockchip-efuse.c nvmem: rockchip-efuse: amend compatible rk322x-efuse to rk3228-efuse 2017-07-17 16:15:57 +02:00
sunxi_sid.c nvmem: sunxi-sid: add support for H3's SID controller 2017-04-08 17:51:48 +02:00
vf610-ocotp.c nvmem: vif610-ocotp: remove nvmem regmap dependency 2016-05-01 14:01:00 -07:00