From 4a82c2a796c710afd1173f88b2f206d9edf244ec Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Dec 2019 21:19:21 -0700 Subject: [PATCH] dm: core: Add a new flag to track platform data We want to avoid allocating platform data twice. This could happen if device_probe() is called after device_ofdata_to_platdata() for the same device. Add a flag to track whether device_ofdata_to_platdata() has been called on a device. Check the flag to make sure it doesn't happen twice, and clear the flag when the data is freed. Change-Id: Idbc90897267890b746858ca01fa5db47e9e6b202 Signed-off-by: Simon Glass --- drivers/core/device-remove.c | 1 + drivers/core/device.c | 4 +++- include/dm/device.h | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 586fadee0a..5540053d3c 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -139,6 +139,7 @@ void device_free(struct udevice *dev) dev->parent_priv = NULL; } } + dev->flags &= ~DM_FLAG_PLATDATA_VALID; devres_release_probe(dev); } diff --git a/drivers/core/device.c b/drivers/core/device.c index 86cd213c33..ace2b1d617 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -315,7 +315,7 @@ int device_ofdata_to_platdata(struct udevice *dev) if (!dev) return -EINVAL; - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev->flags & DM_FLAG_PLATDATA_VALID) return 0; drv = dev->driver; @@ -363,6 +363,8 @@ int device_ofdata_to_platdata(struct udevice *dev) goto fail; } + dev->flags |= DM_FLAG_PLATDATA_VALID; + return 0; fail: device_free(dev); diff --git a/include/dm/device.h b/include/dm/device.h index cd4f477a6e..3deee4e151 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -61,6 +61,12 @@ struct driver_info; */ #define DM_FLAG_OS_PREPARE (1 << 10) +/* DM does not enable/disable the power domains corresponding to this device */ +#define DM_FLAG_DEFAULT_PD_CTRL_OFF (1 << 11) + +/* Driver platdata has been read. Cleared when the device is removed */ +#define DM_FLAG_PLATDATA_VALID (1 << 12) + /* * One or multiple of these flags are passed to device_remove() so that * a selective device removal as specified by the remove-stage and the -- 2.34.1