Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <hverkuil-cisco@xs4all.nl>
Reported-by: Wen Yang <wen.yang99@zte.com.cn>
Acked-by: Wen Yang <wen.yang99@zte.com.cn>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
fbbd403b 63604a14

+48 -1
+30
drivers/media/cec/cec-notifier.c
··· 11 11 #include <linux/slab.h> 12 12 #include <linux/list.h> 13 13 #include <linux/kref.h> 14 + #include <linux/of_platform.h> 14 15 15 16 #include <media/cec.h> 16 17 #include <media/cec-notifier.h> ··· 128 127 cec_notifier_put(n); 129 128 } 130 129 EXPORT_SYMBOL_GPL(cec_notifier_unregister); 130 + 131 + struct device *cec_notifier_parse_hdmi_phandle(struct device *dev) 132 + { 133 + struct platform_device *hdmi_pdev; 134 + struct device *hdmi_dev = NULL; 135 + struct device_node *np; 136 + 137 + np = of_parse_phandle(dev->of_node, "hdmi-phandle", 0); 138 + 139 + if (!np) { 140 + dev_err(dev, "Failed to find HDMI node in device tree\n"); 141 + return ERR_PTR(-ENODEV); 142 + } 143 + hdmi_pdev = of_find_device_by_node(np); 144 + of_node_put(np); 145 + if (hdmi_pdev) { 146 + hdmi_dev = &hdmi_pdev->dev; 147 + /* 148 + * Note that the device struct is only used as a key into the 149 + * cec_notifiers list, it is never actually accessed. 150 + * So we decrement the reference here so we don't leak 151 + * memory. 152 + */ 153 + put_device(hdmi_dev); 154 + return hdmi_dev; 155 + } 156 + return ERR_PTR(-EPROBE_DEFER); 157 + } 158 + EXPORT_SYMBOL_GPL(cec_notifier_parse_hdmi_phandle);
+18 -1
include/media/cec-notifier.h
··· 9 9 #ifndef LINUX_CEC_NOTIFIER_H 10 10 #define LINUX_CEC_NOTIFIER_H 11 11 12 - #include <linux/types.h> 12 + #include <linux/err.h> 13 13 #include <media/cec.h> 14 14 15 15 struct device; ··· 87 87 void cec_register_cec_notifier(struct cec_adapter *adap, 88 88 struct cec_notifier *notifier); 89 89 90 + /** 91 + * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle" 92 + * @dev: the device with the "hdmi-phandle" device tree property 93 + * 94 + * Returns the device pointer referenced by the "hdmi-phandle" property. 95 + * Note that the refcount of the returned device is not incremented. 96 + * This device pointer is only used as a key value in the notifier 97 + * list, but it is never accessed by the CEC driver. 98 + */ 99 + struct device *cec_notifier_parse_hdmi_phandle(struct device *dev); 100 + 90 101 #else 91 102 static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, 92 103 const char *conn) ··· 133 122 struct cec_notifier *notifier) 134 123 { 135 124 } 125 + 126 + static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev) 127 + { 128 + return ERR_PTR(-ENODEV); 129 + } 130 + 136 131 #endif 137 132 138 133 /**