From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Anup Patel <apatel@ventanamicro.com>
Cc: "Jassi Brar" <jassisinghbrar@gmail.com>,
"Atish Patra" <atish.patra@linux.dev>,
"Michael Turquette" <mturquette@baylibre.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
linux-riscv@lists.infradead.org, linux-clk@vger.kernel.org,
"Rob Herring" <robh@kernel.org>,
"Anup Patel" <anup@brainfault.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Rafael J . Wysocki" <rafael@kernel.org>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Andrew Jones" <ajones@ventanamicro.com>,
devicetree@vger.kernel.org, "Conor Dooley" <conor+dt@kernel.org>,
"Leyfoon Tan" <leyfoon.tan@starfivetech.com>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Mika Westerberg" <mika.westerberg@linux.intel.com>,
"Stephen Boyd" <sboyd@kernel.org>,
linux-kernel@vger.kernel.org,
"Samuel Holland" <samuel.holland@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Rahul Pathak" <rpathak@ventanamicro.com>,
"Len Brown" <lenb@kernel.org>
Subject: Re: [PATCH v3 10/23] clk: Add clock driver for the RISC-V RPMI clock service group
Date: Mon, 12 May 2025 10:07:56 +0300 [thread overview]
Message-ID: <aCGeTPS4WiGYMTTo@smile.fi.intel.com> (raw)
In-Reply-To: <20250511133939.801777-11-apatel@ventanamicro.com>
On Sun, May 11, 2025 at 07:09:26PM +0530, Anup Patel wrote:
> From: Rahul Pathak <rpathak@ventanamicro.com>
>
> The RPMI specification defines a clock service group which can be
> accessed via SBI MPXY extension or dedicated S-mode RPMI transport.
>
> Add mailbox client based clock driver for the RISC-V RPMI clock
> service group.
...
> +#include <linux/clk-provider.h>
> +#include <linux/err.h>
> +#include <linux/mailbox_client.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/mailbox/riscv-rpmi-message.h>
Just to point out again that the above misses a lot of headers definitions
and/or APIs this driver uses. Follow IWYU principle.
...
> +#define GET_RATE_U64(hi_u32, lo_u32) ((u64)(hi_u32) << 32 | (lo_u32))
Hmm... Perhaps add this kind of macro to wordpart.h ? IIRC not only this driver
uses something like this.
...
> +enum rpmi_clk_type {
> + RPMI_CLK_DISCRETE = 0,
> + RPMI_CLK_LINEAR = 1,
> + RPMI_CLK_TYPE_MAX_IDX,
No comma for the terminator. Please, clean all these cases.
> +};
...
> +union rpmi_clk_rates {
> + u64 discrete[RPMI_CLK_DISCRETE_MAX_NUM_RATES];
> + struct {
> + u64 min;
> + u64 max;
> + u64 step;
> + } linear;
Have you looked at the linear ranges library we have in the kernel? Can you
utilise it here?
> +};
...
> +struct rpmi_clk {
> + struct rpmi_clk_context *context;
> + u32 id;
> + u32 num_rates;
> + u32 transition_latency;
> + enum rpmi_clk_type type;
> + union rpmi_clk_rates *rates;
> + char name[RPMI_CLK_NAME_LEN];
> + struct clk_hw hw;
Just a reminder to use `pahole` to check that your data layout is optimised for
memory consumption.
> +};
...
> +struct rpmi_get_supp_rates_rx {
> + u32 status;
> + u32 flags;
> + u32 remaining;
> + u32 returned;
> + u32 rates[];
> +};
Is it ABI? (I mean if this is interface with some kind of FW)
If so, Use proper endianess aware types. Same Q for all data
types defined in this driver.
...
> + for (j = 0; j < rx->returned; j++) {
> + if (rateidx >= (clk_rate_idx + rx->returned))
Too many parentheses.
> + break;
> + rpmi_clk->rates->discrete[rateidx++] =
> + GET_RATE_U64(rate_discrete[j].hi,
> + rate_discrete[j].lo);
> + }
> + }
...
> + devm_kfree(context->dev, rx);
Why?! This is a red flag to point that here is misunderstanding or abuse of
managed resources approach. Either use __Free() from cleanup.h or don't call
devm_kfree(). The latter must have a very good justification to explain why.
> + return 0;
(this is even not an error path, where it might have a little argument for)
...
> + /* Keep the requested rate if the clock format
> + * is of discrete type. Let the platform which
> + * is actually controlling the clock handle that.
> + */
/*
* Use proper style for the multi-line comments. You can
* refer to this comment as an example.
*/
...
> +out:
Redundant label. Note, the labels are recommended to be named after the flow
they will run if goto. This one can be named as out_literally_with_return_0,
which makes it obvious how useless it is.
> + return 0;
...
> + rates = devm_kzalloc(dev, sizeof(union rpmi_clk_rates), GFP_KERNEL);
sizeof(*...)
> + if (!rates)
> + return ERR_PTR(-ENOMEM);
> +
> + rpmi_clk = devm_kzalloc(dev, sizeof(struct rpmi_clk), GFP_KERNEL);
Ditto.
> + if (!rpmi_clk)
> + return ERR_PTR(-ENOMEM);
...
> + ret = rpmi_clk_get_supported_rates(clkid, rpmi_clk);
> + if (ret)
> + return dev_err_ptr_probe(dev, ret,
> + "Get supported rates failed for clk-%u, %d\n", clkid, ret);
Indentation issues. Repetitive ret in the message. Please, get familiar with
the format dev_err_probe() uses.
...
> + int ret, num_clocks, i;
Why is 'i' signed?
...
> + /* Allocate RPMI clock context */
> + context = devm_kzalloc(dev, sizeof(*context), GFP_KERNEL);
Ha-ha, you have even inconsistent style in the same file! So, go through the
whole series and make sure that the style used in each file is consistent.
> + if (!context)
> + return -ENOMEM;
...
> + /* Validate RPMI specification version */
> + rpmi_mbox_init_get_attribute(&msg, RPMI_MBOX_ATTR_SPEC_VERSION);
> + ret = rpmi_mbox_send_message(context->chan, &msg);
> + if (ret) {
> + dev_err_probe(dev, ret, "Failed to get spec version\n");
> + goto fail_free_channel;
This is simply wrong. You should not do goto before any devm_*() calls.
The error path and ->remove(), if present) is broken. Fix it accordingly.
Here should be
return dev_err_probe(...);
it's your homework to understand how to achieve that. Plenty of the examples in
the kernel.
> + }
...
> +enum rpmi_clock_service_id {
> + RPMI_CLK_SRV_ENABLE_NOTIFICATION = 0x01,
> + RPMI_CLK_SRV_GET_NUM_CLOCKS = 0x02,
> + RPMI_CLK_SRV_GET_ATTRIBUTES = 0x03,
> + RPMI_CLK_SRV_GET_SUPPORTED_RATES = 0x04,
> + RPMI_CLK_SRV_SET_CONFIG = 0x05,
> + RPMI_CLK_SRV_GET_CONFIG = 0x06,
> + RPMI_CLK_SRV_SET_RATE = 0x07,
> + RPMI_CLK_SRV_GET_RATE = 0x08,
> + RPMI_CLK_SRV_ID_MAX_COUNT,
No comma in the terminator line.
> +};
--
With Best Regards,
Andy Shevchenko
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-05-12 7:08 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-11 13:39 [PATCH v3 00/23] Linux SBI MPXY and RPMI drivers Anup Patel
2025-05-11 13:39 ` [PATCH v3 01/23] riscv: Add new error codes defined by SBI v3.0 Anup Patel
2025-05-11 13:39 ` [PATCH v3 02/23] dt-bindings: mailbox: Add bindings for RPMI shared memory transport Anup Patel
2025-05-19 17:26 ` Rob Herring
2025-05-21 6:12 ` Anup Patel
2025-05-11 13:39 ` [PATCH v3 03/23] dt-bindings: mailbox: Add bindings for RISC-V SBI MPXY extension Anup Patel
2025-05-11 13:39 ` [PATCH v3 04/23] RISC-V: Add defines for the SBI message proxy extension Anup Patel
2025-05-11 13:39 ` [PATCH v3 05/23] mailbox: Add common header for RPMI messages sent via mailbox Anup Patel
2025-05-11 13:39 ` [PATCH v3 06/23] mailbox: Allow controller specific mapping using fwnode Anup Patel
2025-05-11 13:39 ` [PATCH v3 07/23] mailbox: Add RISC-V SBI message proxy (MPXY) based mailbox driver Anup Patel
2025-05-12 18:54 ` Thomas Gleixner
2025-05-21 6:08 ` Anup Patel
2025-05-11 13:39 ` [PATCH v3 08/23] dt-bindings: clock: Add RPMI clock service message proxy bindings Anup Patel
2025-05-11 13:39 ` [PATCH v3 09/23] dt-bindings: clock: Add RPMI clock service controller bindings Anup Patel
2025-05-11 13:39 ` [PATCH v3 10/23] clk: Add clock driver for the RISC-V RPMI clock service group Anup Patel
2025-05-12 7:07 ` Andy Shevchenko [this message]
2025-05-12 9:58 ` Rahul Pathak
2025-05-12 14:15 ` Andy Shevchenko
2025-05-22 13:14 ` Rahul Pathak
2025-05-23 16:35 ` Andy Shevchenko
2025-05-11 13:39 ` [PATCH v3 11/23] dt-bindings: Add RPMI system MSI message proxy bindings Anup Patel
2025-05-11 13:39 ` [PATCH v3 12/23] dt-bindings: Add RPMI system MSI interrupt controller bindings Anup Patel
2025-05-11 13:39 ` [PATCH v3 13/23] irqchip: Add driver for the RPMI system MSI service group Anup Patel
2025-05-12 6:50 ` Andy Shevchenko
2025-05-21 11:37 ` Anup Patel
2025-05-21 14:11 ` Andy Shevchenko
2025-05-23 11:38 ` Anup Patel
2025-05-12 18:58 ` Thomas Gleixner
2025-05-21 11:37 ` Anup Patel
2025-05-11 13:39 ` [PATCH v3 14/23] ACPI: property: Refactor acpi_fwnode_get_reference_args() Anup Patel
2025-05-12 8:43 ` Andy Shevchenko
2025-05-11 13:39 ` [PATCH v3 15/23] ACPI: property: Add support for cells property Anup Patel
2025-05-12 7:16 ` Andy Shevchenko
2025-05-12 8:30 ` Sunil V L
2025-05-11 13:39 ` [PATCH v3 16/23] ACPI: scan: Update honor list for RPMI System MSI Anup Patel
2025-05-11 13:39 ` [PATCH v3 17/23] ACPI: RISC-V: Create interrupt controller list in sorted order Anup Patel
2025-05-11 13:39 ` [PATCH v3 18/23] ACPI: RISC-V: Add support to update gsi range Anup Patel
2025-05-12 7:31 ` Andy Shevchenko
2025-05-11 13:39 ` [PATCH v3 19/23] ACPI: RISC-V: Add RPMI System MSI to GSI mapping Anup Patel
2025-05-11 13:39 ` [PATCH v3 20/23] mailbox/riscv-sbi-mpxy: Add ACPI support Anup Patel
2025-05-12 7:28 ` Andy Shevchenko
2025-05-12 8:36 ` Sunil V L
2025-05-12 8:47 ` Andy Shevchenko
2025-05-12 8:57 ` Sunil V L
2025-05-11 13:39 ` [PATCH v3 21/23] irqchip/riscv-rpmi-sysmsi: " Anup Patel
2025-05-12 7:34 ` Andy Shevchenko
2025-05-12 8:42 ` Sunil V L
2025-05-11 13:39 ` [PATCH v3 22/23] RISC-V: Enable GPIO keyboard and event device in RV64 defconfig Anup Patel
2025-05-11 13:39 ` [PATCH v3 23/23] MAINTAINERS: Add entry for RISC-V RPMI and MPXY drivers 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=aCGeTPS4WiGYMTTo@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=ajones@ventanamicro.com \
--cc=anup@brainfault.org \
--cc=apatel@ventanamicro.com \
--cc=atish.patra@linux.dev \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jassisinghbrar@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=lenb@kernel.org \
--cc=leyfoon.tan@starfivetech.com \
--cc=linus.walleij@linaro.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mika.westerberg@linux.intel.com \
--cc=mturquette@baylibre.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rpathak@ventanamicro.com \
--cc=samuel.holland@sifive.com \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=ukleinek@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).