device property: Get rid of struct fwnode_handle type field
authorSakari Ailus <sakari.ailus@linux.intel.com>
Fri, 21 Jul 2017 11:39:31 +0000 (14:39 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 21 Jul 2017 22:04:50 +0000 (00:04 +0200)
Instead of relying on the struct fwnode_handle type field, define
fwnode_operations structs for all separate types of fwnodes. To find out
the type, compare to the ops field to relevant ops structs.

This change has two benefits:

1. it avoids adding the type field to each and every instance of struct
fwnode_handle, thus saving memory and

2. makes the ops field the single factor that defines both the types of
the fwnode as well as defines the implementation of its operations,
decreasing the possibility of bugs when developing code dealing with
fwnode internals.

Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/property.c
drivers/acpi/scan.c
drivers/base/property.c
drivers/of/property.c
include/acpi/acpi_bus.h
include/linux/acpi.h
include/linux/fwnode.h
include/linux/irqdomain.h
include/linux/of.h
kernel/irq/irqdomain.c

index 917c789f953dfb280f6f00895ce1fcf7ae2484ec..cb6a3b38ded217dacd9ae87fb66698638ceb1fb7 100644 (file)
@@ -56,8 +56,7 @@ static bool acpi_nondev_subnode_extract(const union acpi_object *desc,
                return false;
 
        dn->name = link->package.elements[0].string.pointer;
-       dn->fwnode.type = FWNODE_ACPI_DATA;
-       dn->fwnode.ops = &acpi_fwnode_ops;
+       dn->fwnode.ops = &acpi_data_fwnode_ops;
        dn->parent = parent;
        INIT_LIST_HEAD(&dn->data.subnodes);
 
@@ -469,10 +468,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_property);
 
 static struct acpi_device_data *acpi_device_data_of_node(struct fwnode_handle *fwnode)
 {
-       if (fwnode->type == FWNODE_ACPI) {
+       if (is_acpi_device_node(fwnode)) {
                struct acpi_device *adev = to_acpi_device_node(fwnode);
                return &adev->data;
-       } else if (fwnode->type == FWNODE_ACPI_DATA) {
+       } else if (is_acpi_data_node(fwnode)) {
                struct acpi_data_node *dn = to_acpi_data_node(fwnode);
                return &dn->data;
        }
@@ -903,7 +902,7 @@ struct fwnode_handle *acpi_get_next_subnode(struct fwnode_handle *fwnode,
        struct acpi_device *adev = to_acpi_device_node(fwnode);
        struct list_head *head, *next;
 
-       if (!child || child->type == FWNODE_ACPI) {
+       if (!child || is_acpi_device_node(child)) {
                if (adev)
                        head = &adev->children;
                else
@@ -927,7 +926,7 @@ struct fwnode_handle *acpi_get_next_subnode(struct fwnode_handle *fwnode,
        }
 
  nondev:
-       if (!child || child->type == FWNODE_ACPI_DATA) {
+       if (!child || is_acpi_data_node(child)) {
                struct acpi_data_node *data = to_acpi_data_node(fwnode);
                struct acpi_data_node *dn;
 
@@ -1223,16 +1222,26 @@ static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
        return 0;
 }
 
-const struct fwnode_operations acpi_fwnode_ops = {
-       .device_is_available = acpi_fwnode_device_is_available,
-       .property_present = acpi_fwnode_property_present,
-       .property_read_int_array = acpi_fwnode_property_read_int_array,
-       .property_read_string_array = acpi_fwnode_property_read_string_array,
-       .get_parent = acpi_node_get_parent,
-       .get_next_child_node = acpi_get_next_subnode,
-       .get_named_child_node = acpi_fwnode_get_named_child_node,
-       .graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
-       .graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
-       .graph_get_port_parent = acpi_node_get_parent,
-       .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint,
-};
+#define DECLARE_ACPI_FWNODE_OPS(ops) \
+       const struct fwnode_operations ops = {                          \
+               .device_is_available = acpi_fwnode_device_is_available, \
+               .property_present = acpi_fwnode_property_present,       \
+               .property_read_int_array =                              \
+                       acpi_fwnode_property_read_int_array,            \
+               .property_read_string_array =                           \
+                       acpi_fwnode_property_read_string_array,         \
+               .get_parent = acpi_node_get_parent,                     \
+               .get_next_child_node = acpi_get_next_subnode,           \
+               .get_named_child_node = acpi_fwnode_get_named_child_node, \
+               .graph_get_next_endpoint =                              \
+                       acpi_fwnode_graph_get_next_endpoint,            \
+               .graph_get_remote_endpoint =                            \
+                       acpi_fwnode_graph_get_remote_endpoint,          \
+               .graph_get_port_parent = acpi_node_get_parent,          \
+               .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, \
+       };                                                              \
+       EXPORT_SYMBOL_GPL(ops)
+
+DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops);
+DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops);
+const struct fwnode_operations acpi_static_fwnode_ops;
index 33897298f03e3ed680272ba6f4109077d434a0d8..943536c9a2a89c93424ce402a4d7320302c1f61d 100644 (file)
@@ -1467,8 +1467,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
        device->device_type = type;
        device->handle = handle;
        device->parent = acpi_bus_get_parent(handle);
-       device->fwnode.type = FWNODE_ACPI;
-       device->fwnode.ops = &acpi_fwnode_ops;
+       device->fwnode.ops = &acpi_device_fwnode_ops;
        acpi_set_device_status(device, sta);
        acpi_device_get_busid(device);
        acpi_set_pnp_ids(handle, &device->pnp, type);
index edf02c1b5845968bb94844f51057c6f414b83d64..857e4d39add6e8fdecf67d2cb999581281439260 100644 (file)
@@ -25,9 +25,11 @@ struct property_set {
        const struct property_entry *properties;
 };
 
+static const struct fwnode_operations pset_fwnode_ops;
+
 static inline bool is_pset_node(struct fwnode_handle *fwnode)
 {
-       return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_PDATA;
+       return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &pset_fwnode_ops;
 }
 
 static inline struct property_set *to_pset_node(struct fwnode_handle *fwnode)
@@ -900,7 +902,6 @@ int device_add_properties(struct device *dev,
        if (IS_ERR(p))
                return PTR_ERR(p);
 
-       p->fwnode.type = FWNODE_PDATA;
        p->fwnode.ops = &pset_fwnode_ops;
        set_secondary_fwnode(dev, &p->fwnode);
        return 0;
index eda50b4be9349d26c5600a19426cdc1d7f7fe92b..2d598882040507ebbe559c8798538f9ee9d62402 100644 (file)
@@ -952,3 +952,4 @@ const struct fwnode_operations of_fwnode_ops = {
        .graph_get_port_parent = of_fwnode_graph_get_port_parent,
        .graph_parse_endpoint = of_fwnode_graph_parse_endpoint,
 };
+EXPORT_SYMBOL_GPL(of_fwnode_ops);
index 7569123475b3b31d28e6c97bd4443c407ef93a6c..91b1e58e51892157d69529449ecd5b3ff5ed3a77 100644 (file)
@@ -395,15 +395,21 @@ struct acpi_data_node {
        struct completion kobj_done;
 };
 
+extern const struct fwnode_operations acpi_device_fwnode_ops;
+extern const struct fwnode_operations acpi_data_fwnode_ops;
+extern const struct fwnode_operations acpi_static_fwnode_ops;
+
 static inline bool is_acpi_node(struct fwnode_handle *fwnode)
 {
-       return !IS_ERR_OR_NULL(fwnode) && (fwnode->type == FWNODE_ACPI
-               || fwnode->type == FWNODE_ACPI_DATA);
+       return !IS_ERR_OR_NULL(fwnode) &&
+               (fwnode->ops == &acpi_device_fwnode_ops
+                || fwnode->ops == &acpi_data_fwnode_ops);
 }
 
 static inline bool is_acpi_device_node(struct fwnode_handle *fwnode)
 {
-       return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_ACPI;
+       return !IS_ERR_OR_NULL(fwnode) &&
+               fwnode->ops == &acpi_device_fwnode_ops;
 }
 
 static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
@@ -414,7 +420,7 @@ static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwno
 
 static inline bool is_acpi_data_node(struct fwnode_handle *fwnode)
 {
-       return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_ACPI_DATA;
+       return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &acpi_data_fwnode_ops;
 }
 
 static inline struct acpi_data_node *to_acpi_data_node(struct fwnode_handle *fwnode)
@@ -423,6 +429,12 @@ static inline struct acpi_data_node *to_acpi_data_node(struct fwnode_handle *fwn
                container_of(fwnode, struct acpi_data_node, fwnode) : NULL;
 }
 
+static inline bool is_acpi_static_node(struct fwnode_handle *fwnode)
+{
+       return !IS_ERR_OR_NULL(fwnode) &&
+               fwnode->ops == &acpi_static_fwnode_ops;
+}
+
 static inline bool acpi_data_node_match(struct fwnode_handle *fwnode,
                                        const char *name)
 {
index c749eef1daa1557910ec81c5f296dc907f5ccab2..71b763f0bee91a981a54319169f2d15b9f2886ba 100644 (file)
@@ -57,9 +57,6 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
        acpi_fwnode_handle(adev) : NULL)
 #define ACPI_HANDLE(dev)               acpi_device_handle(ACPI_COMPANION(dev))
 
-
-extern const struct fwnode_operations acpi_fwnode_ops;
-
 static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
 {
        struct fwnode_handle *fwnode;
@@ -68,15 +65,14 @@ static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
        if (!fwnode)
                return NULL;
 
-       fwnode->type = FWNODE_ACPI_STATIC;
-       fwnode->ops = &acpi_fwnode_ops;
+       fwnode->ops = &acpi_static_fwnode_ops;
 
        return fwnode;
 }
 
 static inline void acpi_free_fwnode_static(struct fwnode_handle *fwnode)
 {
-       if (WARN_ON(!fwnode || fwnode->type != FWNODE_ACPI_STATIC))
+       if (WARN_ON(!is_acpi_static_node(fwnode)))
                return;
 
        kfree(fwnode);
index 50893a1646cf3b4cfeeab523caabed50aa119311..c5dbc48b55dd380ab829f8eef9038a5c9023e6b3 100644 (file)
 
 #include <linux/types.h>
 
-enum fwnode_type {
-       FWNODE_INVALID = 0,
-       FWNODE_OF,
-       FWNODE_ACPI,
-       FWNODE_ACPI_DATA,
-       FWNODE_ACPI_STATIC,
-       FWNODE_PDATA,
-       FWNODE_IRQCHIP
-};
-
 struct fwnode_operations;
 
 struct fwnode_handle {
-       enum fwnode_type type;
        struct fwnode_handle *secondary;
        const struct fwnode_operations *ops;
 };
index cac77a5c555544af38d206c7f5b9eecd525394e2..d24273840b798cdd90db6e16f0cdf1685865694f 100644 (file)
@@ -265,9 +265,11 @@ static inline struct fwnode_handle *of_node_to_fwnode(struct device_node *node)
        return node ? &node->fwnode : NULL;
 }
 
+extern const struct fwnode_operations irqchip_fwnode_ops;
+
 static inline bool is_fwnode_irqchip(struct fwnode_handle *fwnode)
 {
-       return fwnode && fwnode->type == FWNODE_IRQCHIP;
+       return fwnode && fwnode->ops == &irqchip_fwnode_ops;
 }
 
 extern void irq_domain_update_bus_token(struct irq_domain *domain,
index 4a8a70916237ec1f9d1583d6cd69bf86f48102cc..cfc34117fc9203eefc2702a87271a95f761a2a3a 100644 (file)
@@ -104,7 +104,6 @@ extern const struct fwnode_operations of_fwnode_ops;
 static inline void of_node_init(struct device_node *node)
 {
        kobject_init(&node->kobj, &of_node_ktype);
-       node->fwnode.type = FWNODE_OF;
        node->fwnode.ops = &of_fwnode_ops;
 }
 
@@ -152,7 +151,7 @@ void of_core_init(void);
 
 static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
-       return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
+       return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops;
 }
 
 #define to_of_node(__fwnode)                                           \
index f1f251479aa6009eddb81041f69e825ebb8d28b7..e064fd1390f1fa1c03d7d6a3084a3e040a77cf4a 100644 (file)
@@ -41,6 +41,8 @@ static inline void debugfs_add_domain_dir(struct irq_domain *d) { }
 static inline void debugfs_remove_domain_dir(struct irq_domain *d) { }
 #endif
 
+const struct fwnode_operations irqchip_fwnode_ops;
+
 /**
  * irq_domain_alloc_fwnode - Allocate a fwnode_handle suitable for
  *                           identifying an irq domain
@@ -86,7 +88,7 @@ struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
        fwid->type = type;
        fwid->name = n;
        fwid->data = data;
-       fwid->fwnode.type = FWNODE_IRQCHIP;
+       fwid->fwnode.ops = &irqchip_fwnode_ops;
        return &fwid->fwnode;
 }
 EXPORT_SYMBOL_GPL(__irq_domain_alloc_fwnode);
@@ -193,10 +195,8 @@ struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, int size,
        }
 
        if (!domain->name) {
-               if (fwnode) {
-                       pr_err("Invalid fwnode type (%d) for irqdomain\n",
-                              fwnode->type);
-               }
+               if (fwnode)
+                       pr_err("Invalid fwnode type for irqdomain\n");
                domain->name = kasprintf(GFP_KERNEL, "unknown-%d",
                                         atomic_inc_return(&unknown_domains));
                if (!domain->name) {