devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh+dt@kernel.org>
To: lijiazi <jqqlijiazi@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>,
	lijiazi <lijiazi@xiaomi.com>,
	devicetree@vger.kernel.org
Subject: Re: [PATCH] of: increase readability when reading prop through sysfs
Date: Fri, 6 Dec 2019 09:47:29 -0600	[thread overview]
Message-ID: <CAL_Jsq+rgS5oJGYP4WvE_uRc9RR+19MZMVe-gpu1nJUmqgdYNA@mail.gmail.com> (raw)
In-Reply-To: <02bf81614fd5806fbdb8e58760f424adeee3fdc6.1575611847.git.lijiazi@xiaomi.com>

On Fri, Dec 6, 2019 at 6:15 AM lijiazi <jqqlijiazi@gmail.com> 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@xiaomi.com>
> ---
>  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
>

      reply	other threads:[~2019-12-06 15:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 12:15 [PATCH] of: increase readability when reading prop through sysfs lijiazi
2019-12-06 15:47 ` Rob Herring [this message]

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=CAL_Jsq+rgS5oJGYP4WvE_uRc9RR+19MZMVe-gpu1nJUmqgdYNA@mail.gmail.com \
    --to=robh+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=jqqlijiazi@gmail.com \
    --cc=lijiazi@xiaomi.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).