aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>2016-04-27 07:04:20 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-04-27 17:40:02 -0400
commit0224a4a30b57385a60065aa598181868881d8fc6 (patch)
treed1cc248a6c1f86a23977e18cf35586315f4a0704
parent02da2d72174c61988eb4456b53f405e3ebdebce4 (diff)
device property: Avoid potential dereferences of invalid pointers
Since fwnode may hold ERR_PTR(-ENODEV) or it may be NULL, the fwnode type checks is_of_node(), is_acpi_node() and is is_pset_node() need to consider it. Using IS_ERR_OR_NULL() to check it. Fixes: 0d67e0fa1664 (device property: fix for a case of use-after-free) Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> [ rjw: Subject & changelog ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/base/property.c2
-rw-r--r--include/acpi/acpi_bus.h4
-rw-r--r--include/linux/of.h2
3 files changed, 4 insertions, 4 deletions
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 9b1a65debd49..7f692accdc90 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -21,7 +21,7 @@
21 21
22static inline bool is_pset_node(struct fwnode_handle *fwnode) 22static inline bool is_pset_node(struct fwnode_handle *fwnode)
23{ 23{
24 return fwnode && fwnode->type == FWNODE_PDATA; 24 return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_PDATA;
25} 25}
26 26
27static inline struct property_set *to_pset_node(struct fwnode_handle *fwnode) 27static inline struct property_set *to_pset_node(struct fwnode_handle *fwnode)
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 14362a84c78e..3a932501d690 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -394,13 +394,13 @@ struct acpi_data_node {
394 394
395static inline bool is_acpi_node(struct fwnode_handle *fwnode) 395static inline bool is_acpi_node(struct fwnode_handle *fwnode)
396{ 396{
397 return fwnode && (fwnode->type == FWNODE_ACPI 397 return !IS_ERR_OR_NULL(fwnode) && (fwnode->type == FWNODE_ACPI
398 || fwnode->type == FWNODE_ACPI_DATA); 398 || fwnode->type == FWNODE_ACPI_DATA);
399} 399}
400 400
401static inline bool is_acpi_device_node(struct fwnode_handle *fwnode) 401static inline bool is_acpi_device_node(struct fwnode_handle *fwnode)
402{ 402{
403 return fwnode && fwnode->type == FWNODE_ACPI; 403 return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_ACPI;
404} 404}
405 405
406static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode) 406static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
diff --git a/include/linux/of.h b/include/linux/of.h
index 7fcb681baadf..31758036787c 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -133,7 +133,7 @@ void of_core_init(void);
133 133
134static inline bool is_of_node(struct fwnode_handle *fwnode) 134static inline bool is_of_node(struct fwnode_handle *fwnode)
135{ 135{
136 return fwnode && fwnode->type == FWNODE_OF; 136 return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
137} 137}
138 138
139static inline struct device_node *to_of_node(struct fwnode_handle *fwnode) 139static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)