lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <e465780e-823c-c59e-29d1-f62f3a0e1673@gmail.com>
Date:   Sat, 4 Aug 2018 09:39:30 -0700
From:   Steve Longerbeam <slongerbeam@...il.com>
To:     jacopo mondi <jacopo@...ndi.org>
Cc:     linux-media@...r.kernel.org,
        Steve Longerbeam <steve_longerbeam@...tor.com>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Niklas Söderlund 
        <niklas.soderlund+renesas@...natech.se>,
        Sakari Ailus <sakari.ailus@...ux.intel.com>,
        Sebastian Reichel <sre@...nel.org>,
        Hans Verkuil <hans.verkuil@...co.com>,
        open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v6 03/17] media: v4l2: async: Add
 v4l2_async_notifier_add_subdev

Hi Jacopo,


On 08/03/2018 08:13 AM, jacopo mondi wrote:
> Hi Steven,
>     I've a small remark, which is probably not only related to your
>     patches but was there alreay... Anyway, please read below..
>
>
> On Mon, Jul 09, 2018 at 03:39:03PM -0700, Steve Longerbeam wrote:
>> <snip>
>> +static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier)
>> +{
>>   	struct v4l2_async_subdev *asd;
>>   	int ret;
>>   	int i;
>> @@ -399,29 +445,25 @@ static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier)
>>
>>   	mutex_lock(&list_lock);
>>
>> -	for (i = 0; i < notifier->num_subdevs; i++) {
>> -		asd = notifier->subdevs[i];
>> +	if (notifier->subdevs) {
>> +		for (i = 0; i < notifier->num_subdevs; i++) {
>> +			asd = notifier->subdevs[i];
>>
>> -		switch (asd->match_type) {
>> -		case V4L2_ASYNC_MATCH_CUSTOM:
>> -		case V4L2_ASYNC_MATCH_DEVNAME:
>> -		case V4L2_ASYNC_MATCH_I2C:
>> -		case V4L2_ASYNC_MATCH_FWNODE:
>> -			if (v4l2_async_notifier_has_async_subdev(
>> -				    notifier, asd, i)) {
>> -				dev_err(dev,
>> -					"asd has already been registered or in notifier's subdev list\n");
>> -				ret = -EEXIST;
>> +			ret = v4l2_async_notifier_asd_valid(notifier, asd, i);
>> +			if (ret)
>>   				goto err_unlock;
>> -			}
>> -			break;
>> -		default:
>> -			dev_err(dev, "Invalid match type %u on %p\n",
>> -				asd->match_type, asd);
>> -			ret = -EINVAL;
>> -			goto err_unlock;
>> +
>> +			list_add_tail(&asd->list, &notifier->waiting);
>> +		}
>> +	} else {
>> +		i = 0;
>> +		list_for_each_entry(asd, &notifier->asd_list, asd_list) {
>> +			ret = v4l2_async_notifier_asd_valid(notifier, asd, i++);
> Here the call stack looks like this, if I'm not mistaken:
>
> list_for_each_entry(asd, notifier->asd_list, i) {
>          v4l2_async_notifier_asd_valid(notifier, asd, i):
>                  v4l2_async_notifier_has_async_subdev(notifier, asd, i):
>                          list_for_each_entry(asd_y, notifier->asd_list, j) {
>                                  if (j >= i) break;
>                                  if (asd == asd_y) return true;
>                          }
> }
>
> Which is an optimization of O(n^2), but still bad.
>
> This was there already there, it was:

Agreed, it should be safe to remove the check for duplicate
asd's at notifier registration, since this check is done now
in v4l2_async_notifier_add_subdev().

Steve

> for (i = 0; i < notifier->num_subdevs; i++) {
>          v4l2_async_notifier_has_async_subdev(notifier, notifier->subdevs[i], i):
>                  for (j = 0; j < i; j++) {
>                          if (notifier->subdevs[i] == notifier->subdevs[j])
>                                  return true;
>                          }
>                  }
> }
>
> We're not talking high performances here, but I see no reason to go through
> the list twice, as after switching to use your here introduced
> v4l2_async_notifier_add_subdev() async subdevices are tested at endpoint
> parsing time in v4l2_async_notifier_fwnode_parse_endpoint(), which
> guarantees we can't have doubles later, at notifier registration time.
>
> If I'm not wrong, this can be anyway optimized later.
>
> Thanks
>     j
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ