All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sascha Hauer" <s.hauer@pengutronix.de>
Cc: conor+dt@kernel.org, media-ci@linuxtv.org, robh@kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH 4/9] media: synopsys: hdmirx: add async subdevice support
Date: Wed, 23 Sep 2026 13:58:08 +0000	[thread overview]
Message-ID: <20260923135809.622691F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260923-hdmirx-media-v1-4-ea3d77d4a5f3@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: missing graph_mutex lock in hdmirx_fwnode_bound() leading to list corruption
--

commit ac73c2eba89ee9517b8e00beeec227f11b4a4eae
Author: Gerald Loacker <gerald.loacker@wolfvision.net>

media: synopsys: hdmirx: add async subdevice support
    
Add V4L2 async notifier support to enable dynamic binding of connected
subdevices in the video pipeline. The driver parses device-tree endpoints
to discover and register video bridge subdevices.

> diff --git a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
> index 11a9b16586a57..0c7cac25bf694 100644
> --- a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
> +++ b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c

[ ... ]

> @@ -2649,6 +2653,48 @@ static int hdmirx_register_cec(struct snps_hdmirx_dev *hdmirx_dev,
>  	return 0;
>  }
>  
> +static int hdmirx_fwnode_bound(struct v4l2_async_notifier *notifier,
> +			       struct v4l2_subdev *subdev,
> +			       struct v4l2_async_connection *asc)
> +{
> +	struct snps_hdmirx_dev *hdmirx_dev =
> +		container_of(notifier, struct snps_hdmirx_dev, notifier);
> +	int source_pad;
> +	int ret;
> +
> +	source_pad = media_entity_get_fwnode_pad(&subdev->entity,
> +						 asc->match.fwnode,
> +						 MEDIA_PAD_FL_SOURCE);
> +	if (source_pad < 0) {
> +		dev_err(hdmirx_dev->dev, "%s has no source pad for %pfw: %d\n",
> +			subdev->name, asc->match.fwnode, source_pad);
> +		return source_pad;
> +	}
> +
> +	ret = media_create_pad_link(&subdev->entity, source_pad,
> +				    &hdmirx_dev->stream.vdev.entity, 0,
> +				    MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);

[Severity: High]
Is it safe to call media_create_pad_link() here without holding the
mdev->graph_mutex?

This function modifies shared media graph lists (such as mdev->links).

Since the media device has already been registered in hdmirx_probe(),
concurrent access from userspace is possible. A userspace process calling the
MEDIA_IOC_G_TOPOLOGY ioctl could be traversing the topology lists while this
call modifies them, potentially leading to list corruption.

Should this call be wrapped in mutex_lock(&hdmirx_dev->mdev.graph_mutex)?

> +	if (ret) {
> +		dev_err(hdmirx_dev->dev, "Failed to create media link: %d\n", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}

[ ... ]

> @@ -2772,9 +2820,38 @@ static int hdmirx_probe(struct platform_device *pdev)
>  		goto err_unreg_video_dev;
>  	}
>  
> +	ep_node = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1);

[Severity: High]
Does registering the async notifier after calling media_device_register()
expose a race condition?

The media_device_register() call (which happens just before this block in
hdmirx_probe()) exposes the topology traversal interface (MEDIA_IOC_G_TOPOLOGY)
to userspace prematurely.

This opens a race window where asynchronous bindings handled by the notifier
can conflict with userspace topology traversal.

Would it be better to call media_device_register() after registering the async
notifier?

> +	if (ep_node) {
> +		v4l2_async_nf_init(&hdmirx_dev->notifier, &hdmirx_dev->v4l2_dev);
> +		hdmirx_dev->notifier.ops = &hdmirx_async_ops;
> +
> +		asc = v4l2_async_nf_add_fwnode_remote(&hdmirx_dev->notifier,
> +						      of_fwnode_handle(ep_node),
> +						      struct v4l2_async_connection);
> +		of_node_put(ep_node);
> +
> +		if (IS_ERR(asc)) {
> +			ret = PTR_ERR(asc);
> +			dev_err_probe(dev, ret, "Failed to add remote fwnode\n");
> +			goto err_unreg_media;
> +		}
> +
> +		ret = v4l2_async_nf_register(&hdmirx_dev->notifier);
> +		if (ret) {
> +			dev_err_probe(dev, ret, "Failed to register async notifier\n");
> +			goto err_cleanup_notifier;
> +		}
> +	} else {
> +		ret = v4l2_device_register_subdev_nodes(&hdmirx_dev->v4l2_dev);
> +		if (ret) {
> +			dev_err_probe(dev, ret, "Failed to register subdev nodes\n");
> +			goto err_unreg_media;
> +		}
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923-hdmirx-media-v1-0-ea3d77d4a5f3@pengutronix.de?part=4

  reply	other threads:[~2026-09-23 13:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 13:44 [PATCH 0/9] media: synopsys: hdmirx: support an HDMI bridge in front of the receiver Sascha Hauer
2026-09-23 13:44 ` [PATCH 1/9] media: synopsys: hdmirx: add media device infrastructure Sascha Hauer
2026-09-23 13:44 ` [PATCH 2/9] media: synopsys: hdmirx: add media entity for video capture device Sascha Hauer
2026-09-23 13:44 ` [PATCH 3/9] dt-bindings: media: snps,dw-hdmi-rx: add the source port Sascha Hauer
2026-09-23 16:34   ` Conor Dooley
2026-09-23 13:44 ` [PATCH 4/9] media: synopsys: hdmirx: add async subdevice support Sascha Hauer
2026-09-23 13:58   ` sashiko-bot [this message]
2026-09-23 13:44 ` [PATCH 5/9] media: synopsys: hdmirx: give the signal lock wait a real timeout Sascha Hauer
2026-09-23 13:44 ` [PATCH 6/9] dt-bindings: media: snps,dw-hdmi-rx: make hpd-gpios optional Sascha Hauer
2026-09-23 16:46   ` Conor Dooley
2026-09-24  6:12     ` Sascha Hauer
2026-09-23 13:44 ` [PATCH 7/9] media: synopsys: hdmirx: skip the 5V detect interrupt without a GPIO Sascha Hauer
2026-09-23 13:44 ` [PATCH 8/9] media: v4l2-subdev: notify the bridge when the source power changes Sascha Hauer
2026-09-23 13:44 ` [PATCH 9/9] media: synopsys: hdmirx: get the 5V state from the upstream subdev Sascha Hauer
2026-09-23 14:05   ` sashiko-bot

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=20260923135809.622691F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.