s5p_cec: use new cec_notifier_find_hdmi_dev helper
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 66 lines · On 4/9/19 4:05 AM, [email protected] wrote:
Hi Hans,
Quoted 19 lines
Subject: [PATCH 3/7]
s5p_cec: use newcec_notifier_find_hdmi_devhelper The S5P CEC driver increased the HDMI device refcount when it shouldn't. Use the new helper function to ensure that that doesn't happen and to simplify the driver code.Signed-off-by Hans Verkuil <[email protected]>---
drivers/media/platform/s5p-cec/s5p_cec.c| 16 +++++-----------1 file changed, 5 insertions(+), 11 deletions(-)drivers/media/platform/s5p-cec/s5p_cec.c +0
-1@@ -178,22 +178,16 @@ static const struct cec_adap_ops s5p_cec_adap_ops = {static int s5p_cec_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct device_node *np;drivers/media/platform/s5p-cec/s5p_cec.c static const struct cec_adap_ops s5p_cec_adap_ops = { · line 188
Quoted 10 lines
drivers/media/platform/s5p-cec/s5p_cec.c +2
-2-struct platform_device *hdmi_dev; +struct device *hdmi_dev;struct resource *res;struct s5p_cec_dev *cec;bool needs_hpd =of_property_read_bool (pdev->dev.of_node,"needs-hpd" );int ret; - np =of_parse_phandle (pdev->dev.of_node,"hdmi-phandle" ,0 ); + hdmi_dev =cec_notifier_find_hdmi_dev (dev);The
hdmi_devreturned by thecec_notifier_find_hdmi_devfunction is just a key value and cannot be used as a struct device *, so the namecec_notifier_find_hdmi_devis a bit inappropriate.Quoted 13 lines
drivers/media/platform/s5p-cec/s5p_cec.c +2
-7-if (!np) { -dev_err (&pdev->dev,"Failed to find hdmi node in device tree\n" ); -return -ENODEV ; - } - hdmi_dev =of_find_device_by_node (np); -if (hdmi_dev ==NULL ) -return -EPROBE_DEFER ; +if (IS_ERR (hdmi_dev)) +return PTR_ERR (hdmi_dev); cec =devm_kzalloc (&pdev->dev,sizeof (*cec),GFP_KERNEL );if (!cec)drivers/media/platform/s5p-cec/s5p_cec.c static int s5p_cec_probe(struct platform_device *pdev) · line 221
Quoted 5 lines
drivers/media/platform/s5p-cec/s5p_cec.c +1
-1@@ -224,7 +218,7 @@ static int s5p_cec_probe(struct platform_device *pdev)if (IS_ERR (cec->reg))return PTR_ERR (cec->reg); - cec->notifier =cec_notifier_get (&hdmi_dev->dev); + cec->notifier =cec_notifier_get (hdmi_dev);The
hdmi_devvariable is only used as a key for the input of thecec_notifier_getfunction. So here is a little advice:
The current code mode is like this:
struct device *dev =&pdev->dev;
...(quoted diff) +3
-0+ struct device *hdmi_dev; + hdmi_dev = cec_notifier_find_hdmi_dev(dev); + cec->notifier = cec_notifier_get(hdmi_dev);
Quoted 8 lines
Can we replace it like this:
struct device *dev =&pdev->dev;
...
+cec->notifier=cec_notifier_get(dev);This way we can remove the
hdmi_devtemporary variable, and we can also remove thecec_notifier_find_hdmi_devfunction. It is enough to provide an API similar tocec_notifier_get.
Some drivers get the HDMI device through other means (e.g. cros-ec-cec) so combining this in one function is not a good idea.
I did decide to rename cec_notifier_find_hdmi_dev to cec_notifier_parse_hdmi_phandle. I think that is a better description of what the helper does.
Regards,
Hans
Quoted 7 lines
--
Regards,
WenQuoted 2 lines
drivers/media/platform/s5p-cec/s5p_cec.c +0
-0if (cec->notifier ==NULL )return -ENOMEM ;