Merge tag 'mfd-for-linus-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
[sfrench/cifs-2.6.git] / drivers / mfd / mfd-core.c
index fc1c1fc138133d86053ee32a2a7a7b96cd255145..3ac486a597f3c31e8e362f1f9954098cdf081086 100644 (file)
@@ -107,7 +107,7 @@ static void mfd_acpi_add_device(const struct mfd_cell *cell,
 
                        strlcpy(ids[0].id, match->pnpid, sizeof(ids[0].id));
                        list_for_each_entry(child, &parent->children, node) {
-                               if (acpi_match_device_ids(child, ids)) {
+                               if (!acpi_match_device_ids(child, ids)) {
                                        adev = child;
                                        break;
                                }
@@ -334,6 +334,44 @@ void mfd_remove_devices(struct device *parent)
 }
 EXPORT_SYMBOL(mfd_remove_devices);
 
+static void devm_mfd_dev_release(struct device *dev, void *res)
+{
+       mfd_remove_devices(dev);
+}
+
+/**
+ * devm_mfd_add_devices - Resource managed version of mfd_add_devices()
+ *
+ * Returns 0 on success or an appropriate negative error number on failure.
+ * All child-devices of the MFD will automatically be removed when it gets
+ * unbinded.
+ */
+int devm_mfd_add_devices(struct device *dev, int id,
+                        const struct mfd_cell *cells, int n_devs,
+                        struct resource *mem_base,
+                        int irq_base, struct irq_domain *domain)
+{
+       struct device **ptr;
+       int ret;
+
+       ptr = devres_alloc(devm_mfd_dev_release, sizeof(*ptr), GFP_KERNEL);
+       if (!ptr)
+               return -ENOMEM;
+
+       ret = mfd_add_devices(dev, id, cells, n_devs, mem_base,
+                             irq_base, domain);
+       if (ret < 0) {
+               devres_free(ptr);
+               return ret;
+       }
+
+       *ptr = dev;
+       devres_add(dev, ptr);
+
+       return ret;
+}
+EXPORT_SYMBOL(devm_mfd_add_devices);
+
 int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones)
 {
        struct mfd_cell cell_entry;