From: Simon Horman <horms@kernel.org>
To: Zijun Hu <zijun_hu@icloud.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Zijun Hu <quic_zijuhu@quicinc.com>
Subject: Re: [PATCH net-next] net: wan: framer: Simplify API framer_provider_simple_of_xlate() implementation
Date: Thu, 12 Dec 2024 16:41:49 +0000 [thread overview]
Message-ID: <20241212164149.GB73795@kernel.org> (raw)
In-Reply-To: <20241211-framer-core-fix-v1-1-0688c6905a0b@quicinc.com>
On Wed, Dec 11, 2024 at 09:28:20PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
>
> Simplify framer_provider_simple_of_xlate() implementation by API
> class_find_device_by_of_node().
>
> Also correct comments to mark its parameter @dev as unused instead of
> @args in passing.
>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
> drivers/net/wan/framer/framer-core.c | 20 +++++++-------------
> 1 file changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/wan/framer/framer-core.c b/drivers/net/wan/framer/framer-core.c
> index f547c22e26ac2b9986e48ed77143f12a0c8f62fb..7b369d9c41613314860753b7927b209e58f45a91 100644
> --- a/drivers/net/wan/framer/framer-core.c
> +++ b/drivers/net/wan/framer/framer-core.c
> @@ -732,8 +732,8 @@ EXPORT_SYMBOL_GPL(devm_framer_create);
>
> /**
> * framer_provider_simple_of_xlate() - returns the framer instance from framer provider
> - * @dev: the framer provider device
> - * @args: of_phandle_args (not used here)
> + * @dev: the framer provider device (not used here)
> + * @args: of_phandle_args
> *
> * Intended to be used by framer provider for the common case where #framer-cells is
> * 0. For other cases where #framer-cells is greater than '0', the framer provider
> @@ -743,20 +743,14 @@ EXPORT_SYMBOL_GPL(devm_framer_create);
> struct framer *framer_provider_simple_of_xlate(struct device *dev,
> const struct of_phandle_args *args)
> {
> - struct class_dev_iter iter;
> - struct framer *framer;
> -
> - class_dev_iter_init(&iter, &framer_class, NULL, NULL);
> - while ((dev = class_dev_iter_next(&iter))) {
> - framer = dev_to_framer(dev);
> - if (args->np != framer->dev.of_node)
> - continue;
> + struct device *target_dev;
>
> - class_dev_iter_exit(&iter);
> - return framer;
> + target_dev = class_find_device_by_of_node(&framer_class, args->np);
> + if (target_dev) {
> + put_device(target_dev);
> + return dev_to_framer(target_dev);
> }
>
> - class_dev_iter_exit(&iter);
> return ERR_PTR(-ENODEV);
Hi Zijun Hu,
FWIIW, I think it would be more idiomatic to have the non-error path in the
main flow of execution, something like this (completely untested!):
target_dev = class_find_device_by_of_node(&framer_class, args->np);
if (!target_dev)
return ERR_PTR(-ENODEV);
put_device(target_dev);
return dev_to_framer(target_dev);
Also, is it safe to put_device(target_dev) before
passing target_dev to dev_to_framer() ?
> }
> EXPORT_SYMBOL_GPL(framer_provider_simple_of_xlate);
...
next prev parent reply other threads:[~2024-12-12 16:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 13:28 [PATCH net-next] net: wan: framer: Simplify API framer_provider_simple_of_xlate() implementation Zijun Hu
2024-12-12 16:41 ` Simon Horman [this message]
2024-12-13 10:57 ` Zijun Hu
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=20241212164149.GB73795@kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_zijuhu@quicinc.com \
--cc=zijun_hu@icloud.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;
as well as URLs for NNTP newsgroup(s).