Re: [PATCH 4.19 62/86] ASoC: intel: skl: Fix pin debug prints

From: Pavel Machek
Date: Wed Mar 11 2020 - 05:52:15 EST


Hi!

> From: Takashi Iwai <tiwai@xxxxxxx>
>
> commit 64bbacc5f08c01954890981c63de744df1f29a30 upstream.
>
> skl_print_pins() loops over all given pins but it overwrites the text
> at the very same position while increasing the returned length.
> Fix this to show the all pin contents properly.

> --- a/sound/soc/intel/skylake/skl-debug.c
> +++ b/sound/soc/intel/skylake/skl-debug.c
> @@ -42,7 +42,7 @@ static ssize_t skl_print_pins(struct skl
> int i;
> ssize_t ret = 0;
>
> - for (i = 0; i < max_pin; i++)
> + for (i = 0; i < max_pin; i++) {
> ret += snprintf(buf + size, MOD_BUF - size,
> "%s %d\n\tModule %d\n\tInstance %d\n\t"
> "In-used %s\n\tType %s\n"
> @@ -53,6 +53,8 @@ static ssize_t skl_print_pins(struct skl
> m_pin[i].in_use ? "Used" : "Unused",
> m_pin[i].is_dynamic ? "Dynamic" : "Static",
> m_pin[i].pin_state, i);
> + size += ret;
> + }
> return ret;

This may be an improvement, but I believe this should use
"scnprintf()" as snprintf can return values bigger than size passed
in.

Best regards,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Attachment: signature.asc
Description: PGP signature