public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Svyatoslav Ryhel <clamor95@gmail.com>,
	Simon Glass <sjg@chromium.org>, Lukasz Majewski <lukma@denx.de>,
	Marek Vasut <marex@denx.de>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>, Bin Meng <bmeng@tinylab.org>,
	Ion Agorria <ion@agorria.com>,
	Svyatoslav Ryhel <clamor95@gmail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Harald Seiler <hws@denx.de>,
	Sean Anderson <sean.anderson@seco.com>,
	Heiko Schocher <hs@denx.de>,
	Dmitrii Merkurev <dimorinny@google.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Cc: u-boot@lists.denx.de
Subject: Re: [PATCH v2 4/5] lib: membuff: fix readline not returning line in case of overflow
Date: Tue, 21 Nov 2023 11:29:51 +0100	[thread overview]
Message-ID: <871qcjmmao.fsf@baylibre.com> (raw)
In-Reply-To: <20231115153836.16537-5-clamor95@gmail.com>

Hi Svyatoslav,

Thank you for your patch.

On mer., nov. 15, 2023 at 17:38, Svyatoslav Ryhel <clamor95@gmail.com> wrote:

> From: Ion Agorria <ion@agorria.com>
>
> If line overflows readline it will not be returned, fix this behavior,
> make it optional and documented properly.
>
> Signed-off-by: Ion Agorria <ion@agorria.com>
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> ---
>  boot/bootmeth_extlinux.c | 2 +-
>  common/console.c         | 2 +-
>  include/membuff.h        | 5 +++--
>  lib/membuff.c            | 4 ++--
>  4 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c
> index aa2a4591eb..ae0ad1d53e 100644
> --- a/boot/bootmeth_extlinux.c
> +++ b/boot/bootmeth_extlinux.c
> @@ -82,7 +82,7 @@ static int extlinux_fill_info(struct bootflow *bflow)
>  	log_debug("parsing bflow file size %x\n", bflow->size);
>  	membuff_init(&mb, bflow->buf, bflow->size);
>  	membuff_putraw(&mb, bflow->size, true, &data);
> -	while (len = membuff_readline(&mb, line, sizeof(line) - 1, ' '), len) {
> +	while (len = membuff_readline(&mb, line, sizeof(line) - 1, ' ', true), len) {
>  		char *tok, *p = line;
>  
>  		tok = strsep(&p, " ");
> diff --git a/common/console.c b/common/console.c
> index 8a869b137e..cd56035171 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -846,7 +846,7 @@ bool console_record_overflow(void)
>  int console_record_readline(char *str, int maxlen)
>  {
>  	return membuff_readline((struct membuff *)&gd->console_out, str,
> -				maxlen, '\0');
> +				maxlen, '\0', false);
>  }
>  
>  int console_record_avail(void)
> diff --git a/include/membuff.h b/include/membuff.h
> index 21051b0c54..4eba626ce1 100644
> --- a/include/membuff.h
> +++ b/include/membuff.h
> @@ -192,10 +192,11 @@ int membuff_free(struct membuff *mb);
>   * @mb: membuff to adjust
>   * @str: Place to put the line
>   * @maxlen: Maximum line length (excluding terminator)
> + * @must_fit: If true then str is empty if line doesn't fit
>   * Return: number of bytes read (including terminator) if a line has been
> - *	   read, 0 if nothing was there
> + *	   read, 0 if nothing was there or line didn't fit when must_fit is set
>   */
> -int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch);
> +int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit);
>  
>  /**
>   * membuff_extend_by() - expand a membuff
> diff --git a/lib/membuff.c b/lib/membuff.c
> index 36dc43a523..964e504d5b 100644
> --- a/lib/membuff.c
> +++ b/lib/membuff.c
> @@ -288,7 +288,7 @@ int membuff_free(struct membuff *mb)
>  			(mb->end - mb->start) - 1 - membuff_avail(mb);
>  }
>  
> -int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch)
> +int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit)
>  {
>  	int len;  /* number of bytes read (!= string length) */
>  	char *s, *end;
> @@ -310,7 +310,7 @@ int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch)
>  	}
>  
>  	/* couldn't get the whole string */
> -	if (!ok) {
> +	if (!ok && must_fit) {
>  		if (maxlen)
>  			*orig = '\0';
>  		return 0;
> -- 
> 2.40.1

  reply	other threads:[~2023-11-21 10:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15 15:38 [PATCH v2 0/5] Implement fastboot multiresponce Svyatoslav Ryhel
2023-11-15 15:38 ` [PATCH v2 1/5] fastboot: multiresponse support Svyatoslav Ryhel
2023-11-21  9:25   ` Mattijs Korpershoek
2023-11-15 15:38 ` [PATCH v2 2/5] fastboot: implement "getvar all" Svyatoslav Ryhel
2023-11-21 13:53   ` Mattijs Korpershoek
2023-11-15 15:38 ` [PATCH v2 3/5] common: console: introduce overflow and isempty calls Svyatoslav Ryhel
2023-11-21 10:27   ` Mattijs Korpershoek
2023-11-15 15:38 ` [PATCH v2 4/5] lib: membuff: fix readline not returning line in case of overflow Svyatoslav Ryhel
2023-11-21 10:29   ` Mattijs Korpershoek [this message]
2023-12-27 17:48   ` Simon Glass
2023-11-15 15:38 ` [PATCH v2 5/5] fastboot: add oem console command support Svyatoslav Ryhel
2023-11-21 10:35   ` Mattijs Korpershoek

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=871qcjmmao.fsf@baylibre.com \
    --to=mkorpershoek@baylibre.com \
    --cc=bmeng@tinylab.org \
    --cc=clamor95@gmail.com \
    --cc=dimorinny@google.com \
    --cc=hs@denx.de \
    --cc=hws@denx.de \
    --cc=ion@agorria.com \
    --cc=joe.hershberger@ni.com \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=matthias.schiffer@ew.tq-group.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=rfried.dev@gmail.com \
    --cc=sean.anderson@seco.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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