struct mtk_iommu_data *data;
struct iommu_domain domain;
+
+ struct mutex mutex; /* Protect "data" in this structure */
};
static const struct iommu_ops mtk_iommu_ops;
dom = kzalloc(sizeof(*dom), GFP_KERNEL);
if (!dom)
return NULL;
+ mutex_init(&dom->mutex);
return &dom->domain;
}
if (domid < 0)
return domid;
+ mutex_lock(&dom->mutex);
if (!dom->data) {
/* Data is in the frstdata in sharing pgtable case. */
frstdata = mtk_iommu_get_m4u_data();
- if (mtk_iommu_domain_finalise(dom, frstdata, domid))
+ ret = mtk_iommu_domain_finalise(dom, frstdata, domid);
+ if (ret) {
+ mutex_unlock(&dom->mutex);
return -ENODEV;
+ }
dom->data = data;
}
+ mutex_unlock(&dom->mutex);
mutex_lock(&data->mutex);
if (!data->m4u_dom) { /* Initialize the M4U HW */