mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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 <hdegoede@redhat.com> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Link: https://lore.kernel.org/r/20230207125821.3837799-1-srinivas.pandruvada@linux.intel.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
		
							parent
							
								
									be1ca8ae66
								
							
						
					
					
						commit
						9a90ea7d37
					
				
					 1 changed files with 9 additions and 0 deletions
				
			
		| 
						 | 
					@ -129,11 +129,16 @@ static void intel_vsec_remove_aux(void *data)
 | 
				
			||||||
	auxiliary_device_uninit(data);
 | 
						auxiliary_device_uninit(data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static DEFINE_MUTEX(vsec_ida_lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void intel_vsec_dev_release(struct device *dev)
 | 
					static void intel_vsec_dev_release(struct device *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct intel_vsec_device *intel_vsec_dev = dev_to_ivdev(dev);
 | 
						struct intel_vsec_device *intel_vsec_dev = dev_to_ivdev(dev);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mutex_lock(&vsec_ida_lock);
 | 
				
			||||||
	ida_free(intel_vsec_dev->ida, intel_vsec_dev->auxdev.id);
 | 
						ida_free(intel_vsec_dev->ida, intel_vsec_dev->auxdev.id);
 | 
				
			||||||
 | 
						mutex_unlock(&vsec_ida_lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kfree(intel_vsec_dev->resource);
 | 
						kfree(intel_vsec_dev->resource);
 | 
				
			||||||
	kfree(intel_vsec_dev);
 | 
						kfree(intel_vsec_dev);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -145,7 +150,9 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent,
 | 
				
			||||||
	struct auxiliary_device *auxdev = &intel_vsec_dev->auxdev;
 | 
						struct auxiliary_device *auxdev = &intel_vsec_dev->auxdev;
 | 
				
			||||||
	int ret, id;
 | 
						int ret, id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mutex_lock(&vsec_ida_lock);
 | 
				
			||||||
	ret = ida_alloc(intel_vsec_dev->ida, GFP_KERNEL);
 | 
						ret = ida_alloc(intel_vsec_dev->ida, GFP_KERNEL);
 | 
				
			||||||
 | 
						mutex_unlock(&vsec_ida_lock);
 | 
				
			||||||
	if (ret < 0) {
 | 
						if (ret < 0) {
 | 
				
			||||||
		kfree(intel_vsec_dev);
 | 
							kfree(intel_vsec_dev);
 | 
				
			||||||
		return ret;
 | 
							return ret;
 | 
				
			||||||
| 
						 | 
					@ -161,7 +168,9 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = auxiliary_device_init(auxdev);
 | 
						ret = auxiliary_device_init(auxdev);
 | 
				
			||||||
	if (ret < 0) {
 | 
						if (ret < 0) {
 | 
				
			||||||
 | 
							mutex_lock(&vsec_ida_lock);
 | 
				
			||||||
		ida_free(intel_vsec_dev->ida, auxdev->id);
 | 
							ida_free(intel_vsec_dev->ida, auxdev->id);
 | 
				
			||||||
 | 
							mutex_unlock(&vsec_ida_lock);
 | 
				
			||||||
		kfree(intel_vsec_dev->resource);
 | 
							kfree(intel_vsec_dev->resource);
 | 
				
			||||||
		kfree(intel_vsec_dev);
 | 
							kfree(intel_vsec_dev);
 | 
				
			||||||
		return ret;
 | 
							return ret;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue