From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Devarsh Thakkar <devarsht@ti.com>,
Jai Luthra <jai.luthra@ideasonboard.com>
Subject: Re: [PATCH 12/19] media: i2c: ds90ub960: Add RX port iteration support
Date: Mon, 3 Feb 2025 09:27:46 +0000 [thread overview]
Message-ID: <Z6CMEkD5YLhJqQiI@kekkonen.localdomain> (raw)
In-Reply-To: <92c7ee5b-3495-4398-99dd-881c704c64c1@ideasonboard.com>
Moi,
On Fri, Jan 24, 2025 at 03:34:44PM +0200, Tomi Valkeinen wrote:
> Hi,
>
> On 15/01/2025 16:23, Sakari Ailus wrote:
> > Moi,
> >
> > On Fri, Jan 10, 2025 at 11:14:12AM +0200, Tomi Valkeinen wrote:
> > > The driver does a lot of iteration over the RX ports with for loops. In
> > > most cases the driver will skip unused RX ports. Also, in the future
> > > patches the FPD-Link IV support will be refreshed with TI's latest init
> > > sequences which involves a lot of additional iterations over the RX
> > > ports, often only for FPD-Link IV ports.
> > >
> > > To make the iteration simpler and to make it clearer what we're
> > > iterating over (all or only-active, all or only-fpd4), add macros and
> > > support functions for iterating the RX ports. Use the macros in the
> > > driver, replacing the for loops.
> > >
> > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> > > ---
> > > drivers/media/i2c/ds90ub960.c | 260 ++++++++++++++++++++++--------------------
> > > 1 file changed, 135 insertions(+), 125 deletions(-)
> > >
> > > diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c
> > > index bca858172942..02e22ae813fa 100644
> > > --- a/drivers/media/i2c/ds90ub960.c
> > > +++ b/drivers/media/i2c/ds90ub960.c
> > > @@ -649,6 +649,63 @@ static const struct ub960_format_info *ub960_find_format(u32 code)
> > > return NULL;
> > > }
> > > +struct ub960_rxport_iter {
> > > + unsigned int nport;
> > > + struct ub960_rxport *rxport;
> > > +};
> > > +
> > > +enum ub960_iter_flags {
> > > + UB960_ITER_ACTIVE_ONLY = BIT(0),
> > > + UB960_ITER_FPD4_ONLY = BIT(1),
> > > +};
> > > +
> > > +static struct ub960_rxport_iter ub960_iter_rxport(struct ub960_data *priv,
> > > + struct ub960_rxport_iter it,
> > > + enum ub960_iter_flags flags)
> > > +{
> > > + for (; it.nport < priv->hw_data->num_rxports; it.nport++) {
> > > + it.rxport = priv->rxports[it.nport];
> > > +
> > > + if ((flags & UB960_ITER_ACTIVE_ONLY) && !it.rxport)
> > > + continue;
> > > +
> > > + if ((flags & UB960_ITER_FPD4_ONLY) &&
> > > + it.rxport->cdr_mode != RXPORT_CDR_FPD4)
> > > + continue;
> > > +
> > > + return it;
> > > + }
> > > +
> > > + it.rxport = NULL;
> > > +
> > > + return it;
> > > +}
> > > +
> > > +#define for_each_rxport(priv) \
> >
> > it should be also an argument to the macro as it's visible outside it.
> >
> > And wouldn't it be reasonable to use a pointer instead for the purpsoe?
>
> You mean something like:
>
> struct ub960_rxport_iter it = { 0 };
>
> for_each_rxport(priv, &it) { }
>
> Then we leak the iterator, and I really hate it. I've fixed numerous bugs
> caused by such cases.
You can still define it for the loop only, just give it a name instead of
using a pre-determined name.
Could you also pass the iterator by reference instead of the value?
>
> Tomi
>
> >
> > > + for (struct ub960_rxport_iter it = \
> > > + ub960_iter_rxport(priv, (struct ub960_rxport_iter){ 0 }, \
> > > + 0); \
> > > + it.nport < (priv)->hw_data->num_rxports; \
> > > + it.nport++, it = ub960_iter_rxport(priv, it, 0))
> > > +
> > > +#define for_each_active_rxport(priv) \
> > > + for (struct ub960_rxport_iter it = \
> > > + ub960_iter_rxport(priv, (struct ub960_rxport_iter){ 0 }, \
> > > + UB960_ITER_ACTIVE_ONLY); \
> > > + it.nport < (priv)->hw_data->num_rxports; \
> > > + it.nport++, it = ub960_iter_rxport(priv, it, \
> > > + UB960_ITER_ACTIVE_ONLY))
> > > +
> > > +#define for_each_active_rxport_fpd4(priv) \
> > > + for (struct ub960_rxport_iter it = \
> > > + ub960_iter_rxport(priv, (struct ub960_rxport_iter){ 0 }, \
> > > + UB960_ITER_ACTIVE_ONLY | \
> > > + UB960_ITER_FPD4_ONLY); \
> > > + it.nport < (priv)->hw_data->num_rxports; \
> > > + it.nport++, it = ub960_iter_rxport(priv, it, \
> > > + UB960_ITER_ACTIVE_ONLY | \
> > > + UB960_ITER_FPD4_ONLY))
> >
>
--
Terveisin,
Sakari Ailus
next prev parent reply other threads:[~2025-02-03 9:27 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 9:14 [PATCH 00/19] media: i2c: ds90ub9xx: Error handling, UB9702 improvements Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 01/19] media: i2c: ds90ub953: Fix error prints Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 02/19] media: i2c: ds90ub913: Align ub913_read() with other similar functions Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 03/19] media: i2c: ds90ub9xx: Add err parameter to read/write funcs Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 04/19] media: i2c: ds90ub960: Add error handling to multiple places Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 05/19] media: i2c: ds90ub953: Add error handling to ub953_log_status() Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 06/19] media: i2c: ds90ub913: Add error handling to ub913_log_status() Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 07/19] media: i2c: ds90ub953: Speed-up I2C watchdog timer Tomi Valkeinen
2025-01-15 14:17 ` Sakari Ailus
2025-01-24 13:19 ` Tomi Valkeinen
2025-02-03 9:23 ` Sakari Ailus
2025-01-10 9:14 ` [PATCH 08/19] media: i2c: ds90ub960: Move UB9702 registers to a separate section Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 09/19] media: i2c: ds90ub960: Add UB9702 specific registers Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 10/19] media: i2c: ds90ub960: Split ub960_init_tx_ports() Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 11/19] media: i2c: ds90ub960: Refresh ub960_init_tx_ports_ub9702() Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 12/19] media: i2c: ds90ub960: Add RX port iteration support Tomi Valkeinen
2025-01-15 14:23 ` Sakari Ailus
2025-01-24 13:34 ` Tomi Valkeinen
2025-02-03 9:27 ` Sakari Ailus [this message]
2025-01-10 9:14 ` [PATCH 13/19] media: i2c: ds90ub960: Move all RX port init code into ub960_init_rx_ports() Tomi Valkeinen
2025-01-15 14:25 ` Sakari Ailus
2025-01-24 13:23 ` Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 14/19] media: i2c: ds90ub960: Remove old ub9702 RX port init code (SQUASH) Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 15/19] media: i2c: ds90ub960: Update UB9702 init sequences Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 16/19] media: i2c: ds90ub960: Enable SSCG for UB9702 Tomi Valkeinen
2025-01-15 14:26 ` Sakari Ailus
2025-01-15 16:04 ` Tomi Valkeinen
2025-01-16 9:58 ` Sakari Ailus
2025-01-16 10:05 ` Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 17/19] media: dt-bindings: ti,ds90ub960: Add "i2c-addr" link property Tomi Valkeinen
2025-01-11 10:31 ` Krzysztof Kozlowski
2025-01-14 11:50 ` Tomi Valkeinen
2025-01-15 8:40 ` Krzysztof Kozlowski
2025-01-15 17:19 ` Tomi Valkeinen
2025-01-15 20:25 ` Krzysztof Kozlowski
2025-01-15 15:53 ` Konstantin Ryabitsev
2025-01-15 16:09 ` Tomi Valkeinen
2025-01-15 16:46 ` Krzysztof Kozlowski
2025-01-15 17:14 ` Tomi Valkeinen
2025-01-10 9:14 ` [PATCH 18/19] media: i2c: ds90ub960: Configure serializer using back-channel Tomi Valkeinen
2025-01-15 14:29 ` Sakari Ailus
2025-01-24 13:29 ` Tomi Valkeinen
2025-02-03 9:28 ` Sakari Ailus
2025-01-10 9:14 ` [PATCH 19/19] media: i2c: ds90ub9xx: Set serializer temperature ramp Tomi Valkeinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z6CMEkD5YLhJqQiI@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=devarsht@ti.com \
--cc=jai.luthra@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®