From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com [209.85.128.182]) by dpdk.org (Postfix) with ESMTP id 54CC17D4F for ; Wed, 23 Aug 2017 15:05:47 +0200 (CEST) Received: by mail-wr0-f182.google.com with SMTP id k46so121717wre.2 for ; Wed, 23 Aug 2017 06:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8UVefeVblDWA0uu62sgkaw0Lw4kkAcpWbz1CByLzR24=; b=qQBBw886RRie0/Itoun4+JNvCCoc9AdnLb1l/eAJ9A9nsYxN9oVPuld5TAVc6RNrlj NNzEXHC/7MOvroyJgq0KE6k3OzEguqok7iFeg+JV5uG3lHQNp1Te5dXAUfv0sp4nGJ68 svlhbLHOaDdNUNggovItHt+vZvFf/4T8drO/LLStOEuGpG6EH/V/pwhaJTmMCC55LNzi R/WgtAxcXX1vbbpXLU1k0qRTSMeH/VA0eGOq8UQQheJcyce3rlkD7a6uCXhbZfWl7qXc 7aIdYUdUGI3G7rSebuNKr3WW70Lvk+RwLY6dO411WO4mnfw98iN+FzdLBry2qbz+saqf dTbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8UVefeVblDWA0uu62sgkaw0Lw4kkAcpWbz1CByLzR24=; b=MjlCqQZ1uptD2czvsu2vxn8THxOs6nJCcTogWK+IWTy2kVJETzBkHja6IcvqBCg0oM AQgb8NOeMoRmnN+q9O5sw4ilmR5CIobgjq5+b8sPx0ZeX6er4T2slp/Xe5O8ttzMi+RI X84OCqQmIsFHvFpOhLB6h+xuqJYq0raUYb40oiv33H8UXfhJ8qvbochLfLNLolP3fd3x cC7bmw2o1u0A/1moc0/Q0NulI6GXD498CwvRJinpdBmBbD/GpXdqrVu7zVvHUhEpn5pq siUjEsK7vXwXKiep9yiiztQOhynAyZAL3cB7xi1LyAUuMzvR2guWUijhUJjdSkDNuGNZ qFDQ== X-Gm-Message-State: AHYfb5iDZXAGadAC/aEj+6pEK5ZjpT7OePDjQwcGDHVFbPAFkKdgRIfV j18PgISoTOYv7s9h/dk= X-Received: by 10.223.135.12 with SMTP id a12mr1454375wra.253.1503493546626; Wed, 23 Aug 2017 06:05:46 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 190sm2634183wmy.13.2017.08.23.06.05.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Aug 2017 06:05:45 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 23 Aug 2017 15:05:30 +0200 Message-Id: <1503493530-22569-1-git-send-email-gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1502985129-7461-1-git-send-email-gaetan.rivet@6wind.com> References: <1502985129-7461-1-git-send-email-gaetan.rivet@6wind.com> Subject: [dpdk-dev] [PATCH v2] net/failsafe: safer subdev iterator X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Aug 2017 13:05:47 -0000 The sub_device iterator macro should follow the general gist of the tailq API for an easier understanding and safer use. Once the loop has finished, the iterator should be set to NULL. If no sub_device was iterated upon, the iterator should still be NULL. Signed-off-by: Gaetan Rivet --- v2: - Rewrite fs_find_next to simplify the macro using it. drivers/net/failsafe/failsafe_private.h | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index 0361cf4..19d36ab 100644 --- a/drivers/net/failsafe/failsafe_private.h +++ b/drivers/net/failsafe/failsafe_private.h @@ -220,10 +220,10 @@ extern int mac_from_arg; * dev: (struct rte_eth_dev *), fail-safe ethdev * state: (enum dev_state), minimum acceptable device state */ -#define FOREACH_SUBDEV_STATE(s, i, dev, state) \ - for (i = fs_find_next((dev), 0, state); \ - i < PRIV(dev)->subs_tail && (s = &PRIV(dev)->subs[i]); \ - i = fs_find_next((dev), i + 1, state)) +#define FOREACH_SUBDEV_STATE(s, i, dev, state) \ + for (s = fs_find_next((dev), 0, state, &i); \ + s != NULL; \ + s = fs_find_next((dev), i + 1, state, &i)) /** * Iterator construct over fail-safe sub-devices: @@ -294,18 +294,26 @@ extern int mac_from_arg; /* inlined functions */ -static inline uint8_t -fs_find_next(struct rte_eth_dev *dev, uint8_t sid, - enum dev_state min_state) +static inline struct sub_device * +fs_find_next(struct rte_eth_dev *dev, + uint8_t sid, + enum dev_state min_state, + uint8_t *sid_out) { - while (sid < PRIV(dev)->subs_tail) { - if (PRIV(dev)->subs[sid].state >= min_state) + struct sub_device *subs; + uint8_t tail; + + subs = PRIV(dev)->subs; + tail = PRIV(dev)->subs_tail; + while (sid < tail) { + if (subs[sid].state >= min_state) break; sid++; } - if (sid >= PRIV(dev)->subs_tail) - return PRIV(dev)->subs_tail; - return sid; + *sid_out = sid; + if (sid >= tail) + return NULL; + return &subs[sid]; } /* -- 2.1.4