diff mbox series

[1/1] firmware: smci: possible NULL dereference

Message ID 20210201020154.67751-1-xypron.glpk@gmx.de
State Accepted
Commit 6f5edbaf938952e4a9860727c633dcaa36caf699
Delegated to: Simon Glass
Headers show
Series [1/1] firmware: smci: possible NULL dereference | expand

Commit Message

Heinrich Schuchardt Feb. 1, 2021, 2:01 a.m. UTC
sandbox_scmi_devices_ctx() may return NULL. We should not dereference this
value in sandbox_scmi_devices_remove().

The problem was indicated by 'gcc-11 -fanalyzer'.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 drivers/firmware/scmi/sandbox-scmi_devices.c | 3 +++
 1 file changed, 3 insertions(+)

--
2.29.2

Comments

Simon Glass Feb. 1, 2021, 8:44 p.m. UTC | #1
On Sun, 31 Jan 2021 at 19:02, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> sandbox_scmi_devices_ctx() may return NULL. We should not dereference this
> value in sandbox_scmi_devices_remove().
>
> The problem was indicated by 'gcc-11 -fanalyzer'.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  drivers/firmware/scmi/sandbox-scmi_devices.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Feb. 4, 2021, 1:53 a.m. UTC | #2
On Sun, 31 Jan 2021 at 19:02, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> sandbox_scmi_devices_ctx() may return NULL. We should not dereference this
> value in sandbox_scmi_devices_remove().
>
> The problem was indicated by 'gcc-11 -fanalyzer'.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  drivers/firmware/scmi/sandbox-scmi_devices.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/drivers/firmware/scmi/sandbox-scmi_devices.c b/drivers/firmware/scmi/sandbox-scmi_devices.c
index 414da6f4df..1a6fafbf53 100644
--- a/drivers/firmware/scmi/sandbox-scmi_devices.c
+++ b/drivers/firmware/scmi/sandbox-scmi_devices.c
@@ -50,6 +50,9 @@  static int sandbox_scmi_devices_remove(struct udevice *dev)
 	int ret = 0;
 	size_t n;

+	if (!devices)
+		return 0;
+
 	for (n = 0; n < SCMI_TEST_DEVICES_RD_COUNT; n++) {
 		int ret2 = reset_free(devices->reset + n);