[PATCH v2 1/3] misc: open-dice: do not assume dev->of_node is valid

From: Song Guo

Date: Wed Jul 15 2026 - 08:26:12 EST


dev->of_node is not null only when the device is configured via device
tree. When the matching device is configured by other means (like ACPI),
the current code will cause null pointer dereference.

Signed-off-by: Song Guo <songguo@xxxxxxxxxx>
---
drivers/misc/open-dice.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/open-dice.c b/drivers/misc/open-dice.c
index 45060fb4ea27..094b24dfc6ea 100644
--- a/drivers/misc/open-dice.c
+++ b/drivers/misc/open-dice.c
@@ -118,13 +118,18 @@ static int __init open_dice_probe(struct platform_device *pdev)
{
static unsigned int dev_idx;
struct device *dev = &pdev->dev;
- struct reserved_mem *rmem;
+ struct reserved_mem *rmem = NULL;
struct open_dice_drvdata *drvdata;
int ret;

- rmem = of_reserved_mem_lookup(dev->of_node);
- if (!rmem) {
- dev_err(dev, "failed to lookup reserved memory\n");
+ if (dev->of_node) {
+ rmem = of_reserved_mem_lookup(dev->of_node);
+ if (!rmem) {
+ dev_err(dev, "failed to lookup reserved memory\n");
+ return -EINVAL;
+ }
+ } else {
+ dev_err(dev, "device not supported (no DT node)\n");
return -EINVAL;
}

--
2.55.0.141.g00534a21ce-goog