diff mbox series

soc: qcom: cmd-db: Drop NUL bytes from debugfs output

Message ID 20230620213703.283583-1-quic_bjorande@quicinc.com (mailing list archive)
State Accepted
Headers show
Series soc: qcom: cmd-db: Drop NUL bytes from debugfs output | expand

Commit Message

Bjorn Andersson June 20, 2023, 9:37 p.m. UTC
The debugfs dump of Command DB relies uses %*pEp to print the resource
identifiers, with escaping of non-printable characters.
But p (ESCAPE_NP) does not escape NUL characters, so for identifiers
less than 8 bytes in length the output will retain these.

This does not cause an issue while looking at the dump in the terminal
(no known complaints at least), but when programmatically consuming the
debugfs output the extra characters are unwanted.

Change the fixed 8-byte sizeof() to a dynamic strnlen() to avoid
printing these NUL characters.

Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
---
 drivers/soc/qcom/cmd-db.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Konrad Dybcio June 20, 2023, 11:27 p.m. UTC | #1
On 20.06.2023 23:37, Bjorn Andersson wrote:
> The debugfs dump of Command DB relies uses %*pEp to print the resource
> identifiers, with escaping of non-printable characters.
> But p (ESCAPE_NP) does not escape NUL characters, so for identifiers
> less than 8 bytes in length the output will retain these.
> 
> This does not cause an issue while looking at the dump in the terminal
> (no known complaints at least), but when programmatically consuming the
> debugfs output the extra characters are unwanted.
> 
> Change the fixed 8-byte sizeof() to a dynamic strnlen() to avoid
> printing these NUL characters.
> 
> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
>  drivers/soc/qcom/cmd-db.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c
> index 33856abd560c..34c40368d5b5 100644
> --- a/drivers/soc/qcom/cmd-db.c
> +++ b/drivers/soc/qcom/cmd-db.c
> @@ -284,7 +284,7 @@ static int cmd_db_debugfs_dump(struct seq_file *seq, void *p)
>  		ent = rsc_to_entry_header(rsc);
>  		for (j = 0; j < le16_to_cpu(rsc->cnt); j++, ent++) {
>  			seq_printf(seq, "0x%05x: %*pEp", le32_to_cpu(ent->addr),
> -				   (int)sizeof(ent->id), ent->id);
> +				   (int)strnlen(ent->id, sizeof(ent->id)), ent->id);
>  
>  			len = le16_to_cpu(ent->len);
>  			if (len) {
Bjorn Andersson July 10, 2023, 5:07 a.m. UTC | #2
On Tue, 20 Jun 2023 14:37:03 -0700, Bjorn Andersson wrote:
> The debugfs dump of Command DB relies uses %*pEp to print the resource
> identifiers, with escaping of non-printable characters.
> But p (ESCAPE_NP) does not escape NUL characters, so for identifiers
> less than 8 bytes in length the output will retain these.
> 
> This does not cause an issue while looking at the dump in the terminal
> (no known complaints at least), but when programmatically consuming the
> debugfs output the extra characters are unwanted.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: cmd-db: Drop NUL bytes from debugfs output
      commit: d4600cbd5bcbaa2b296b5cf9a5c04408eedb4ef3

Best regards,
diff mbox series

Patch

diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c
index 33856abd560c..34c40368d5b5 100644
--- a/drivers/soc/qcom/cmd-db.c
+++ b/drivers/soc/qcom/cmd-db.c
@@ -284,7 +284,7 @@  static int cmd_db_debugfs_dump(struct seq_file *seq, void *p)
 		ent = rsc_to_entry_header(rsc);
 		for (j = 0; j < le16_to_cpu(rsc->cnt); j++, ent++) {
 			seq_printf(seq, "0x%05x: %*pEp", le32_to_cpu(ent->addr),
-				   (int)sizeof(ent->id), ent->id);
+				   (int)strnlen(ent->id, sizeof(ent->id)), ent->id);
 
 			len = le16_to_cpu(ent->len);
 			if (len) {