Re: [PATCH] of: increase readability when reading prop through sysfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 6, 2019 at 6:15 AM lijiazi <jqqlijiazi@xxxxxxxxx> wrote:
>
> Replace '\0' with '\n', output will display on a single line.

That would be nice, but that breaks the ABI. For example, dtc can read
this filesystem tree and convert to dts or dtb.

Even if we ignored that or could fix all the users (we can't), your
implementation is just broken in all cases. If the value is a string
(you could guess, but you really don't know), then you are removing
the null termination. If the value is a number, then you are changing
the value when the last byte is 0.

> Signed-off-by: lijiazi <lijiazi@xxxxxxxxxx>
> ---
>  drivers/of/kobj.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c
> index c72eef9..c776610 100644
> --- a/drivers/of/kobj.c
> +++ b/drivers/of/kobj.c
> @@ -32,8 +32,18 @@ static ssize_t of_node_property_read(struct file *filp, struct kobject *kobj,
>                                 struct bin_attribute *bin_attr, char *buf,
>                                 loff_t offset, size_t count)
>  {
> +       ssize_t pos = 0;
>         struct property *pp = container_of(bin_attr, struct property, attr);
> -       return memory_read_from_buffer(buf, count, &offset, pp->value, pp->length);
> +       pos = memory_read_from_buffer(buf, count, &offset,
> +                       pp->value, pp->length);
> +       /*
> +        * value is ends with '\0', so if read prop value through sysfs, the
> +        * output will be displayed on the same line as the shell prompt.
> +        * Replace '\0' with '\n', increase readability of output.
> +        */
> +       if (pos >= 1)
> +               buf[pos-1] = '\n';
> +       return pos;
>  }
>
>  /* always return newly allocated name, caller must free after use */
> --
> 2.7.4
>



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux