drivers/iommu/iommu.c:698:6-12: ERROR: invalid reference to the index variable of the iterator on line 692
PATCH 28/38 drivers/iommu/iommu.c:698:6-12: ERROR: invalid reference to the index variable of the iterator on line 692
When a list_for_each_entry reaches the end, it comes back to the list_node that represents the pointer to the list. This will never be null. It should also not be dereferenced. So you will need to set a flag to detect whether the list was exited on a break.
julia
---------- Forwarded message ----------
Date: Fri, 3 Jan 2020 00:12:50 +0800
From: kbuild test robot <[email protected]>
To: kbuild(a)lists.01.org
Cc: Julia Lawall <[email protected]>
Subject: [baolu:iommu/master/5.5-rc4/20200102 28/38]
drivers/iommu/iommu.c:698:6-12: ERROR: invalid reference to the index variable of the iterator on line 692
CC: kbuild-all(a)lists.01.org
CC: Baolu Lu <[email protected]>
BCC: philip.li(a)intel.com
TO: Lu Baolu <[email protected]>
tree: baolu/iommu/master/5.5-rc4/20200102 head: 1f6b85204f719cce6abba002410a7f3129996843 commit: 1e64ab21bdc0ecd9fee7cd3a2d4166d9d8329140 [28/38] iommu: Preallocate iommu group when probing devices
:::::: branch date: 10 hours ago
:::::: commit date: 10 hours ago
If you fix the issue, kindly add following tag
Quoted 1 line
Quoted 1 line
drivers/iommu/iommu.c:698:6-12: ERROR: invalid reference to the index variable of the iterator on line 692
drivers/iommu/iommu.c:698:16-22: ERROR: invalid reference to the index variable of the iterator on line 692
git remote add baolu git://bee.sh.intel.com/git/blu2/usb.git
git remote update baolu
git checkout 1e64ab21bdc0ecd9fee7cd3a2d4166d9d8329140 vim +698 drivers/iommu/iommu.c
beed2821b4f42c Joerg Roedel 2015-05-28 677
d72e31c9374627 Alex Williamson 2012-05-30 678 /**
d72e31c9374627 Alex Williamson 2012-05-30 679 * iommu_group_add_device - add a device to an iommu group
d72e31c9374627 Alex Williamson 2012-05-30 680 * @group: the group into which to add the device (reference should be held)
d72e31c9374627 Alex Williamson 2012-05-30 681 * @dev: the device
d72e31c9374627 Alex Williamson 2012-05-30 682 *
d72e31c9374627 Alex Williamson 2012-05-30 683 * This function is called by an iommu driver to add a device into a
d72e31c9374627 Alex Williamson 2012-05-30 684 * group. Adding a device increments the group reference count.
d72e31c9374627 Alex Williamson 2012-05-30 685 */
d72e31c9374627 Alex Williamson 2012-05-30 686 int iommu_group_add_device(struct iommu_group *group, struct device *dev)
1460432cb513f0 Alex Williamson 2011-10-21 687 {
d72e31c9374627 Alex Williamson 2012-05-30 688 int ret, i = 0;
1e64ab21bdc0ec Lu Baolu 2019-12-30 689 struct group_device *device = NULL;
d72e31c9374627 Alex Williamson 2012-05-30 690
1e64ab21bdc0ec Lu Baolu 2019-12-30 691 mutex_lock(&group->mutex);
1e64ab21bdc0ec Lu Baolu 2019-12-30 @692 list_for_each_entry(device, &group->devices, list) {
1e64ab21bdc0ec Lu Baolu 2019-12-30 693 if (device->dev == dev)
1e64ab21bdc0ec Lu Baolu 2019-12-30 694 break;
1e64ab21bdc0ec Lu Baolu 2019-12-30 695 }
1e64ab21bdc0ec Lu Baolu 2019-12-30 696 mutex_unlock(&group->mutex);
1e64ab21bdc0ec Lu Baolu 2019-12-30 697
1e64ab21bdc0ec Lu Baolu 2019-12-30 @698 if (!device || device->dev != dev) {
d72e31c9374627 Alex Williamson 2012-05-30 699 device = kzalloc(sizeof(*device), GFP_KERNEL);
d72e31c9374627 Alex Williamson 2012-05-30 700 if (!device)
d72e31c9374627 Alex Williamson 2012-05-30 701 return -ENOMEM;
d72e31c9374627 Alex Williamson 2012-05-30 702
d72e31c9374627 Alex Williamson 2012-05-30 703 device->dev = dev;
1e64ab21bdc0ec Lu Baolu 2019-12-30 704 mutex_lock(&group->mutex);
1e64ab21bdc0ec Lu Baolu 2019-12-30 705 list_add_tail(&device->list, &group->devices);
1e64ab21bdc0ec Lu Baolu 2019-12-30 706 mutex_unlock(&group->mutex);
1e64ab21bdc0ec Lu Baolu 2019-12-30 707 } else if (device->added) {
1e64ab21bdc0ec Lu Baolu 2019-12-30 708 kobject_get(group->devices_kobj);
1e64ab21bdc0ec Lu Baolu 2019-12-30 709 return 0;
1e64ab21bdc0ec Lu Baolu 2019-12-30 710 }
d72e31c9374627 Alex Williamson 2012-05-30 711
d72e31c9374627 Alex Williamson 2012-05-30 712 ret = sysfs_create_link(&dev->kobj, &group->kobj, "iommu_group");
797a8b4d768c58 Robin Murphy 2017-01-16 713 if (ret)
797a8b4d768c58 Robin Murphy 2017-01-16 714 goto err_free_device;
d72e31c9374627 Alex Williamson 2012-05-30 715
d72e31c9374627 Alex Williamson 2012-05-30 716 device->name = kasprintf(GFP_KERNEL, "%s", kobject_name(&dev->kobj));
d72e31c9374627 Alex Williamson 2012-05-30 717 rename:
d72e31c9374627 Alex Williamson 2012-05-30 718 if (!device->name) {
797a8b4d768c58 Robin Murphy 2017-01-16 719 ret = -ENOMEM;
797a8b4d768c58 Robin Murphy 2017-01-16 720 goto err_remove_link;
d72e31c9374627 Alex Williamson 2012-05-30 721 }
1460432cb513f0 Alex Williamson 2011-10-21 722
d72e31c9374627 Alex Williamson 2012-05-30 723 ret = sysfs_create_link_nowarn(group->devices_kobj,
d72e31c9374627 Alex Williamson 2012-05-30 724 &dev->kobj, device->name);
d72e31c9374627 Alex Williamson 2012-05-30 725 if (ret) {
d72e31c9374627 Alex Williamson 2012-05-30 726 if (ret == -EEXIST && i >= 0) {
d72e31c9374627 Alex Williamson 2012-05-30 727 /*
d72e31c9374627 Alex Williamson 2012-05-30 728 * Account for the slim chance of collision
d72e31c9374627 Alex Williamson 2012-05-30 729 * and append an instance to the name.
d72e31c9374627 Alex Williamson 2012-05-30 730 */
797a8b4d768c58 Robin Murphy 2017-01-16 731 kfree(device->name);
d72e31c9374627 Alex Williamson 2012-05-30 732 device->name = kasprintf(GFP_KERNEL, "%s.%d",
d72e31c9374627 Alex Williamson 2012-05-30 733 kobject_name(&dev->kobj), i++);
d72e31c9374627 Alex Williamson 2012-05-30 734 goto rename;
d72e31c9374627 Alex Williamson 2012-05-30 735 }
797a8b4d768c58 Robin Murphy 2017-01-16 736 goto err_free_name;
d72e31c9374627 Alex Williamson 2012-05-30 737 }
d72e31c9374627 Alex Williamson 2012-05-30 738
d72e31c9374627 Alex Williamson 2012-05-30 739 kobject_get(group->devices_kobj);
1460432cb513f0 Alex Williamson 2011-10-21 740
d72e31c9374627 Alex Williamson 2012-05-30 741 dev->iommu_group = group;
1460432cb513f0 Alex Williamson 2011-10-21 742
beed2821b4f42c Joerg Roedel 2015-05-28 743 iommu_group_create_direct_mappings(group, dev);
beed2821b4f42c Joerg Roedel 2015-05-28 744
d72e31c9374627 Alex Williamson 2012-05-30 745 mutex_lock(&group->mutex);
e39cb8a3aa988a Joerg Roedel 2015-05-28 746 if (group->domain)
797a8b4d768c58 Robin Murphy 2017-01-16 747 ret = __iommu_attach_device(group->domain, dev);
d72e31c9374627 Alex Williamson 2012-05-30 748 mutex_unlock(&group->mutex);
797a8b4d768c58 Robin Murphy 2017-01-16 749 if (ret)
797a8b4d768c58 Robin Murphy 2017-01-16 750 goto err_put_group;
d72e31c9374627 Alex Williamson 2012-05-30 751
1e64ab21bdc0ec Lu Baolu 2019-12-30 752 device->added = true;
1e64ab21bdc0ec Lu Baolu 2019-12-30 753
d72e31c9374627 Alex Williamson 2012-05-30 754 /* Notify any listeners about change to group. */
d72e31c9374627 Alex Williamson 2012-05-30 755 blocking_notifier_call_chain(&group->notifier,
d72e31c9374627 Alex Williamson 2012-05-30 756 IOMMU_GROUP_NOTIFY_ADD_DEVICE, dev);
d1cf7e822746b5 Shuah Khan 2013-08-15 757
d1cf7e822746b5 Shuah Khan 2013-08-15 758 trace_add_device_to_group(group->id, dev);
269aa808a990b3 Joerg Roedel 2015-05-28 759
780da9e4f5bf35 Bjorn Helgaas 2019-02-08 760 dev_info(dev, "Adding to iommu group %d\n", group->id);
269aa808a990b3 Joerg Roedel 2015-05-28 761
1460432cb513f0 Alex Williamson 2011-10-21 762 return 0;
797a8b4d768c58 Robin Murphy 2017-01-16 763
797a8b4d768c58 Robin Murphy 2017-01-16 764 err_put_group:
797a8b4d768c58 Robin Murphy 2017-01-16 765 kobject_put(group->devices_kobj);
797a8b4d768c58 Robin Murphy 2017-01-16 766 err_free_name:
797a8b4d768c58 Robin Murphy 2017-01-16 767 kfree(device->name);
797a8b4d768c58 Robin Murphy 2017-01-16 768 err_remove_link:
797a8b4d768c58 Robin Murphy 2017-01-16 769 sysfs_remove_link(&dev->kobj, "iommu_group");
797a8b4d768c58 Robin Murphy 2017-01-16 770 err_free_device:
1e64ab21bdc0ec Lu Baolu 2019-12-30 771 mutex_lock(&group->mutex);
1e64ab21bdc0ec Lu Baolu 2019-12-30 772 list_del(&device->list);
1e64ab21bdc0ec Lu Baolu 2019-12-30 773 mutex_unlock(&group->mutex);
1e64ab21bdc0ec Lu Baolu 2019-12-30 774 dev->iommu_group = NULL;
797a8b4d768c58 Robin Murphy 2017-01-16 775 kfree(device);
780da9e4f5bf35 Bjorn Helgaas 2019-02-08 776 dev_err(dev, "Failed to add to iommu group %d: %d\n", group->id, ret);
797a8b4d768c58 Robin Murphy 2017-01-16 777 return ret;
1460432cb513f0 Alex Williamson 2011-10-21 778 }
d72e31c9374627 Alex Williamson 2012-05-30 779 EXPORT_SYMBOL_GPL(iommu_group_add_device);
d72e31c9374627 Alex Williamson 2012-05-30 780---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation