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] [thread-next>] [day] [month] [year] [list]
Message-ID: <e216e27592e50bb9786c6bae106762fc7cb97109.camel@gmail.com>
Date:   Fri, 21 Jul 2023 10:03:32 +0200
From:   Nuno Sá <noname.nuno@...il.com>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>
Subject: Re: [PATCH v1 2/8] iio: core: Use sysfs_match_string() helper

On Thu, 2023-07-20 at 23:53 +0300, Andy Shevchenko wrote:
> Use sysfs_match_string() helper instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> ---
>  drivers/iio/industrialio-core.c | 81 +++++++++++++--------------------
>  1 file changed, 31 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 6cca86fd0ef9..90e59223b178 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1400,50 +1400,32 @@ static ssize_t label_show(struct device *dev, struct
> device_attribute *attr,
>  
>  static DEVICE_ATTR_RO(label);
>  
> +static const char * const clock_names[] = {
> +       [CLOCK_REALTIME]                = "realtime",
> +       [CLOCK_MONOTONIC]               = "monotonic",
> +       [CLOCK_PROCESS_CPUTIME_ID]      = "process_cputime_id",
> +       [CLOCK_THREAD_CPUTIME_ID]       = "thread_cputime_id",
> +       [CLOCK_MONOTONIC_RAW]           = "monotonic_raw",
> +       [CLOCK_REALTIME_COARSE]         = "realtime_coarse",
> +       [CLOCK_MONOTONIC_COARSE]        = "monotonic_coarse",
> +       [CLOCK_BOOTTIME]                = "boottime",
> +       [CLOCK_REALTIME_ALARM]          = "realtime_alarm",
> +       [CLOCK_BOOTTIME_ALARM]          = "boottime_alarm",
> +       [CLOCK_SGI_CYCLE]               = "sgi_cycle",
> +       [CLOCK_TAI]                     = "tai",
> +};
> +
>  static ssize_t current_timestamp_clock_show(struct device *dev,
>                                             struct device_attribute *attr,
>                                             char *buf)
>  {
>         const struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>         const clockid_t clk = iio_device_get_clock(indio_dev);
> -       const char *name;
> -       ssize_t sz;
>  
> -       switch (clk) {
> -       case CLOCK_REALTIME:
> -               name = "realtime\n";
> -               sz = sizeof("realtime\n");
> -               break;
> -       case CLOCK_MONOTONIC:
> -               name = "monotonic\n";
> -               sz = sizeof("monotonic\n");
> -               break;
> -       case CLOCK_MONOTONIC_RAW:
> -               name = "monotonic_raw\n";
> -               sz = sizeof("monotonic_raw\n");
> -               break;
> -       case CLOCK_REALTIME_COARSE:
> -               name = "realtime_coarse\n";
> -               sz = sizeof("realtime_coarse\n");
> -               break;
> -       case CLOCK_MONOTONIC_COARSE:
> -               name = "monotonic_coarse\n";
> -               sz = sizeof("monotonic_coarse\n");
> -               break;
> -       case CLOCK_BOOTTIME:
> -               name = "boottime\n";
> -               sz = sizeof("boottime\n");
> -               break;
> -       case CLOCK_TAI:
> -               name = "tai\n";
> -               sz = sizeof("tai\n");
> -               break;
> -       default:
> +       if (clk < 0 && clk >= ARRAY_SIZE(clock_names))
>                 BUG();
> -       }
>  
> -       memcpy(buf, name, sz);
> -       return sz;
> +       return sprintf(buf, "%s\n", clock_names[clk]);

syfs_emit()...

- Nuno Sá

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ