From: Rob Herring <robh@kernel.org>
To: Anup Patel <apatel@ventanamicro.com>
Cc: devicetree@vger.kernel.org,
Saravana Kannan <saravanak@google.com>,
Anup Patel <anup@brainfault.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
linux-kernel@vger.kernel.org, Palmer Dabbelt <palmer@dabbelt.com>,
Atish Patra <atishp@atishpatra.org>,
linux-riscv@lists.infradead.org,
Andrew Jones <ajones@ventanamicro.com>
Subject: Re: [PATCH v2] of: property: Add fw_devlink support for interrupt-map property
Date: Tue, 16 Apr 2024 09:10:49 -0500 [thread overview]
Message-ID: <20240416141049.GA2148267-robh@kernel.org> (raw)
In-Reply-To: <20240413091942.316054-1-apatel@ventanamicro.com>
On Sat, Apr 13, 2024 at 02:49:42PM +0530, Anup Patel wrote:
> Some of the PCI controllers (such as generic PCI host controller)
> use "interrupt-map" DT property to describe the mapping between
> PCI endpoints and PCI interrupt pins. This the only case where
> the interrupts are not described in DT.
>
> Currently, there is no fw_devlink created based on "interrupt-map"
> DT property so interrupt controller is not guaranteed to be probed
> before PCI host controller. This affects every platform where both
> PCI host controller and interrupt controllers are probed as regular
> platform devices.
>
> This creates fw_devlink between consumers (PCI host controller) and
> supplier (interrupt controller) based on "interrupt-map" DT property.
>
> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> ---
> Changes since v1:
> - Updated commit description based on Rob's suggestion
> - Use of_irq_parse_raw() for parsing interrupt-map DT property
> ---
> drivers/of/property.c | 58 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 58 insertions(+)
>
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index a6358ee99b74..67be66384dac 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -1311,6 +1311,63 @@ static struct device_node *parse_interrupts(struct device_node *np,
> return of_irq_parse_one(np, index, &sup_args) ? NULL : sup_args.np;
> }
>
> +static struct device_node *parse_interrupt_map(struct device_node *np,
> + const char *prop_name, int index)
> +{
> + const __be32 *imap, *imap_end, *addr;
> + struct of_phandle_args sup_args;
> + struct device_node *tn, *ipar;
> + u32 addrcells, intcells;
> + int i, j, imaplen;
> +
> + if (!IS_ENABLED(CONFIG_OF_IRQ))
> + return NULL;
> +
> + if (strcmp(prop_name, "interrupt-map"))
> + return NULL;
> +
> + ipar = of_node_get(np);
> + do {
> + if (!of_property_read_u32(ipar, "#interrupt-cells", &intcells))
> + break;
> + tn = ipar;
> + ipar = of_irq_find_parent(ipar);
> + of_node_put(tn);
> + } while (ipar);
No need for this loop. We've only gotten here if 'interrupt-map' is
present in the node and '#interrupt-cells' is required if
'interrupt-map' is present.
> + if (!ipar)
> + return NULL;
> + addrcells = of_bus_n_addr_cells(ipar);
> + of_node_put(ipar);
> +
> + imap = of_get_property(np, "interrupt-map", &imaplen);
> + if (!imap || imaplen <= (addrcells + intcells))
> + return NULL;
> + imap_end = imap + imaplen;
> +
> + sup_args.np = NULL;
> + for (i = 0; i <= index && imap < imap_end; i++) {
> + if (sup_args.np) {
> + of_node_put(sup_args.np);
> + sup_args.np = NULL;
> + }
> +
> + addr = imap;
> + imap += addrcells;
> +
> + sup_args.np = np;
> + sup_args.args_count = intcells;
> + for (j = 0; j < intcells; j++)
> + sup_args.args[j] = be32_to_cpu(imap[j]);
> + imap += intcells;
> +
> + if (of_irq_parse_raw(addr, &sup_args))
> + return NULL;
> + imap += sup_args.args_count + 1;
> + }
Doesn't this leak a ref on the last time the function is invoked? For
example, if we have 2 entries and index is 2. We'll get index=1, but
then exit because imap==imap_end. We need a put on index==1 node.
Look at my next branch where I've converted things to use __free()
cleanups. I don't see it helping here as-is, but maybe when it is
correct.
Rob
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Rob Herring <robh@kernel.org>
To: Anup Patel <apatel@ventanamicro.com>
Cc: Saravana Kannan <saravanak@google.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Atish Patra <atishp@atishpatra.org>,
Andrew Jones <ajones@ventanamicro.com>,
Sunil V L <sunilvl@ventanamicro.com>,
Anup Patel <anup@brainfault.org>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v2] of: property: Add fw_devlink support for interrupt-map property
Date: Tue, 16 Apr 2024 09:10:49 -0500 [thread overview]
Message-ID: <20240416141049.GA2148267-robh@kernel.org> (raw)
In-Reply-To: <20240413091942.316054-1-apatel@ventanamicro.com>
On Sat, Apr 13, 2024 at 02:49:42PM +0530, Anup Patel wrote:
> Some of the PCI controllers (such as generic PCI host controller)
> use "interrupt-map" DT property to describe the mapping between
> PCI endpoints and PCI interrupt pins. This the only case where
> the interrupts are not described in DT.
>
> Currently, there is no fw_devlink created based on "interrupt-map"
> DT property so interrupt controller is not guaranteed to be probed
> before PCI host controller. This affects every platform where both
> PCI host controller and interrupt controllers are probed as regular
> platform devices.
>
> This creates fw_devlink between consumers (PCI host controller) and
> supplier (interrupt controller) based on "interrupt-map" DT property.
>
> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> ---
> Changes since v1:
> - Updated commit description based on Rob's suggestion
> - Use of_irq_parse_raw() for parsing interrupt-map DT property
> ---
> drivers/of/property.c | 58 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 58 insertions(+)
>
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index a6358ee99b74..67be66384dac 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -1311,6 +1311,63 @@ static struct device_node *parse_interrupts(struct device_node *np,
> return of_irq_parse_one(np, index, &sup_args) ? NULL : sup_args.np;
> }
>
> +static struct device_node *parse_interrupt_map(struct device_node *np,
> + const char *prop_name, int index)
> +{
> + const __be32 *imap, *imap_end, *addr;
> + struct of_phandle_args sup_args;
> + struct device_node *tn, *ipar;
> + u32 addrcells, intcells;
> + int i, j, imaplen;
> +
> + if (!IS_ENABLED(CONFIG_OF_IRQ))
> + return NULL;
> +
> + if (strcmp(prop_name, "interrupt-map"))
> + return NULL;
> +
> + ipar = of_node_get(np);
> + do {
> + if (!of_property_read_u32(ipar, "#interrupt-cells", &intcells))
> + break;
> + tn = ipar;
> + ipar = of_irq_find_parent(ipar);
> + of_node_put(tn);
> + } while (ipar);
No need for this loop. We've only gotten here if 'interrupt-map' is
present in the node and '#interrupt-cells' is required if
'interrupt-map' is present.
> + if (!ipar)
> + return NULL;
> + addrcells = of_bus_n_addr_cells(ipar);
> + of_node_put(ipar);
> +
> + imap = of_get_property(np, "interrupt-map", &imaplen);
> + if (!imap || imaplen <= (addrcells + intcells))
> + return NULL;
> + imap_end = imap + imaplen;
> +
> + sup_args.np = NULL;
> + for (i = 0; i <= index && imap < imap_end; i++) {
> + if (sup_args.np) {
> + of_node_put(sup_args.np);
> + sup_args.np = NULL;
> + }
> +
> + addr = imap;
> + imap += addrcells;
> +
> + sup_args.np = np;
> + sup_args.args_count = intcells;
> + for (j = 0; j < intcells; j++)
> + sup_args.args[j] = be32_to_cpu(imap[j]);
> + imap += intcells;
> +
> + if (of_irq_parse_raw(addr, &sup_args))
> + return NULL;
> + imap += sup_args.args_count + 1;
> + }
Doesn't this leak a ref on the last time the function is invoked? For
example, if we have 2 entries and index is 2. We'll get index=1, but
then exit because imap==imap_end. We need a put on index==1 node.
Look at my next branch where I've converted things to use __free()
cleanups. I don't see it helping here as-is, but maybe when it is
correct.
Rob
next prev parent reply other threads:[~2024-04-16 14:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-13 9:19 [PATCH v2] of: property: Add fw_devlink support for interrupt-map property Anup Patel
2024-04-13 9:19 ` Anup Patel
2024-04-16 14:10 ` Rob Herring [this message]
2024-04-16 14:10 ` Rob Herring
2024-04-17 1:03 ` Saravana Kannan
2024-04-17 1:03 ` Saravana Kannan
2024-04-17 6:34 ` Anup Patel
2024-04-17 6:34 ` Anup Patel
2024-04-17 6:55 ` Anup Patel
2024-04-17 6:55 ` Anup Patel
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=20240416141049.GA2148267-robh@kernel.org \
--to=robh@kernel.org \
--cc=ajones@ventanamicro.com \
--cc=anup@brainfault.org \
--cc=apatel@ventanamicro.com \
--cc=atishp@atishpatra.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=saravanak@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.