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: <4bfc67b7-b062-a8cb-8a30-ccd117d67db9@metafoo.de>
Date:   Thu, 12 Jul 2018 20:31:59 +0200
From:   Lars-Peter Clausen <lars@...afoo.de>
To:     Andy Shevchenko <andy.shevchenko@...il.com>,
        Stefan Popa <stefan.popa@...log.com>
Cc:     Jonathan Cameron <jic23@...nel.org>,
        Michael Hennerich <Michael.Hennerich@...log.com>,
        Hartmut Knaack <knaack.h@....de>,
        Peter Meerwald <pmeerw@...erw.net>,
        linux-iio <linux-iio@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 4/5] iio:adxl372: Add sampling frequency support

On 07/12/2018 08:25 PM, Andy Shevchenko wrote:
> On Thu, Jul 12, 2018 at 6:36 PM, Stefan Popa <stefan.popa@...log.com> wrote:
>> This patch adds the option for the user to select the sampling frequency.
>> Also, the user can read the available frequencies and read the currently
>> set frequency via the read_raw function. The frequency can be set via the
>> write_raw function.
>>
>> When the frequency is set, the bandwidth is also checked and ensured
>> that it is constrained to at most half of the sampling frequency.
> 
>> +static int adxl372_find_closest_match(const int *array,
>> +                                     unsigned int size, int val)
>> +{
>> +       int i;
>> +
>> +       for (i = 0; i < size; i++) {
>> +               if (val <= array[i])
>> +                       return i;
>> +       }
>> +
>> +       return size - 1;
>> +}
> 
> Perhaps it's time to extend bsearch with something called
> bsearch_closest().
> 

While it makes sense to have a helper function for this the generic bsearch
is not a good solution for small arrays. The generated code is probably
larger and the function call overhead of calling the cmp function completely
outweighs the savings from doing a binary search. bsearch() is good if your
array has 100s or 1000s of entries. If it only has 5, not so much.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ