d->mask_buf[i],
                                                     chip->irq_drv_data);
                        if (ret)
-                               goto err_alloc;
+                               goto err_mutex;
                }
 
                if (chip->mask_base && !chip->handle_mask_sync) {
                        if (ret) {
                                dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
                                        reg, ret);
-                               goto err_alloc;
+                               goto err_mutex;
                        }
                }
 
                        if (ret) {
                                dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
                                        reg, ret);
-                               goto err_alloc;
+                               goto err_mutex;
                        }
                }
 
                        if (ret != 0) {
                                dev_err(map->dev, "Failed to read IRQ status: %d\n",
                                        ret);
-                               goto err_alloc;
+                               goto err_mutex;
                        }
                }
 
                        if (ret != 0) {
                                dev_err(map->dev, "Failed to ack 0x%x: %d\n",
                                        reg, ret);
-                               goto err_alloc;
+                               goto err_mutex;
                        }
                }
        }
                        if (ret != 0) {
                                dev_err(map->dev, "Failed to set masks in 0x%x: %d\n",
                                        reg, ret);
-                               goto err_alloc;
+                               goto err_mutex;
                        }
                }
        }
        if (chip->status_is_level) {
                ret = read_irq_data(d);
                if (ret < 0)
-                       goto err_alloc;
+                       goto err_mutex;
 
                memcpy(d->prev_status_buf, d->status_buf,
                       array_size(d->chip->num_regs, sizeof(d->prev_status_buf[0])));
 
        ret = regmap_irq_create_domain(fwnode, irq_base, chip, d);
        if (ret)
-               goto err_alloc;
+               goto err_mutex;
 
        ret = request_threaded_irq(irq, NULL, regmap_irq_thread,
                                   irq_flags | IRQF_ONESHOT,
 
 err_domain:
        /* Should really dispose of the domain but... */
+err_mutex:
+       mutex_destroy(&d->lock);
 err_alloc:
        kfree(d->type_buf);
        kfree(d->type_buf_def);
                        kfree(d->config_buf[i]);
                kfree(d->config_buf);
        }
+       mutex_destroy(&d->lock);
        kfree(d);
 }
 EXPORT_SYMBOL_GPL(regmap_del_irq_chip);