From: Avri Altman <Avri.Altman@wdc.com>
To: Daniel Mentz <danielmentz@google.com>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Tomas Winkler <tomas.winkler@intel.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Mars Cheng <marscheng@google.com>,
Bart Van Assche <bvanassche@acm.org>,
Yen-lin Lai <yenlinlai@google.com>
Subject: RE: [PATCH] scsi: ufs: Leave space for '\0' in utf8 desc string
Date: Tue, 17 Oct 2023 19:20:48 +0000 [thread overview]
Message-ID: <DM6PR04MB6575C45CF299649DF41FD963FCD6A@DM6PR04MB6575.namprd04.prod.outlook.com> (raw)
In-Reply-To: <20231017182026.2141163-1-danielmentz@google.com>
> utf16s_to_utf8s does not NULL terminate the output string. For us to be able
> to add a NULL character when utf16s_to_utf8s returns, we need to make
> sure that there is space for such NULL character at the end of the output
> buffer. We can achieve this by passing an output buffer size to
> utf16s_to_utf8s that is one character less than what we allocated.
>
> Other call sites of utf16s_to_utf8s appear to be using the same technique
> where they artificially reduce the buffer size by one to leave space for a
> NULL character or line feed character.
>
> Fixes: 4b828fe156a6 ("scsi: ufs: revamp string descriptor reading")
I think this code goes back to commit b573d484e4ff (scsi: ufs: add support to read device and string descriptors)
Reviewed-by: Avri Altman <avri.altman@wdc.com>
> Reviewed-by: Mars Cheng <marscheng@google.com>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
> Reviewed-by: Yen-lin Lai <yenlinlai@google.com>
> Signed-off-by: Daniel Mentz <danielmentz@google.com>
> ---
> drivers/ufs/core/ufshcd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index
> 8382e8cfa414..5767642982c1 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -3632,7 +3632,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba,
> u8 desc_index,
> */
> ret = utf16s_to_utf8s(uc_str->uc,
> uc_str->len - QUERY_DESC_HDR_SIZE,
> - UTF16_BIG_ENDIAN, str, ascii_len);
> + UTF16_BIG_ENDIAN, str, ascii_len -
> + 1);
>
> /* replace non-printable or non-ASCII characters with spaces */
> for (i = 0; i < ret; i++)
> --
> 2.42.0.655.g421f12c284-goog
next prev parent reply other threads:[~2023-10-17 19:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 18:20 Daniel Mentz
2023-10-17 19:20 ` Avri Altman [this message]
2023-10-17 19:33 ` Bart Van Assche
2023-10-17 21:56 ` Daniel Mentz
2023-10-25 2:46 ` Martin K. Petersen
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=DM6PR04MB6575C45CF299649DF41FD963FCD6A@DM6PR04MB6575.namprd04.prod.outlook.com \
--to=avri.altman@wdc.com \
--cc=bvanassche@acm.org \
--cc=danielmentz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=marscheng@google.com \
--cc=martin.petersen@oracle.com \
--cc=tomas.winkler@intel.com \
--cc=yenlinlai@google.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
all inboxes | Powered by JetHome®