* [dpdk-dev] [PATCH] net/failsafe: safer subdev iterator @ 2017-08-17 15:52 Gaetan Rivet 2017-08-18 0:39 ` Stephen Hemminger 2017-08-23 13:05 ` [dpdk-dev] [PATCH v2] " Gaetan Rivet 0 siblings, 2 replies; 5+ messages in thread From: Gaetan Rivet @ 2017-08-17 15:52 UTC (permalink / raw) To: dev; +Cc: Gaetan Rivet 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 <gaetan.rivet@6wind.com> --- drivers/net/failsafe/failsafe_private.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index 0361cf4..6fa8de5 100644 --- a/drivers/net/failsafe/failsafe_private.h +++ b/drivers/net/failsafe/failsafe_private.h @@ -222,6 +222,7 @@ extern int mac_from_arg; */ #define FOREACH_SUBDEV_STATE(s, i, dev, state) \ for (i = fs_find_next((dev), 0, state); \ + ((s = NULL) == NULL) && \ i < PRIV(dev)->subs_tail && (s = &PRIV(dev)->subs[i]); \ i = fs_find_next((dev), i + 1, state)) -- 2.1.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH] net/failsafe: safer subdev iterator 2017-08-17 15:52 [dpdk-dev] [PATCH] net/failsafe: safer subdev iterator Gaetan Rivet @ 2017-08-18 0:39 ` Stephen Hemminger 2017-08-18 7:43 ` Gaëtan Rivet 2017-08-23 13:05 ` [dpdk-dev] [PATCH v2] " Gaetan Rivet 1 sibling, 1 reply; 5+ messages in thread From: Stephen Hemminger @ 2017-08-18 0:39 UTC (permalink / raw) To: Gaetan Rivet; +Cc: dev On Thu, 17 Aug 2017 17:52:09 +0200 Gaetan Rivet <gaetan.rivet@6wind.com> wrote: > 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 <gaetan.rivet@6wind.com> > --- > drivers/net/failsafe/failsafe_private.h | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h > index 0361cf4..6fa8de5 100644 > --- a/drivers/net/failsafe/failsafe_private.h > +++ b/drivers/net/failsafe/failsafe_private.h > @@ -222,6 +222,7 @@ extern int mac_from_arg; > */ > #define FOREACH_SUBDEV_STATE(s, i, dev, state) \ > for (i = fs_find_next((dev), 0, state); \ > + ((s = NULL) == NULL) && \ I assume you are trying to do assignment inside an expression and just expect that to always to be true and go onto next part of assignment. This is a convulted way to put code in the loop iterator. But this macro is way too complex. Please break it up into inline functions or figure out how to simplify the logic better. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH] net/failsafe: safer subdev iterator 2017-08-18 0:39 ` Stephen Hemminger @ 2017-08-18 7:43 ` Gaëtan Rivet 0 siblings, 0 replies; 5+ messages in thread From: Gaëtan Rivet @ 2017-08-18 7:43 UTC (permalink / raw) To: Stephen Hemminger; +Cc: dev On Thu, Aug 17, 2017 at 05:39:29PM -0700, Stephen Hemminger wrote: > On Thu, 17 Aug 2017 17:52:09 +0200 > Gaetan Rivet <gaetan.rivet@6wind.com> wrote: > > > 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 <gaetan.rivet@6wind.com> > > --- > > drivers/net/failsafe/failsafe_private.h | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h > > index 0361cf4..6fa8de5 100644 > > --- a/drivers/net/failsafe/failsafe_private.h > > +++ b/drivers/net/failsafe/failsafe_private.h > > @@ -222,6 +222,7 @@ extern int mac_from_arg; > > */ > > #define FOREACH_SUBDEV_STATE(s, i, dev, state) \ > > for (i = fs_find_next((dev), 0, state); \ > > + ((s = NULL) == NULL) && \ > I assume you are trying to do assignment inside an expression and just expect that > to always to be true and go onto next part of assignment. This is a convulted > way to put code in the loop iterator. > > But this macro is way too complex. Please break it up into inline functions or > figure out how to simplify the logic better. I think you are right, thanks for the wake-up call. -- Gaëtan Rivet 6WIND ^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [PATCH v2] net/failsafe: safer subdev iterator 2017-08-17 15:52 [dpdk-dev] [PATCH] net/failsafe: safer subdev iterator Gaetan Rivet 2017-08-18 0:39 ` Stephen Hemminger @ 2017-08-23 13:05 ` Gaetan Rivet 2017-08-28 12:30 ` Ferruh Yigit 1 sibling, 1 reply; 5+ messages in thread From: Gaetan Rivet @ 2017-08-23 13:05 UTC (permalink / raw) To: dev; +Cc: Gaetan Rivet 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 <gaetan.rivet@6wind.com> --- 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH v2] net/failsafe: safer subdev iterator 2017-08-23 13:05 ` [dpdk-dev] [PATCH v2] " Gaetan Rivet @ 2017-08-28 12:30 ` Ferruh Yigit 0 siblings, 0 replies; 5+ messages in thread From: Ferruh Yigit @ 2017-08-28 12:30 UTC (permalink / raw) To: Gaetan Rivet, dev On 8/23/2017 2:05 PM, Gaetan Rivet wrote: > 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 <gaetan.rivet@6wind.com> Applied to dpdk-next-net/master, thanks. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-08-28 12:30 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-08-17 15:52 [dpdk-dev] [PATCH] net/failsafe: safer subdev iterator Gaetan Rivet 2017-08-18 0:39 ` Stephen Hemminger 2017-08-18 7:43 ` Gaëtan Rivet 2017-08-23 13:05 ` [dpdk-dev] [PATCH v2] " Gaetan Rivet 2017-08-28 12:30 ` Ferruh Yigit
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).