From: Simon Horman <horms@kernel.org>
To: "Rob Herring (Arm)" <robh@kernel.org>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-can@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: can: cc770: Simplify parsing DT properties
Date: Wed, 28 Aug 2024 17:16:24 +0100 [thread overview]
Message-ID: <20240828161624.GS1368797@kernel.org> (raw)
In-Reply-To: <20240828131902.3632167-1-robh@kernel.org>
On Wed, Aug 28, 2024 at 08:19:02AM -0500, Rob Herring (Arm) wrote:
> Use of the typed property accessors is preferred over of_get_property().
> The existing code doesn't work on little endian systems either. Replace
> the of_get_property() calls with of_property_read_bool() and
> of_property_read_u32().
>
> Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
...
> diff --git a/drivers/net/can/cc770/cc770_platform.c b/drivers/net/can/cc770/cc770_platform.c
> index 13bcfba05f18..9993568154f8 100644
> --- a/drivers/net/can/cc770/cc770_platform.c
> +++ b/drivers/net/can/cc770/cc770_platform.c
> @@ -71,16 +71,9 @@ static int cc770_get_of_node_data(struct platform_device *pdev,
> struct cc770_priv *priv)
> {
> struct device_node *np = pdev->dev.of_node;
> - const u32 *prop;
> - int prop_size;
> - u32 clkext;
> -
> - prop = of_get_property(np, "bosch,external-clock-frequency",
> - &prop_size);
> - if (prop && (prop_size == sizeof(u32)))
> - clkext = *prop;
> - else
> - clkext = CC770_PLATFORM_CAN_CLOCK; /* default */
> + u32 clkext = CC770_PLATFORM_CAN_CLOCK, clkout = 0;
Marc,
Could you clarify if reverse xmas tree ordering - longest line to shortest
- of local variables is desired for can code? If so, I'm flagging that the
above now doesn't follow that scheme.
> +
> + of_property_read_u32(np, "bosch,external-clock-frequency", &clkext);
> priv->can.clock.freq = clkext;
>
> /* The system clock may not exceed 10 MHz */
...
> @@ -109,20 +102,16 @@ static int cc770_get_of_node_data(struct platform_device *pdev,
> if (of_property_read_bool(np, "bosch,polarity-dominant"))
> priv->bus_config |= BUSCFG_POL;
>
> - prop = of_get_property(np, "bosch,clock-out-frequency", &prop_size);
> - if (prop && (prop_size == sizeof(u32)) && *prop > 0) {
> - u32 cdv = clkext / *prop;
> - int slew;
> + of_property_read_u32(np, "bosch,clock-out-frequency", &clkout);
> + if (clkout > 0) {
> + u32 cdv = clkext / clkout;
> + u32 slew;
>
> if (cdv > 0 && cdv < 16) {
> priv->cpu_interface |= CPUIF_CEN;
> priv->clkout |= (cdv - 1) & CLKOUT_CD_MASK;
>
> - prop = of_get_property(np, "bosch,slew-rate",
> - &prop_size);
> - if (prop && (prop_size == sizeof(u32))) {
> - slew = *prop;
> - } else {
> + if (of_property_read_u32(np, "bosch,slew-rate", &slew)) {
> /* Determine default slew rate */
> slew = (CLKOUT_SL_MASK >>
> CLKOUT_SL_SHIFT) -
Rob,
The next few lines look like this:
((cdv * clkext - 1) / 8000000);
if (slew < 0)
slew = 0;
But slew is now unsigned, so this check will always be false.
Flagged by Smatch and Coccinelle.
next prev parent reply other threads:[~2024-08-28 16:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 13:19 [PATCH] net: can: cc770: Simplify parsing DT properties Rob Herring (Arm)
2024-08-28 16:16 ` Simon Horman [this message]
2024-08-29 19:35 ` Marc Kleine-Budde
-- strict thread matches above, loose matches on Subject: below --
2024-09-03 13:57 Rob Herring (Arm)
2024-09-04 9:52 ` Marc Kleine-Budde
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=20240828161624.GS1368797@kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robh@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).