From 8b6d35a41d96ba0ecdc30fe8b7a0892625fbb609 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:36 -0700 Subject: [PATCH] dm: core: Use const where possible in device.h Update this header file to use const devices where possible, to permit callers to also use const. Signed-off-by: Simon Glass Conflicts: drivers/core/device.c include/dm/device.h [backport of mainline commit fc347fbdd44a01b1aba6283dec56c1374baca383] Signed-off-by: Marek Szyprowski Change-Id: Id883506ac5c20ae7898c576316b64e64a9a52c90 --- drivers/core/device.c | 25 +++++++++++++------------ include/dm/device.h | 28 +++++++++++++++------------- include/dm/read.h | 4 ++-- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 05dadf9..b46af87 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -555,7 +555,8 @@ static int device_find_by_ofnode(ofnode node, struct udevice **devp) } #endif -int device_get_child(struct udevice *parent, int index, struct udevice **devp) +int device_get_child(const struct udevice *parent, int index, + struct udevice **devp) { struct udevice *dev; @@ -567,7 +568,7 @@ int device_get_child(struct udevice *parent, int index, struct udevice **devp) return -ENODEV; } -int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, +int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { struct udevice *dev; @@ -587,7 +588,7 @@ int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, return -ENODEV; } -int device_get_child_by_seq(struct udevice *parent, int seq, +int device_get_child_by_seq(const struct udevice *parent, int seq, struct udevice **devp) { struct udevice *dev; @@ -605,7 +606,7 @@ int device_get_child_by_seq(struct udevice *parent, int seq, return device_get_device_tail(dev, ret, devp); } -int device_find_child_by_of_offset(struct udevice *parent, int of_offset, +int device_find_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp) { struct udevice *dev; @@ -622,7 +623,7 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset, return -ENODEV; } -int device_get_child_by_of_offset(struct udevice *parent, int node, +int device_get_child_by_of_offset(const struct udevice *parent, int node, struct udevice **devp) { struct udevice *dev; @@ -665,7 +666,7 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp) return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); } -int device_find_first_child(struct udevice *parent, struct udevice **devp) +int device_find_first_child(const struct udevice *parent, struct udevice **devp) { if (list_empty(&parent->child_head)) { *devp = NULL; @@ -692,7 +693,7 @@ int device_find_next_child(struct udevice **devp) return 0; } -int device_find_first_inactive_child(struct udevice *parent, +int device_find_first_inactive_child(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp) { @@ -710,7 +711,7 @@ int device_find_first_inactive_child(struct udevice *parent, return -ENODEV; } -int device_find_first_child_by_uclass(struct udevice *parent, +int device_find_first_child_by_uclass(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp) { @@ -727,7 +728,7 @@ int device_find_first_child_by_uclass(struct udevice *parent, return -ENODEV; } -int device_find_child_by_name(struct udevice *parent, const char *name, +int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp) { struct udevice *dev; @@ -780,7 +781,7 @@ bool device_has_children(const struct udevice *dev) return !list_empty(&dev->child_head); } -bool device_has_active_children(struct udevice *dev) +bool device_has_active_children(const struct udevice *dev) { struct udevice *child; @@ -794,7 +795,7 @@ bool device_has_active_children(struct udevice *dev) return false; } -bool device_is_last_sibling(struct udevice *dev) +bool device_is_last_sibling(const struct udevice *dev) { struct udevice *parent = dev->parent; @@ -820,7 +821,7 @@ int device_set_name(struct udevice *dev, const char *name) } #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) -bool device_is_compatible(struct udevice *dev, const char *compat) +bool device_is_compatible(const struct udevice *dev, const char *compat) { return ofnode_device_is_compatible(dev_ofnode(dev), compat); } diff --git a/include/dm/device.h b/include/dm/device.h index 27a6d7b..cd4f477 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -402,7 +402,8 @@ const char *dev_get_uclass_name(const struct udevice *dev); * @return 0 if OK, -ENODEV if no such device, other error if the device fails * to probe */ -int device_get_child(struct udevice *parent, int index, struct udevice **devp); +int device_get_child(const struct udevice *parent, int index, + struct udevice **devp); /** * device_find_child_by_seq() - Find a child device based on a sequence @@ -423,7 +424,7 @@ int device_get_child(struct udevice *parent, int index, struct udevice **devp); * Set to NULL if none is found * @return 0 if OK, -ve on error */ -int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, +int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, bool find_req_seq, struct udevice **devp); /** @@ -441,7 +442,7 @@ int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, * Set to NULL if none is found * @return 0 if OK, -ve on error */ -int device_get_child_by_seq(struct udevice *parent, int seq, +int device_get_child_by_seq(const struct udevice *parent, int seq, struct udevice **devp); /** @@ -454,7 +455,7 @@ int device_get_child_by_seq(struct udevice *parent, int seq, * @devp: Returns pointer to device if found, otherwise this is set to NULL * @return 0 if OK, -ve on error */ -int device_find_child_by_of_offset(struct udevice *parent, int of_offset, +int device_find_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp); /** @@ -469,7 +470,7 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset, * @devp: Returns pointer to device if found, otherwise this is set to NULL * @return 0 if OK, -ve on error */ -int device_get_child_by_of_offset(struct udevice *parent, int of_offset, +int device_get_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp); /** @@ -508,7 +509,8 @@ int device_get_global_by_ofnode(ofnode node, struct udevice **devp); * @devp: Returns first child device, or NULL if none * @return 0 */ -int device_find_first_child(struct udevice *parent, struct udevice **devp); +int device_find_first_child(const struct udevice *parent, + struct udevice **devp); /** * device_find_next_child() - Find the next child of a device @@ -532,7 +534,7 @@ int device_find_next_child(struct udevice **devp); * @devp: Returns device found, if any * @return 0 if found, else -ENODEV */ -int device_find_first_inactive_child(struct udevice *parent, +int device_find_first_inactive_child(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp); @@ -544,7 +546,7 @@ int device_find_first_inactive_child(struct udevice *parent, * @devp: Returns first child device in that uclass, if any * @return 0 if found, else -ENODEV */ -int device_find_first_child_by_uclass(struct udevice *parent, +int device_find_first_child_by_uclass(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp); @@ -556,7 +558,7 @@ int device_find_first_child_by_uclass(struct udevice *parent, * @devp: Returns device found, if any * @return 0 if found, else -ENODEV */ -int device_find_child_by_name(struct udevice *parent, const char *name, +int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp); /** @@ -574,7 +576,7 @@ bool device_has_children(const struct udevice *dev); * @return true if the device has one or more children and at least one of * them is active (probed). */ -bool device_has_active_children(struct udevice *dev); +bool device_has_active_children(const struct udevice *dev); /** * device_is_last_sibling() - check if a device is the last sibling @@ -587,7 +589,7 @@ bool device_has_active_children(struct udevice *dev); * @return true if there are no more siblings after this one - i.e. is it * last in the list. */ -bool device_is_last_sibling(struct udevice *dev); +bool device_is_last_sibling(const struct udevice *dev); /** * device_set_name() - set the name of a device @@ -627,7 +629,7 @@ void device_set_name_alloced(struct udevice *dev); * device * @return true if OK, false if the compatible is not found */ -bool device_is_compatible(struct udevice *dev, const char *compat); +bool device_is_compatible(const struct udevice *dev, const char *compat); /** * of_machine_is_compatible() - check if the machine is compatible with @@ -662,7 +664,7 @@ int dev_enable_by_path(const char *path); * @dev: device to test * @return: true if it is on a PCI bus, false otherwise */ -static inline bool device_is_on_pci_bus(struct udevice *dev) +static inline bool device_is_on_pci_bus(const struct udevice *dev) { return device_get_uclass_id(dev->parent) == UCLASS_PCI; } diff --git a/include/dm/read.h b/include/dm/read.h index 803daf7..70ce41b 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -33,12 +33,12 @@ static inline const struct device_node *dev_np(struct udevice *dev) * @dev: device to check * @return reference of the the device's DT node */ -static inline ofnode dev_ofnode(struct udevice *dev) +static inline ofnode dev_ofnode(const struct udevice *dev) { return dev->node; } -static inline bool dev_of_valid(struct udevice *dev) +static inline bool dev_of_valid(const struct udevice *dev) { return ofnode_valid(dev_ofnode(dev)); } -- 2.7.4