All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH 12/19] dm: core: Add a new flag to track platform data
Date: Sun, 29 Dec 2019 21:19:21 -0700	[thread overview]
Message-ID: <20191229211913.12.Iaee21ff41733fc4ee01284e3a7ca6f57874a1a1b@changeid> (raw)
In-Reply-To: <20191230041928.74874-1-sjg@chromium.org>

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.

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

 drivers/core/device-remove.c | 1 +
 drivers/core/device.c        | 4 +++-
 include/dm/device.h          | 3 +++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 5c8dc4ad70..444e34b492 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -140,6 +140,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 9506c7df8d..9f39218423 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -320,7 +320,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;
@@ -368,6 +368,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 21774708e7..9ebfd0a34e 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -65,6 +65,9 @@ struct driver_info;
 /* 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.24.1.735.g03f4e72817-goog

  parent reply	other threads:[~2019-12-30  4:19 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30  4:19 [PATCH 00/19] dm: core: Fully separate ofdata_to_platdata() from probe() Simon Glass
2019-12-30  4:19 ` [PATCH 01/19] common: Add a noisy assert() Simon Glass
2019-12-30  4:19 ` [PATCH 02/19] dm: core: Use assert_noisy() in devres Simon Glass
2019-12-30  4:19 ` [PATCH 03/19] usb: Drop use of BUG_ON() and WARN_ON() Simon Glass
2019-12-30  4:19 ` [PATCH 04/19] x86: apl: Avoid accessing the PCI bus before it is probed Simon Glass
2019-12-30  4:19 ` [PATCH 05/19] pci: Print a warning if the bus is accessed before probing Simon Glass
2019-12-30  4:19 ` [PATCH 06/19] aspeed: ast2500: Read clock ofdata in the correct method Simon Glass
2020-01-07  8:20   ` Cédric Le Goater
2020-01-09 20:04     ` Simon Glass
2020-01-10  8:57     ` sjg at google.com
2019-12-30  4:19 ` [PATCH 07/19] dm: core: Don't clear active flag twice when probe() fails Simon Glass
2019-12-30  4:19 ` [PATCH 08/19] dm: core: Move ofdata_to_platdata() call earlier Simon Glass
2019-12-30  4:19 ` [PATCH 09/19] dm: core: Allocate parent data separate from probing parent Simon Glass
2019-12-30  4:19 ` [PATCH 10/19] dm: core: Add a comment for DM_FLAG_OF_PLATDATA Simon Glass
2019-12-30  4:19 ` [PATCH 11/19] dm: core: Export a new function to read platdata Simon Glass
2019-12-30  4:19 ` Simon Glass [this message]
2019-12-30  4:19 ` [PATCH 13/19] dm: devres: Create a new devres header file Simon Glass
2019-12-30  4:19 ` [PATCH 14/19] test: Add functions to find the amount of allocated memory Simon Glass
2019-12-30  4:19 ` [PATCH 15/19] dm: devres: Convert to use logging Simon Glass
2019-12-30  4:19 ` [PATCH 16/19] dm: test: Add a test driver for devres Simon Glass
2019-12-30  4:19 ` [PATCH 17/19] dm: devres: Add tests Simon Glass
2019-12-30  4:19 ` [PATCH 18/19] dm: devres: Use an enum for the allocation phase Simon Glass
2019-12-30  4:19 ` [PATCH 19/19] dm: devres: Add a new OFDATA phase Simon Glass
2020-01-10  8:57 ` [PATCH 18/19] dm: devres: Use an enum for the allocation phase sjg at google.com
2020-01-10  8:57 ` [PATCH 19/19] dm: devres: Add a new OFDATA phase sjg at google.com
2020-01-10  8:57 ` [PATCH 17/19] dm: devres: Add tests sjg at google.com
2020-01-10  8:57 ` [PATCH 16/19] dm: test: Add a test driver for devres sjg at google.com
2020-01-10  8:57 ` [PATCH 14/19] test: Add functions to find the amount of allocated memory sjg at google.com
2020-01-10  8:57 ` [PATCH 15/19] dm: devres: Convert to use logging sjg at google.com
2020-01-10  8:57 ` [PATCH 13/19] dm: devres: Create a new devres header file sjg at google.com
2020-01-10  8:57 ` [PATCH 12/19] dm: core: Add a new flag to track platform data sjg at google.com
2020-01-10  8:57 ` [PATCH 11/19] dm: core: Export a new function to read platdata sjg at google.com
2020-01-10  8:57 ` [PATCH 10/19] dm: core: Add a comment for DM_FLAG_OF_PLATDATA sjg at google.com
2020-01-10  8:57 ` [PATCH 09/19] dm: core: Allocate parent data separate from probing parent sjg at google.com
2020-01-10  8:57 ` [PATCH 08/19] dm: core: Move ofdata_to_platdata() call earlier sjg at google.com
2020-01-10  8:57 ` [PATCH 07/19] dm: core: Don't clear active flag twice when probe() fails sjg at google.com
2020-01-10  8:57 ` [PATCH 05/19] pci: Print a warning if the bus is accessed before probing sjg at google.com
2020-01-10  8:57 ` [PATCH 04/19] x86: apl: Avoid accessing the PCI bus before it is probed sjg at google.com
2020-01-10  8:57 ` [PATCH 03/19] usb: Drop use of BUG_ON() and WARN_ON() sjg at google.com
2020-01-10  8:57 ` [PATCH 02/19] dm: core: Use assert_noisy() in devres sjg at google.com
2020-01-10  8:57 ` [PATCH 01/19] common: Add a noisy assert() sjg at google.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191229211913.12.Iaee21ff41733fc4ee01284e3a7ca6f57874a1a1b@changeid \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.