diff options
author | Wan Zongshun <Vincent.Wan@amd.com> | 2016-04-01 09:06:02 -0400 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2016-04-07 07:29:41 -0400 |
commit | 7aba6cb9ee9db7849d0bf57891d9c7feb4e89457 (patch) | |
tree | 546e3084c0185e9487668b1eea0ad871e6fe2344 /drivers/iommu/amd_iommu.c | |
parent | ca3bf5d47cec8b7614bcb2e9132c40081d6d81db (diff) |
iommu/amd: Make call-sites of get_device_id aware of its return value
This patch is to make the call-sites of get_device_id aware of its
return value.
Signed-off-by: Wan Zongshun <Vincent.Wan@amd.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu/amd_iommu.c')
-rw-r--r-- | drivers/iommu/amd_iommu.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index d8e59a84f7c0..400867f01d35 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c | |||
@@ -279,9 +279,11 @@ static void init_unity_mappings_for_device(struct device *dev, | |||
279 | struct dma_ops_domain *dma_dom) | 279 | struct dma_ops_domain *dma_dom) |
280 | { | 280 | { |
281 | struct unity_map_entry *e; | 281 | struct unity_map_entry *e; |
282 | u16 devid; | 282 | int devid; |
283 | 283 | ||
284 | devid = get_device_id(dev); | 284 | devid = get_device_id(dev); |
285 | if (IS_ERR_VALUE(devid)) | ||
286 | return; | ||
285 | 287 | ||
286 | list_for_each_entry(e, &amd_iommu_unity_map, list) { | 288 | list_for_each_entry(e, &amd_iommu_unity_map, list) { |
287 | if (!(devid >= e->devid_start && devid <= e->devid_end)) | 289 | if (!(devid >= e->devid_start && devid <= e->devid_end)) |
@@ -296,7 +298,7 @@ static void init_unity_mappings_for_device(struct device *dev, | |||
296 | */ | 298 | */ |
297 | static bool check_device(struct device *dev) | 299 | static bool check_device(struct device *dev) |
298 | { | 300 | { |
299 | u16 devid; | 301 | int devid; |
300 | 302 | ||
301 | if (!dev || !dev->dma_mask) | 303 | if (!dev || !dev->dma_mask) |
302 | return false; | 304 | return false; |
@@ -306,6 +308,8 @@ static bool check_device(struct device *dev) | |||
306 | return false; | 308 | return false; |
307 | 309 | ||
308 | devid = get_device_id(dev); | 310 | devid = get_device_id(dev); |
311 | if (IS_ERR_VALUE(devid)) | ||
312 | return false; | ||
309 | 313 | ||
310 | /* Out of our scope? */ | 314 | /* Out of our scope? */ |
311 | if (devid > amd_iommu_last_bdf) | 315 | if (devid > amd_iommu_last_bdf) |
@@ -342,11 +346,16 @@ static int iommu_init_device(struct device *dev) | |||
342 | { | 346 | { |
343 | struct pci_dev *pdev = to_pci_dev(dev); | 347 | struct pci_dev *pdev = to_pci_dev(dev); |
344 | struct iommu_dev_data *dev_data; | 348 | struct iommu_dev_data *dev_data; |
349 | int devid; | ||
345 | 350 | ||
346 | if (dev->archdata.iommu) | 351 | if (dev->archdata.iommu) |
347 | return 0; | 352 | return 0; |
348 | 353 | ||
349 | dev_data = find_dev_data(get_device_id(dev)); | 354 | devid = get_device_id(dev); |
355 | if (IS_ERR_VALUE(devid)) | ||
356 | return devid; | ||
357 | |||
358 | dev_data = find_dev_data(devid); | ||
350 | if (!dev_data) | 359 | if (!dev_data) |
351 | return -ENOMEM; | 360 | return -ENOMEM; |
352 | 361 | ||
@@ -367,9 +376,13 @@ static int iommu_init_device(struct device *dev) | |||
367 | 376 | ||
368 | static void iommu_ignore_device(struct device *dev) | 377 | static void iommu_ignore_device(struct device *dev) |
369 | { | 378 | { |
370 | u16 devid, alias; | 379 | u16 alias; |
380 | int devid; | ||
371 | 381 | ||
372 | devid = get_device_id(dev); | 382 | devid = get_device_id(dev); |
383 | if (IS_ERR_VALUE(devid)) | ||
384 | return; | ||
385 | |||
373 | alias = amd_iommu_alias_table[devid]; | 386 | alias = amd_iommu_alias_table[devid]; |
374 | 387 | ||
375 | memset(&amd_iommu_dev_table[devid], 0, sizeof(struct dev_table_entry)); | 388 | memset(&amd_iommu_dev_table[devid], 0, sizeof(struct dev_table_entry)); |
@@ -381,8 +394,14 @@ static void iommu_ignore_device(struct device *dev) | |||
381 | 394 | ||
382 | static void iommu_uninit_device(struct device *dev) | 395 | static void iommu_uninit_device(struct device *dev) |
383 | { | 396 | { |
384 | struct iommu_dev_data *dev_data = search_dev_data(get_device_id(dev)); | 397 | int devid; |
398 | struct iommu_dev_data *dev_data; | ||
399 | |||
400 | devid = get_device_id(dev); | ||
401 | if (IS_ERR_VALUE(devid)) | ||
402 | return; | ||
385 | 403 | ||
404 | dev_data = search_dev_data(devid); | ||
386 | if (!dev_data) | 405 | if (!dev_data) |
387 | return; | 406 | return; |
388 | 407 | ||
@@ -2314,13 +2333,15 @@ static int amd_iommu_add_device(struct device *dev) | |||
2314 | struct iommu_dev_data *dev_data; | 2333 | struct iommu_dev_data *dev_data; |
2315 | struct iommu_domain *domain; | 2334 | struct iommu_domain *domain; |
2316 | struct amd_iommu *iommu; | 2335 | struct amd_iommu *iommu; |
2317 | u16 devid; | 2336 | int ret, devid; |
2318 | int ret; | ||
2319 | 2337 | ||
2320 | if (!check_device(dev) || get_dev_data(dev)) | 2338 | if (!check_device(dev) || get_dev_data(dev)) |
2321 | return 0; | 2339 | return 0; |
2322 | 2340 | ||
2323 | devid = get_device_id(dev); | 2341 | devid = get_device_id(dev); |
2342 | if (IS_ERR_VALUE(devid)) | ||
2343 | return devid; | ||
2344 | |||
2324 | iommu = amd_iommu_rlookup_table[devid]; | 2345 | iommu = amd_iommu_rlookup_table[devid]; |
2325 | 2346 | ||
2326 | ret = iommu_init_device(dev); | 2347 | ret = iommu_init_device(dev); |
@@ -2358,12 +2379,15 @@ out: | |||
2358 | static void amd_iommu_remove_device(struct device *dev) | 2379 | static void amd_iommu_remove_device(struct device *dev) |
2359 | { | 2380 | { |
2360 | struct amd_iommu *iommu; | 2381 | struct amd_iommu *iommu; |
2361 | u16 devid; | 2382 | int devid; |
2362 | 2383 | ||
2363 | if (!check_device(dev)) | 2384 | if (!check_device(dev)) |
2364 | return; | 2385 | return; |
2365 | 2386 | ||
2366 | devid = get_device_id(dev); | 2387 | devid = get_device_id(dev); |
2388 | if (IS_ERR_VALUE(devid)) | ||
2389 | return; | ||
2390 | |||
2367 | iommu = amd_iommu_rlookup_table[devid]; | 2391 | iommu = amd_iommu_rlookup_table[devid]; |
2368 | 2392 | ||
2369 | iommu_uninit_device(dev); | 2393 | iommu_uninit_device(dev); |
@@ -3035,12 +3059,14 @@ static void amd_iommu_detach_device(struct iommu_domain *dom, | |||
3035 | { | 3059 | { |
3036 | struct iommu_dev_data *dev_data = dev->archdata.iommu; | 3060 | struct iommu_dev_data *dev_data = dev->archdata.iommu; |
3037 | struct amd_iommu *iommu; | 3061 | struct amd_iommu *iommu; |
3038 | u16 devid; | 3062 | int devid; |
3039 | 3063 | ||
3040 | if (!check_device(dev)) | 3064 | if (!check_device(dev)) |
3041 | return; | 3065 | return; |
3042 | 3066 | ||
3043 | devid = get_device_id(dev); | 3067 | devid = get_device_id(dev); |
3068 | if (IS_ERR_VALUE(devid)) | ||
3069 | return; | ||
3044 | 3070 | ||
3045 | if (dev_data->domain != NULL) | 3071 | if (dev_data->domain != NULL) |
3046 | detach_device(dev); | 3072 | detach_device(dev); |
@@ -3158,9 +3184,11 @@ static void amd_iommu_get_dm_regions(struct device *dev, | |||
3158 | struct list_head *head) | 3184 | struct list_head *head) |
3159 | { | 3185 | { |
3160 | struct unity_map_entry *entry; | 3186 | struct unity_map_entry *entry; |
3161 | u16 devid; | 3187 | int devid; |
3162 | 3188 | ||
3163 | devid = get_device_id(dev); | 3189 | devid = get_device_id(dev); |
3190 | if (IS_ERR_VALUE(devid)) | ||
3191 | return; | ||
3164 | 3192 | ||
3165 | list_for_each_entry(entry, &amd_iommu_unity_map, list) { | 3193 | list_for_each_entry(entry, &amd_iommu_unity_map, list) { |
3166 | struct iommu_dm_region *region; | 3194 | struct iommu_dm_region *region; |
@@ -3862,6 +3890,9 @@ static struct irq_domain *get_irq_domain(struct irq_alloc_info *info) | |||
3862 | case X86_IRQ_ALLOC_TYPE_MSI: | 3890 | case X86_IRQ_ALLOC_TYPE_MSI: |
3863 | case X86_IRQ_ALLOC_TYPE_MSIX: | 3891 | case X86_IRQ_ALLOC_TYPE_MSIX: |
3864 | devid = get_device_id(&info->msi_dev->dev); | 3892 | devid = get_device_id(&info->msi_dev->dev); |
3893 | if (IS_ERR_VALUE(devid)) | ||
3894 | return NULL; | ||
3895 | |||
3865 | iommu = amd_iommu_rlookup_table[devid]; | 3896 | iommu = amd_iommu_rlookup_table[devid]; |
3866 | if (iommu) | 3897 | if (iommu) |
3867 | return iommu->msi_domain; | 3898 | return iommu->msi_domain; |