Skip to content

Commit 9a90ea7

Browse files
spandruvadajwrdegoede
authored andcommitted
platform/x86/intel/vsec: Use mutex for ida_alloc() and ida_free()
ID alloc and free functions don't have in built protection for parallel invocation of ida_alloc() and ida_free(). With the current flow in the vsec driver, there is no such scenario. But add mutex protection for potential future changes. Suggested-by: Hans de Goede <[email protected]> Signed-off-by: Srinivas Pandruvada <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent be1ca8a commit 9a90ea7

File tree

1 file changed

+9
-0
lines changed
  • drivers/platform/x86/intel

1 file changed

+9
-0
lines changed

drivers/platform/x86/intel/vsec.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,16 @@ static void intel_vsec_remove_aux(void *data)
129129
auxiliary_device_uninit(data);
130130
}
131131

132+
static DEFINE_MUTEX(vsec_ida_lock);
133+
132134
static void intel_vsec_dev_release(struct device *dev)
133135
{
134136
struct intel_vsec_device *intel_vsec_dev = dev_to_ivdev(dev);
135137

138+
mutex_lock(&vsec_ida_lock);
136139
ida_free(intel_vsec_dev->ida, intel_vsec_dev->auxdev.id);
140+
mutex_unlock(&vsec_ida_lock);
141+
137142
kfree(intel_vsec_dev->resource);
138143
kfree(intel_vsec_dev);
139144
}
@@ -145,7 +150,9 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent,
145150
struct auxiliary_device *auxdev = &intel_vsec_dev->auxdev;
146151
int ret, id;
147152

153+
mutex_lock(&vsec_ida_lock);
148154
ret = ida_alloc(intel_vsec_dev->ida, GFP_KERNEL);
155+
mutex_unlock(&vsec_ida_lock);
149156
if (ret < 0) {
150157
kfree(intel_vsec_dev);
151158
return ret;
@@ -161,7 +168,9 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent,
161168

162169
ret = auxiliary_device_init(auxdev);
163170
if (ret < 0) {
171+
mutex_lock(&vsec_ida_lock);
164172
ida_free(intel_vsec_dev->ida, auxdev->id);
173+
mutex_unlock(&vsec_ida_lock);
165174
kfree(intel_vsec_dev->resource);
166175
kfree(intel_vsec_dev);
167176
return ret;

0 commit comments

Comments
 (0)