All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: mc: Reject disconnected pads on an active pipeline
@ 2026-11-24 16:37 Anthony McGivern
  2026-12-03  8:05 ` Linus Walleij
  2026-12-04 11:57 ` Sakari Ailus
  0 siblings, 2 replies; 5+ messages in thread
From: Anthony McGivern @ 2026-11-24 16:37 UTC (permalink / raw)
  To: linux-media
  Cc: Anthony McGivern, Vincenzo Frascino, Nayden Kanchev,
	Konstantin Babin, Linus Walleij, Mauro Carvalho Chehab,
	Hans Verkuil, laurent.pinchart, Sakari Ailus, Anthony McGivern

From: Anthony McGivern <Anthony.McGivern@arm.com>

When starting an already active media pipeline, graph validation is skipped
and its start count is incremented. This allows a disconnected origin pad
to return success even though it does not belong to a pipeline.

Reject a disconnected origin pad with -EINVAL before incrementing the
start count.

Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
---
 drivers/media/mc/mc-entity.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
index 7938f785e2e3c76372a585426faa0482d78083ef..4508afacdd68e2a9ab81261561997317ab525662 100644
--- a/drivers/media/mc/mc-entity.c
+++ b/drivers/media/mc/mc-entity.c
@@ -791,10 +791,13 @@ __must_check int __media_pipeline_start(struct media_pad *origin,
 		return -EINVAL;
 
 	/*
-	 * If the pipeline has already been started, it is guaranteed to be
-	 * valid, so just increase the start count.
+	 * If the pipeline has already been started, ensure the pad is a part of the pipeline.
+	 * If so, it is guaranteed to be valid, so just increase the start count.
 	 */
 	if (pipe->start_count) {
+		if (!origin->pipe)
+			return -EINVAL;
+
 		pipe->start_count++;
 		return 0;
 	}

---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261124-mali-c720-media-controller-fix-3efb64d9cd6d

Best regards,
-- 
Anthony McGivern <Anthony.McGivern@arm.com>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: mc: Reject disconnected pads on an active pipeline
  2026-11-24 16:37 [PATCH] media: mc: Reject disconnected pads on an active pipeline Anthony McGivern
@ 2026-12-03  8:05 ` Linus Walleij
  2026-12-03 12:23   ` Anthony McGivern
  2026-12-04 11:57 ` Sakari Ailus
  1 sibling, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2026-12-03  8:05 UTC (permalink / raw)
  To: Anthony McGivern
  Cc: linux-media, Vincenzo Frascino, Nayden Kanchev, Konstantin Babin,
	Mauro Carvalho Chehab, Hans Verkuil, laurent.pinchart,
	Sakari Ailus

Hi Anthony,

thanks for your patch!

On Tue, Nov 24, 2026 at 5:38 PM Anthony McGivern
<anthony.mcgivern@arm.com> wrote:

> From: Anthony McGivern <Anthony.McGivern@arm.com>
>
> When starting an already active media pipeline, graph validation is skipped
> and its start count is incremented. This allows a disconnected origin pad
> to return success even though it does not belong to a pipeline.
>
> Reject a disconnected origin pad with -EINVAL before incrementing the
> start count.
>
> Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>

Maybe also mention that this will surely give a WARN_ON() splat
from __media_pipeline_stop() unless this patch is applied?
I suppose this is how you found it?

(...)
>         /*
> -        * If the pipeline has already been started, it is guaranteed to be
> -        * valid, so just increase the start count.
> +        * If the pipeline has already been started, ensure the pad is a part of the pipeline.
> +        * If so, it is guaranteed to be valid, so just increase the start count.
>          */
>         if (pipe->start_count) {
> +               if (!origin->pipe)
> +                       return -EINVAL;

Should this be -ENOLINK?

I see this is used under similar circumstances (disconnected
node/pad) in the media framework.

Some media maintainer maybe can confirm.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: mc: Reject disconnected pads on an active pipeline
  2026-12-03  8:05 ` Linus Walleij
@ 2026-12-03 12:23   ` Anthony McGivern
  0 siblings, 0 replies; 5+ messages in thread
From: Anthony McGivern @ 2026-12-03 12:23 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-media, Vincenzo Frascino, Nayden Kanchev, Konstantin Babin,
	Mauro Carvalho Chehab, Hans Verkuil, laurent.pinchart,
	Sakari Ailus


Hi Linus,

On 03/12/2026 08:05, Linus Walleij wrote:
> Hi Anthony,
> 
> thanks for your patch!
> 
> On Tue, Nov 24, 2026 at 5:38 PM Anthony McGivern
> <anthony.mcgivern@arm.com> wrote:
> 
>> From: Anthony McGivern <Anthony.McGivern@arm.com>
>>
>> When starting an already active media pipeline, graph validation is skipped
>> and its start count is incremented. This allows a disconnected origin pad
>> to return success even though it does not belong to a pipeline.
>>
>> Reject a disconnected origin pad with -EINVAL before incrementing the
>> start count.
>>
>> Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
> 
> Maybe also mention that this will surely give a WARN_ON() splat
> from __media_pipeline_stop() unless this patch is applied?
> I suppose this is how you found it?

Good point, yeah this indicated the issue to me initially as you have
described. I also noticed this as the start_count would also be mistakenly
incremented so any driver checks that depend on this could inadvertently
pass. In any case, I will update the description in V2 to state this
consequential WARN_ON().

Another thought would be how this differs to media_pipeline_alloc_start
where instead a new pipe would be allocated and run through its own
validation, thus failing for an unconnected pad if MUST_CONNECT is set.
Maybe for that reason it is preferred to use the alloc_start variant?

> 
> (...)
>>         /*
>> -        * If the pipeline has already been started, it is guaranteed to be
>> -        * valid, so just increase the start count.
>> +        * If the pipeline has already been started, ensure the pad is a part of the pipeline.
>> +        * If so, it is guaranteed to be valid, so just increase the start count.
>>          */
>>         if (pipe->start_count) {
>> +               if (!origin->pipe)
>> +                       return -EINVAL;
> 
> Should this be -ENOLINK?
> 
> I see this is used under similar circumstances (disconnected
> node/pad) in the media framework.
> 
> Some media maintainer maybe can confirm.

Yeah that does sound more reasonable, but I agree it would be good
to clarify this. If so I can make the change in V2.

> 
> Yours,
> Linus Walleij

Thanks,
Anthony

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: mc: Reject disconnected pads on an active pipeline
  2026-11-24 16:37 [PATCH] media: mc: Reject disconnected pads on an active pipeline Anthony McGivern
  2026-12-03  8:05 ` Linus Walleij
@ 2026-12-04 11:57 ` Sakari Ailus
  2026-12-04 14:29   ` Anthony McGivern
  1 sibling, 1 reply; 5+ messages in thread
From: Sakari Ailus @ 2026-12-04 11:57 UTC (permalink / raw)
  To: Anthony McGivern
  Cc: linux-media, Vincenzo Frascino, Nayden Kanchev, Konstantin Babin,
	Linus Walleij, Mauro Carvalho Chehab, Hans Verkuil,
	laurent.pinchart

Hi Anthony,

On Tue, Nov 24, 2026 at 04:37:52PM +0000, Anthony McGivern wrote:
> From: Anthony McGivern <Anthony.McGivern@arm.com>
> 
> When starting an already active media pipeline, graph validation is skipped
> and its start count is incremented. This allows a disconnected origin pad
> to return success even though it does not belong to a pipeline.
> 
> Reject a disconnected origin pad with -EINVAL before incrementing the
> start count.
> 
> Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
> ---
>  drivers/media/mc/mc-entity.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> index 7938f785e2e3c76372a585426faa0482d78083ef..4508afacdd68e2a9ab81261561997317ab525662 100644
> --- a/drivers/media/mc/mc-entity.c
> +++ b/drivers/media/mc/mc-entity.c
> @@ -791,10 +791,13 @@ __must_check int __media_pipeline_start(struct media_pad *origin,
>  		return -EINVAL;
>  
>  	/*
> -	 * If the pipeline has already been started, it is guaranteed to be
> -	 * valid, so just increase the start count.
> +	 * If the pipeline has already been started, ensure the pad is a part of the pipeline.
> +	 * If so, it is guaranteed to be valid, so just increase the start count.
>  	 */
>  	if (pipe->start_count) {
> +		if (!origin->pipe)
> +			return -EINVAL;

Can this happen somewhere? Presumably, the caller will have provided a
pipeline that has been started and a pad that isn't a part of it. This case
was intended to allow dynamically adding entities (or pads) to the
pipeline, but I don't think this has been implemented anywhere (nor it
probably works in practice).

> +
>  		pipe->start_count++;
>  		return 0;
>  	}
> 

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] media: mc: Reject disconnected pads on an active pipeline
  2026-12-04 11:57 ` Sakari Ailus
@ 2026-12-04 14:29   ` Anthony McGivern
  0 siblings, 0 replies; 5+ messages in thread
From: Anthony McGivern @ 2026-12-04 14:29 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, Vincenzo Frascino, Nayden Kanchev, Konstantin Babin,
	Linus Walleij, Mauro Carvalho Chehab, Hans Verkuil,
	laurent.pinchart


Hi Sakari,

On 04/12/2026 11:57, Sakari Ailus wrote:
> Hi Anthony,
> 
> On Tue, Nov 24, 2026 at 04:37:52PM +0000, Anthony McGivern wrote:
>> From: Anthony McGivern <Anthony.McGivern@arm.com>
>>
>> When starting an already active media pipeline, graph validation is skipped
>> and its start count is incremented. This allows a disconnected origin pad
>> to return success even though it does not belong to a pipeline.
>>
>> Reject a disconnected origin pad with -EINVAL before incrementing the
>> start count.
>>
>> Signed-off-by: Anthony McGivern <Anthony.McGivern@arm.com>
>> ---
>>  drivers/media/mc/mc-entity.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
>> index 7938f785e2e3c76372a585426faa0482d78083ef..4508afacdd68e2a9ab81261561997317ab525662 100644
>> --- a/drivers/media/mc/mc-entity.c
>> +++ b/drivers/media/mc/mc-entity.c
>> @@ -791,10 +791,13 @@ __must_check int __media_pipeline_start(struct media_pad *origin,
>>  		return -EINVAL;
>>  
>>  	/*
>> -	 * If the pipeline has already been started, it is guaranteed to be
>> -	 * valid, so just increase the start count.
>> +	 * If the pipeline has already been started, ensure the pad is a part of the pipeline.
>> +	 * If so, it is guaranteed to be valid, so just increase the start count.
>>  	 */
>>  	if (pipe->start_count) {
>> +		if (!origin->pipe)
>> +			return -EINVAL;
> 
> Can this happen somewhere? Presumably, the caller will have provided a
> pipeline that has been started and a pad that isn't a part of it. This case
> was intended to allow dynamically adding entities (or pads) to the
> pipeline, but I don't think this has been implemented anywhere (nor it
> probably works in practice).

An example would be rkisp1 where it has a mainpath and selfpath, since the
links between the ISP subdev and the resizers are mutable.

Say a user configured the pipeline to enable mainpath and leave selfpath
disconnected, they would call STREAMON for the mainpath cap dev and the
ISP would start. However they could then call STREAMON for the selfpath,
and without this fix the video_device_pipeline_start would return success.
This is problematic since that path is actually disconnected in the media
graph and not validated, so neither the ISP-to-resizer nor the resizer-to-cap
format and dimensions have been checked. Yet rkisp1_sp_config would then
fetch the cap dev's format and write to registers.

If the link was originally enabled to the selfpath, it would undergo the usual
pipeline validation. In rkisp1 specifically, they then allow both paths to be
started/stopped individually at runtime, which I suppose is similar to the
usecase you described. I don't see any existing examples where a dynamic link
can be enabled on a pipeline that is already enabled, in fact I don't see any
drivers using MEDIA_LNK_FL_DYNAMIC at present. This change would prevent such
behaviour, but validating that newly enabled link and any downstream entities
would require additional changes.

It could be a case that in the future this fix is dropped to allow such
usecases, but doing so would require further changes to handle validation
of the newly attached entities.

> 
>> +
>>  		pipe->start_count++;
>>  		return 0;
>>  	}
>>
> 

Thanks,
Anthony

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04 14:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 16:37 [PATCH] media: mc: Reject disconnected pads on an active pipeline Anthony McGivern
2026-12-03  8:05 ` Linus Walleij
2026-12-03 12:23   ` Anthony McGivern
2026-12-04 11:57 ` Sakari Ailus
2026-12-04 14:29   ` Anthony McGivern

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.