linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Cc: "Linux Media Mailing List" <linux-media@vger.kernel.org>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>
Subject: Re: [PATCH for v5.3] v4l2-subdev: fix regression in check_pad()
Date: Sat, 29 Jun 2019 15:19:39 +0200	[thread overview]
Message-ID: <58a1ea38-622a-0ed1-2cd1-afe8b8268fbe@xs4all.nl> (raw)
In-Reply-To: <1892813.ECJImQiLv2@z50>

On 6/29/19 3:13 PM, Janusz Krzysztofik wrote:
> On Saturday, June 29, 2019 2:57:09 P.M. CEST Hans Verkuil wrote:
>> On 6/29/19 2:06 PM, Janusz Krzysztofik wrote:
>>> Hi Hans,
>>>
>>> On Saturday, June 29, 2019 12:00:24 P.M. CEST Hans Verkuil wrote:
>>>> sd->entity.graph_obj.mdev can be NULL when this function is called, and
>>>> that breaks existing drivers (rcar-vin, but probably others as well).
>>>>
>>>> Check if sd->entity.num_pads is non-zero instead since that doesn't
>>>> depend
>>>> on mdev.
>>>>
>>>> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
>>>> Reported-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
>>>> Fixes: a8fa55078a77 ("media: v4l2-subdev: Verify arguments in
>>>> v4l2_subdev_call()") ---
>>>> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
>>>> b/drivers/media/v4l2-core/v4l2-subdev.c index 21fb90d66bfc..bc32fc1e0c0b
>>>> 100644
>>>> --- a/drivers/media/v4l2-core/v4l2-subdev.c
>>>> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
>>>> @@ -124,16 +124,11 @@ static inline int check_which(__u32 which)
>>>>
>>>>  static inline int check_pad(struct v4l2_subdev *sd, __u32 pad)
>>>>  {
>>>>  #if defined(CONFIG_MEDIA_CONTROLLER)
>>>>
>>>> -	if (sd->entity.graph_obj.mdev) {
>>>> -		if (pad >= sd->entity.num_pads)
>>>> -			return -EINVAL;
>>>> -		return 0;
>>>> -	}
>>>> +	if (sd->entity.num_pads)
>>>
>>> This reverts a change introduced on Sakari's request in v7 of the series
>>> which is the source of the regression.  The intention was to fail if
>>> num_pads == 0 on a valid media entity. Maybe we should still keep that
>>> restriction and fail in case mdev is not NULL? In other words:
>>>
>>> -	if (sd->entity.num_pads)
>>> +	if (sd->entity.num_pads || sd->entity.graph_obj.mdev)
>>
>> If an entity has no pads, then it doesn't have pad ops either and this
>> function would never be called.
> 
> Unless this is a subdevice which doesn't support MC, was updated in the past 
> to use pad ops instead of depreciated video ops, so it actually has pad ops 
> even if it has num_pads == 0, and is built by a user with 
> CONFIG_MEDIA_CONTROLLER=y for some reason.

That's fine. Then it just checks if pad == 0, which is OK for such drivers.

The issue here is a MC-enabled subdev with pad ops, but that really has no pads
for some reason, so check_pad() would always have to return -EINVAL.

Regards,

	Hans

> 
> Thanks,
> Janusz
> 
>>
>>> Thanks,
>>> Janusz
>>>
>>>> +		return pad >= sd->entity.num_pads ? -EINVAL : 0;
>>>
>>> This and below look like coding style changes, not related strictly to the
>>> merit.  Shouldn't they rather be split into a separate patch?
>>
>> I'll post a v2, the diff is a lot smaller. I might post a follow-up patch
>> to use ? : since that's a lot shorter code.
>>
>> Regards,
>>
>> 	Hans
>>
>>> BTW, the current coding style follows original implementation of check_*
>>> functions present before that series was introduced.  Maybe it would be
>>> better to keep them unified, i.e., either as is or all updated with the
>>> new style.
>>>
>>> Thanks,
>>> Janusz
>>>
>>>>  #endif
>>>>  
>>>>  	/* allow pad 0 on subdevices not registered as media entities */
>>>>
>>>> -	if (pad > 0)
>>>> -		return -EINVAL;
>>>> -	return 0;
>>>> +	return pad ? -EINVAL : 0;
>>>>
>>>>  }
>>>>  
>>>>  static int check_cfg(__u32 which, struct v4l2_subdev_pad_config *cfg)
> 
> 
> 
> 


  reply	other threads:[~2019-06-29 13:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-29 10:00 [PATCH for v5.3] v4l2-subdev: fix regression in check_pad() Hans Verkuil
2019-06-29 11:33 ` Niklas Söderlund
2019-06-29 12:06 ` Janusz Krzysztofik
2019-06-29 12:57   ` Hans Verkuil
2019-06-29 13:08     ` Hans Verkuil
2019-07-01  7:50       ` Sakari Ailus
2019-07-01 21:24         ` Janusz Krzysztofik
2019-06-29 13:13     ` Janusz Krzysztofik
2019-06-29 13:19       ` Hans Verkuil [this message]
2019-06-29 12:59 Hans Verkuil

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=58a1ea38-622a-0ed1-2cd1-afe8b8268fbe@xs4all.nl \
    --to=hverkuil-cisco@xs4all.nl \
    --cc=jmkrzyszt@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=sakari.ailus@linux.intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).