[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0gQj8cNHgXkgwGeNcegAmP2xxqPQXz1kGNqFFDDCgfX_w@mail.gmail.com>
Date: Tue, 10 Nov 2020 20:19:54 +0100
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Lukasz Luba <lukasz.luba@....com>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Linux PM <linux-pm@...r.kernel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
"Rafael J. Wysocki" <rjw@...ysocki.net>
Subject: Re: [PATCH] powercap: Adjust printing the constraint name with new line
On Mon, Nov 9, 2020 at 6:25 PM Lukasz Luba <lukasz.luba@....com> wrote:
>
> The constraint name has limit of size 30, which sometimes might be hit.
> When this happens the new line might be lost. Prevent this and set the
> new line when the name string is too long."
>
> Signed-off-by: Lukasz Luba <lukasz.luba@....com>
> ---
> drivers/powercap/powercap_sys.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
> index f808c5fa9838..575f9fdb810e 100644
> --- a/drivers/powercap/powercap_sys.c
> +++ b/drivers/powercap/powercap_sys.c
> @@ -174,6 +174,10 @@ static ssize_t show_constraint_name(struct device *dev,
> "%s\n", name);
> buf[POWERCAP_CONSTRAINT_NAME_LEN] = '\0';
> len = strlen(buf);
> +
> + /* When the 'name' is too long, don't lose new line */
> + if (strlen(name) >= POWERCAP_CONSTRAINT_NAME_LEN)
> + buf[POWERCAP_CONSTRAINT_NAME_LEN - 1] = '\n';
Wouldn't it be better to pass POWERCAP_CONSTRAINT_NAME_LEN - 1 to
snprintf() above?
> }
> }
>
> --
Powered by blists - more mailing lists