Content-Type: multipart/mixed; boundary="===============4737480445801681503==" MIME-Version: 1.0 From: Julia Lawall To: kbuild-all@lists.01.org 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 Date: Fri, 03 Jan 2020 07:22:38 +0100 Message-ID: List-Id: --===============4737480445801681503== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 To: kbuild(a)lists.01.org Cc: Julia Lawall 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 BCC: philip.li(a)intel.com TO: Lu Baolu 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 Reported-by: kbuild test robot Reported-by: Julia Lawall >> drivers/iommu/iommu.c:698:6-12: ERROR: invalid reference to the index va= riable of the iterator on line 692 drivers/iommu/iommu.c:698:16-22: ERROR: invalid reference to the index v= ariable 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 w= hich 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 =3D 0; 1e64ab21bdc0ec Lu Baolu 2019-12-30 689 struct group_device *devic= e =3D 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 =3D=3D de= v) 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= !=3D dev) { d72e31c9374627 Alex Williamson 2012-05-30 699 device =3D 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 =3D dev; 1e64ab21bdc0ec Lu Baolu 2019-12-30 704 mutex_lock(&group->mutex); 1e64ab21bdc0ec Lu Baolu 2019-12-30 705 list_add_tail(&device->li= st, &group->devices); 1e64ab21bdc0ec Lu Baolu 2019-12-30 706 mutex_unlock(&group->mute= x); 1e64ab21bdc0ec Lu Baolu 2019-12-30 707 } else if (device->added) { 1e64ab21bdc0ec Lu Baolu 2019-12-30 708 kobject_get(group->device= s_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 =3D 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 =3D 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 =3D -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 =3D sysfs_create_link_= nowarn(group->devices_kobj, d72e31c9374627 Alex Williamson 2012-05-30 724 &dev->kobj, devi= ce->name); d72e31c9374627 Alex Williamson 2012-05-30 725 if (ret) { d72e31c9374627 Alex Williamson 2012-05-30 726 if (ret =3D=3D -EEXIST &&= i >=3D 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 instanc= e 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 =3D kasprin= tf(GFP_KERNEL, "%s.%d", d72e31c9374627 Alex Williamson 2012-05-30 733 kobject_name(&dev->k= obj), 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 =3D 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 =3D __iommu_attach_de= vice(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 =3D true; 1e64ab21bdc0ec Lu Baolu 2019-12-30 753 d72e31c9374627 Alex Williamson 2012-05-30 754 /* Notify any listeners ab= out change to group. */ d72e31c9374627 Alex Williamson 2012-05-30 755 blocking_notifier_call_cha= in(&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 i= ommu 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->ko= bj, "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 =3D NULL; 797a8b4d768c58 Robin Murphy 2017-01-16 775 kfree(device); 780da9e4f5bf35 Bjorn Helgaas 2019-02-08 776 dev_err(dev, "Failed to ad= d 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_gro= up_add_device); d72e31c9374627 Alex Williamson 2012-05-30 780 --- 0-DAY kernel test infrastructure Open Source Technology Cen= ter https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corpor= ation --===============4737480445801681503==--