Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp433573imj; Thu, 7 Feb 2019 06:35:34 -0800 (PST) X-Google-Smtp-Source: AHgI3IZwiYfafA4kJ5HBxpMuGB1Olzm0DJImi/afifJes8EwQxEE88aobErkUxf1yo4XSpaFqK95 X-Received: by 2002:a63:6bc1:: with SMTP id g184mr15402669pgc.25.1549550134429; Thu, 07 Feb 2019 06:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549550134; cv=none; d=google.com; s=arc-20160816; b=ja+hiN3Cd7olJHBjA5agJwFVJsB1izY+Y3cswHBfSujLRmcZ2v3srf1CSsp0UucPxp A5eEF8UaP4A9Mo85Rx/KMbj3cK7C8B4+OPpW2zwto0FRCcppposUXeabzS/aAWX4w2Ws uuUXNa0ZMjayUKx2JxPepIPGveZvPCLGfNbqjuxuNlgMrbB8Pk9NrlQGDD0Tg6Ef+4dA Sjbof+A86usnjJ0r3BWR46xOwQKVkivuoYTQwnqi7uEqlIIATCCzB6rj93SsI9gng5GR DwE/z7pgBk3b11gxXFlMxeWjSXeX3C5vwLyODrdZLxgcZEnSelq75G4A1kvqLjK6ripg Il9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=br9fvDDCfIIQFyACs2t+AbB1+mKp1ZWx5Q+hIvwptpw=; b=VlVNsdT47Xcid86yUpxNsNiL3bid29azqrz4iAFlH5FWzT4ucEmM+InROk6jxJxuER Ds7A99XRFdwDfaL1/X5TW6sg3a4qsZRSIFwLuBcOt/FoJZkkQsle6yKSQTZ2LSTUKg16 7B3fpnf4MTgLOnNqCpx+kAzrGBxpHasLthiZmsvP+eI3VctZPgu2Qc3AEY+kMWjefu41 F/CUCJ1Yr8jrbwmPgWVEMCQ7xTdbdCNPSAOTF1X8pChumPyJRyFiVy9qucJIa7Zmv5IM CMihzfBOKJoBUHKiEycrRE7XAEp/kUPYmAeJmoMovcOI7RYw28u6DKV3HVs/8I99DOvw zORw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r10si5596478pgr.489.2019.02.07.06.35.17; Thu, 07 Feb 2019 06:35:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727125AbfBGOdQ (ORCPT + 99 others); Thu, 7 Feb 2019 09:33:16 -0500 Received: from mga07.intel.com ([134.134.136.100]:19576 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726809AbfBGOdQ (ORCPT ); Thu, 7 Feb 2019 09:33:16 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Feb 2019 06:33:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,344,1544515200"; d="scan'208";a="136642324" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by orsmga001.jf.intel.com with ESMTP; 07 Feb 2019 06:33:13 -0800 Received: from andy by smile with local (Exim 4.92-RC5) (envelope-from ) id 1grkjo-0006Te-J6; Thu, 07 Feb 2019 16:33:12 +0200 Date: Thu, 7 Feb 2019 16:33:12 +0200 From: Andy Shevchenko To: Mika Westerberg Cc: linux-kernel@vger.kernel.org, Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , netdev@vger.kernel.org Subject: Re: [PATCH v2 13/28] thunderbolt: Add helper function to iterate from one port to another Message-ID: <20190207143312.GI9224@smile.fi.intel.com> References: <20190206131738.43696-1-mika.westerberg@linux.intel.com> <20190206131738.43696-14-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190206131738.43696-14-mika.westerberg@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 06, 2019 at 04:17:23PM +0300, Mika Westerberg wrote: > We need to be able to walk from one port to another when we are creating > paths where there are multiple switches between two ports. For this > reason introduce a new function tb_port_get_next() and a new macro > tb_for_each_port(). > +struct tb_port *tb_port_get_next(struct tb_port *start, struct tb_port *end, > + struct tb_port *prev) > +{ > + struct tb_port *port, *next; > + > + if (!prev) > + return start; > + > + if (prev->sw == end->sw) { > + if (prev != end) > + return end; > + return NULL; I would prefer to see the similar pattern as you used below, i.e. when we have an "bail out" condition, check for it. if (prev == end) return NULL; return end; > + } > + > + /* Switch back to use primary links for walking */ > + if (prev->dual_link_port && prev->link_nr) > + port = prev->dual_link_port; > + else > + port = prev; > + > + if (start->sw->config.depth < end->sw->config.depth) { > + if (port->remote && > + port->remote->sw->config.depth > port->sw->config.depth) > + next = port->remote; > + else > + next = tb_port_at(tb_route(end->sw), port->sw); > + } else if (start->sw->config.depth > end->sw->config.depth) { > + if (tb_is_upstream_port(port)) > + next = port->remote; > + else > + next = tb_upstream_port(port->sw); > + } else { > + /* Must be the same switch then */ > + if (start->sw != end->sw) > + return NULL; > + return end; Here is a good pattern. > + } > + > + /* If prev was dual link return another end of that link then */ > + if (next->dual_link_port && next->link_nr != prev->link_nr) > + return next->dual_link_port; > + > + return next; > +} -- With Best Regards, Andy Shevchenko