All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <treding@nvidia.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: <linux-media@vger.kernel.org>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Sylwester Nawrocki <snawrocki@kernel.org>,
	Benjamin Gaignard <benjamin.gaignard@linaro.org>,
	Ettore Chimenti <ek5.chimenti@gmail.com>,
	Wen Yang <wen.yang99@zte.com.cn>
Subject: Re: [PATCH 1/7] cec-notifier: add cec_notifier_find_hdmi_dev helper
Date: Mon, 8 Apr 2019 15:09:53 +0200	[thread overview]
Message-ID: <20190408130953.GA2219@ulmo> (raw)
In-Reply-To: <20190408110401.3345-2-hverkuil-cisco@xs4all.nl>

[-- Attachment #1: Type: text/plain, Size: 2472 bytes --]

On Mon, Apr 08, 2019 at 01:03:55PM +0200, Hans Verkuil wrote:
> Add helper function to parse the DT for the hdmi-phandle property
> and find the corresponding struct device pointer.
> 
> It takes care to avoid increasing the device refcount since all
> we need is the device pointer. This pointer is used in the
> notifier list as a key, but it is never accessed by the CEC driver.
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Reported-by: Wen Yang <wen.yang99@zte.com.cn>
> ---
>  drivers/media/cec/cec-notifier.c | 24 ++++++++++++++++++++++++
>  include/media/cec-notifier.h     | 19 ++++++++++++++++++-
>  2 files changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c
> index dd2078b27a41..870b3788e9f7 100644
> --- a/drivers/media/cec/cec-notifier.c
> +++ b/drivers/media/cec/cec-notifier.c
> @@ -11,6 +11,7 @@
>  #include <linux/slab.h>
>  #include <linux/list.h>
>  #include <linux/kref.h>
> +#include <linux/of_platform.h>
>  
>  #include <media/cec.h>
>  #include <media/cec-notifier.h>
> @@ -127,3 +128,26 @@ void cec_notifier_unregister(struct cec_notifier *n)
>  	cec_notifier_put(n);
>  }
>  EXPORT_SYMBOL_GPL(cec_notifier_unregister);
> +
> +struct device *cec_notifier_find_hdmi_dev(struct device *dev)

This doesn't really do anything with notifiers, so perhaps rename this
to something more independent?

> +{
> +	struct platform_device *hdmi_pdev;
> +	struct device *hdmi_dev = NULL;
> +	struct device_node *np;
> +
> +	np = of_parse_phandle(dev->of_node, "hdmi-phandle", 0);
> +
> +	if (!np) {
> +		dev_err(dev, "Failed to find hdmi node in device tree\n");

Perhaps "... to find HDMI node..."? HDMI here doesn't refer to a name,
so I think it's better to use the capitalized abbreviation to avoid any
potential confusion.

> +		return ERR_PTR(-ENODEV);
> +	}
> +	hdmi_pdev = of_find_device_by_node(np);
> +	of_node_put(np);
> +	if (hdmi_pdev) {
> +		hdmi_dev = &hdmi_pdev->dev;
> +		put_device(hdmi_dev);

Don't you need to hold onto that reference and pass it to the caller?
Otherwise somebody could be dropping the last reference to the struct
device backing the HDMI device after this call finishes.

In conjunction with the above comment, perhaps it'd be clearer if we had
a cec_hdmi_get()/cec_hdmi_put() pair of functions so that callers can
explicitly manage the reference count.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-04-08 13:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-08 11:03 [PATCH 0/7] cec: introduce cec_notifier_find_hdmi_dev helper Hans Verkuil
2019-04-08 11:03 ` [PATCH 1/7] cec-notifier: add " Hans Verkuil
2019-04-08 13:09   ` Thierry Reding [this message]
2019-04-08 13:17     ` Hans Verkuil
2019-04-08 11:03 ` [PATCH 2/7] meson: ao-cec: use new " Hans Verkuil
2019-04-08 12:01   ` Neil Armstrong
2019-04-08 11:03 ` [PATCH 3/7] s5p_cec: " Hans Verkuil
2019-04-08 11:03 ` [PATCH 4/7] stih_cec: " Hans Verkuil
2019-04-08 12:44   ` Benjamin Gaignard
2019-04-08 11:03 ` [PATCH 5/7] tegra_cec: " Hans Verkuil
2019-04-08 11:04 ` [PATCH 6/7] seco-cec: decrement HDMI device refcount Hans Verkuil
2019-04-08 13:21   ` Ettore Chimenti
2019-04-08 11:04 ` [PATCH 7/7] cros-ec-cec: " Hans Verkuil

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=20190408130953.GA2219@ulmo \
    --to=treding@nvidia.com \
    --cc=benjamin.gaignard@linaro.org \
    --cc=ek5.chimenti@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=narmstrong@baylibre.com \
    --cc=snawrocki@kernel.org \
    --cc=wen.yang99@zte.com.cn \
    /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.