device: Add checks for NULL in device_const.c functions
This change checks to ensure that device/path passed into any of the functions in device_const.c is not NULL. Since NULL is not expected to be passed into these functions, this change adds a die() call in case the assumption is broken. Change-Id: I1ad8d2bcb9d0546104c5e065af1eeff331cdf96d Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/40475 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
/* This file is part of the coreboot project. */
|
/* This file is part of the coreboot project. */
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <console/console.h>
|
#include <console/console.h>
|
||||||
#include <device/device.h>
|
#include <device/device.h>
|
||||||
#include <device/path.h>
|
#include <device/path.h>
|
||||||
@ -86,6 +87,13 @@ static int path_eq(const struct device_path *path1,
|
|||||||
{
|
{
|
||||||
int equal = 0;
|
int equal = 0;
|
||||||
|
|
||||||
|
if (!path1 || !path2) {
|
||||||
|
assert(path1);
|
||||||
|
assert(path2);
|
||||||
|
/* Return 0 in case assert is considered non-fatal. */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (path1->type != path2->type)
|
if (path1->type != path2->type)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -156,6 +164,13 @@ DEVTREE_CONST struct device *find_dev_path(
|
|||||||
const struct bus *parent, const struct device_path *path)
|
const struct bus *parent, const struct device_path *path)
|
||||||
{
|
{
|
||||||
DEVTREE_CONST struct device *child;
|
DEVTREE_CONST struct device *child;
|
||||||
|
|
||||||
|
if (!parent) {
|
||||||
|
assert(0);
|
||||||
|
/* Return NULL in case asserts are considered non-fatal. */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (child = parent->children; child; child = child->sibling) {
|
for (child = parent->children; child; child = child->sibling) {
|
||||||
if (path_eq(path, &child->path))
|
if (path_eq(path, &child->path))
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user