From: "Arnd Bergmann" <arnd@arndb.de>
To: "Justin Stitt" <justinstitt@google.com>,
"Arnd Bergmann" <arnd@kernel.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Dan Carpenter" <dan.carpenter@linaro.org>,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] [v2] staging: rts5208: replace weird strncpy() with memcpy()
Date: Tue, 09 Apr 2024 07:34:41 +0200 [thread overview]
Message-ID: <b5740321-455e-4939-8a94-72c01e4c09f3@app.fastmail.com> (raw)
In-Reply-To: <wb5h2syqmxpoxmajwiiyqvlkyojjsjql5xpfmris6djegtqzya@6xfio4dmqjdp>
On Mon, Apr 8, 2024, at 22:28, Justin Stitt wrote:
> On Mon, Apr 08, 2024 at 09:48:09PM +0200, Arnd Bergmann wrote:
>> @@ -523,7 +523,7 @@ static int inquiry(struct scsi_cmnd *srb, struct rtsx_chip *chip)
>>
>> if (sendbytes > 8) {
>> memcpy(buf, inquiry_buf, 8);
>> - strncpy(buf + 8, inquiry_string, sendbytes - 8);
>> + memcpy(buf + 8, inquiry_string, min(sendbytes, 36) - 8);
>
> I must say I am not the biggest fan of manual string management with raw
> pointer offsets. I wonder if scnprintf() could achieve your goal here of
> combining inquiry_buf with inquiry_string into buf (perhaps utilizing
> %.*s format specifier).
scnprintf() would be wrong here, since it's not actually a string
but a SCSI HW data structure with both binary and ASCII members
and no NUL termination. It's supposed to be padded with spaces.
> With that being said, I am just a casual reader of this code and I
> really don't know much about the expected behavior of `buf`
> (NUL-terminated, NUL-padded, etc) or even what the next line buf[4]=0x33
> does.
I believe this sets the length of the buffer to 51 bytes when
pro_formatter_flag is set, overriding the 0x1f (31 bytes) for the
normal length.
The root of the problem here is that the driver emulates a SCSI
command set on a card reader for both SD cards and memory sticks
instead of using the existing abstractions from
drivers/{mmc,memstick}.
Apparently drivers/misc/cardreader/rtsx_pcr.c does this the
right way for all later devices (rts5209 and up) but is
not compatible with this variant of the hardware.
Arnd
next prev parent reply other threads:[~2024-04-09 5:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 19:48 [PATCH 1/3] [v2] staging: rts5208: replace weird strncpy() with memcpy() Arnd Bergmann
2024-04-08 19:48 ` [PATCH 2/3] [v2] staging: rtl8723bs: convert strncpy to strscpy Arnd Bergmann
2024-04-08 20:35 ` Justin Stitt
2024-04-09 7:10 ` Dan Carpenter
2024-04-08 19:48 ` [PATCH 3/3] [v2] staging: greybus: change strncpy() to strscpy_pad() Arnd Bergmann
2024-04-08 20:38 ` Justin Stitt
2024-04-09 7:04 ` Dan Carpenter
2024-04-08 20:28 ` [PATCH 1/3] [v2] staging: rts5208: replace weird strncpy() with memcpy() Justin Stitt
2024-04-09 5:34 ` Arnd Bergmann [this message]
2024-04-09 6:23 ` Dan Carpenter
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=b5740321-455e-4939-8a94-72c01e4c09f3@app.fastmail.com \
--to=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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