From: Hans Verkuil Date: Wed, 10 Apr 2019 09:13:28 +0000 (-0400) Subject: media: cec-notifier: add cec_notifier_parse_hdmi_phandle helper X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=fbbd403b3286b4467f8b755efa0f10819cef9bba;p=openwrt%2Fstaging%2Fblogic.git media: cec-notifier: add cec_notifier_parse_hdmi_phandle helper Add helper function to parse the DT for the hdmi-phandle property and return 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 Reported-by: Wen Yang Acked-by: Wen Yang Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c index dd2078b27a41..9598c7778871 100644 --- a/drivers/media/cec/cec-notifier.c +++ b/drivers/media/cec/cec-notifier.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -127,3 +128,32 @@ void cec_notifier_unregister(struct cec_notifier *n) cec_notifier_put(n); } EXPORT_SYMBOL_GPL(cec_notifier_unregister); + +struct device *cec_notifier_parse_hdmi_phandle(struct device *dev) +{ + 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"); + return ERR_PTR(-ENODEV); + } + hdmi_pdev = of_find_device_by_node(np); + of_node_put(np); + if (hdmi_pdev) { + hdmi_dev = &hdmi_pdev->dev; + /* + * Note that the device struct is only used as a key into the + * cec_notifiers list, it is never actually accessed. + * So we decrement the reference here so we don't leak + * memory. + */ + put_device(hdmi_dev); + return hdmi_dev; + } + return ERR_PTR(-EPROBE_DEFER); +} +EXPORT_SYMBOL_GPL(cec_notifier_parse_hdmi_phandle); diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h index 814eeef35a5c..57b3a9f6ea1d 100644 --- a/include/media/cec-notifier.h +++ b/include/media/cec-notifier.h @@ -9,7 +9,7 @@ #ifndef LINUX_CEC_NOTIFIER_H #define LINUX_CEC_NOTIFIER_H -#include +#include #include struct device; @@ -87,6 +87,17 @@ void cec_notifier_unregister(struct cec_notifier *n); void cec_register_cec_notifier(struct cec_adapter *adap, struct cec_notifier *notifier); +/** + * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle" + * @dev: the device with the "hdmi-phandle" device tree property + * + * Returns the device pointer referenced by the "hdmi-phandle" property. + * Note that the refcount of the returned device is not incremented. + * This device pointer is only used as a key value in the notifier + * list, but it is never accessed by the CEC driver. + */ +struct device *cec_notifier_parse_hdmi_phandle(struct device *dev); + #else static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn) @@ -122,6 +133,12 @@ static inline void cec_register_cec_notifier(struct cec_adapter *adap, struct cec_notifier *notifier) { } + +static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev) +{ + return ERR_PTR(-ENODEV); +} + #endif /**