Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751517AbbLUNEC (ORCPT ); Mon, 21 Dec 2015 08:04:02 -0500 Received: from mga14.intel.com ([192.55.52.115]:4874 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751342AbbLUNEA (ORCPT ); Mon, 21 Dec 2015 08:04:00 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,459,1444719600"; d="scan'208";a="878200448" Message-ID: <5677F9F7.8060201@linux.intel.com> Date: Mon, 21 Dec 2015 15:09:11 +0200 From: Mathias Nyman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Julia Lawall , Geliang Tang CC: Mathias Nyman , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/9] usb: xhci: use list_for_each_entry References: <201512190233.xPC4M6l4%fengguang.wu@intel.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1660 Lines: 45 On 18.12.2015 20:30, Julia Lawall wrote: > Geliang, > > Please check whether it is acceptable that last_unlinked_td point to the > dummy entry at th beginning of the list, in the case where the > list_for_each_entry loop runs out normally. > > It seems that you have sent a bunch of these patches. Please recheck them > all to see if they really follow the semantics of list_for_each_entry > properly. If particular, you should not normally use the index variable > after leaving the loop, unless it is guaranteed that the exit from the > loop was via a break. > Julia is correct, we can't use list_for_each_entry() here as cur_td would end up pointing to list head, and we really need it to point to the last entry in the list at that point. old: - list_for_each(entry, &ep->cancelled_td_list) { - cur_td = list_entry(entry, struct xhci_td, cancelled_td_list); cur_td_will point to last element in list. "entry" will point to head, but is on longer used. new: + list_for_each_entry(cur_td, &ep->cancelled_td_list, cancelled_td_list) { cur_td will point to head of list. This is important as newly canceled TDs can be added to the tail of the list while looping through and returning the canceled TDs. We want to make sure we only return and delete the TDs up to the point we have handled them on the ring. (code continues with: last_unlinked_td = cur_td;) Thanks Julia for spotting this -Mathias -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/