Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3121120ybp; Sun, 6 Oct 2019 05:16:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqaa/7m/fOLODB9OFJhxNNnNsvZiwM+W4hPk9W76znviOvT3ycTMA18wAumRQxgzxlyOx3 X-Received: by 2002:a50:a5f8:: with SMTP id b53mr24290895edc.39.1570364178233; Sun, 06 Oct 2019 05:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570364178; cv=none; d=google.com; s=arc-20160816; b=CWXHmCUVCrwG869mmdEhgJ02tux8T3y1QOkNUZZB4/BcyTr6HygX3Dcn6d5rCMG9GS Jz2734wTOArwTQpLbjKX3OBqiYe2Wmye5SF870JD8HYDnxQq2R4ychFo7g0MnnoBIns+ eW9TATP64jTgyDOREhiVgZd8dd2l+rW98HvH5TW23g/uGDjH6coZ0sBPA+5gmU/wziZs cTHIxCv/SkubUQKtH1ujstTwOrak0FRMe944cMXpKL/+cXUXRk3VuIXsDuz3FiRt/Abi SeVmNvK+/XDIIN2cdkkGq9kI+sSDWBTODBTL8ERhPsFPJcx+vEDjXrs9GZztTMtOrY7v 11fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ge/CdO3/0tQB562o3BQeuHAyOBzySmsBqqqOB6QLRRM=; b=LSllNB845E4diyrl9wSp19W6uvoCJxLJmKARa7IOsosCXzyJR19YIFfO1DiDqlTmBN qpfDyHlcf7tm88U7ATWccu8H2PU9CNdlVSCPQnWSxaGvWeo9LfknGyj66Ct28miDsfxZ JXFdcmq4xXZDCV43s/IkoM+ymeOrWtsHrhMPmBtMbe8JT9oTmz+6Wz8er/zlQkl0EK9L DAP4YEsLBBIpHIAWDx02vcC0arDpErstFpkUe8y4qGSt/ZMLPv2F48x+Vh87lBg9tBn2 +kciUn18clWt+gJ2iSYb5+STzOGa8Mnun7HHC/sl5Sy+Cnz4twYlT4fA8d9tVa66xuss bA0g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a33si7160705edf.121.2019.10.06.05.15.53; Sun, 06 Oct 2019 05:16:18 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726421AbfJFMPj (ORCPT + 99 others); Sun, 6 Oct 2019 08:15:39 -0400 Received: from bmailout3.hostsharing.net ([176.9.242.62]:41257 "EHLO bmailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfJFMPj (ORCPT ); Sun, 6 Oct 2019 08:15:39 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id 10C0D1005D063; Sun, 6 Oct 2019 14:15:37 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id BDDED29FBEE; Sun, 6 Oct 2019 14:15:36 +0200 (CEST) Date: Sun, 6 Oct 2019 14:15:36 +0200 From: Lukas Wunner To: Mika Westerberg Cc: Oliver Neukum , linux-usb@vger.kernel.org, Anthony Wong , Mario.Limonciello@dell.com, Andreas Noever , Yehezkel Bernat , Michael Jamet , Rajmohan Mani , Greg Kroah-Hartman , Nicholas Johnson , Alan Stern , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 05/22] thunderbolt: Add helper macros to iterate over switch ports Message-ID: <20191006121536.6u7noudvfiri5h3s@wunner.de> References: <20191001113830.13028-1-mika.westerberg@linux.intel.com> <20191001113830.13028-6-mika.westerberg@linux.intel.com> <1570025874.2472.14.camel@suse.com> <20191002142859.GF2819@lahna.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191002142859.GF2819@lahna.fi.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 02, 2019 at 05:28:59PM +0300, Mika Westerberg wrote: > On Wed, Oct 02, 2019 at 04:17:54PM +0200, Oliver Neukum wrote: > > Am Dienstag, den 01.10.2019, 14:38 +0300 schrieb Mika Westerberg: > > > @@ -1975,10 +1972,8 @@ void tb_switch_suspend(struct tb_switch *sw) > > > if (err) > > > return; > > > > > > - for (i = 1; i <= sw->config.max_port_number; i++) { > > > - if (tb_port_has_remote(&sw->ports[i])) > > > - tb_switch_suspend(sw->ports[i].remote->sw); > > > - } > > > + tb_switch_for_each_remote_port(sw, i) > > > + tb_switch_suspend(sw->ports[i].remote->sw); > > > > This macro looks a bit prone to misunderstanding. > > I guess the function would be better if the test could be seen. > > The macro does not really save too many lines so I think I can just drop > this patch for now and keep these open-coded. Introducing a macro is fine. However instead of using an index "i" as iterator, I'd suggest using a pointer to struct tb_port. This reduces the horizontal width of the code because you can replace the "sw->ports[i]" with just "port". In most of the loops this also saves 1 line for an assignment: "struct tb_port *port = &sw->ports[i];" In fact, I've already proposed such a macro more than a year ago but it never got merged: https://lore.kernel.org/patchwork/patch/983863/ /** * tb_sw_for_each_port() - iterate over ports on a switch * @switch: pointer to struct tb_switch over whose ports shall be iterated * @port: pointer to struct tb_port which shall be used as the iterator * * Excludes port 0, which is the switch itself and therefore irrelevant for * most iterations. */ #define tb_sw_for_each_port(switch, port) \ for (port = &(switch)->ports[1]; \ port <= &(switch)->ports[(switch)->config.max_port_number]; \ port++) Thanks, Lukas