From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAED4745D6 for ; Tue, 9 Apr 2024 05:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712641040; cv=none; b=KStovpC7dTKUjdy4cKtYkOQ8k1aGFzfbaO668wVENRlrHJ0nwd+11Uz6GIdZXRWETYW3TRZzlVDQO7q7CyfAOPeKBPvLezr1Imrz210V7yZQixE6bPJVb+En3y0hF6sJmPXpTA7q7FGG/9sTMSuHuwOWito+q1xRrAP829dPTcU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712641040; c=relaxed/simple; bh=lTCSNVlJ6eROconCklf0lUttHmQ5Wtcp6EAz241j66g=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=l2dgWbpzk6HkmJQWxe4Nr4MyWRQA0vFWXetrJ3xgY/qn8KqI01ySZym8GwMU1BZFiFRnYEErWG6lJ3FkCo/tMkcrMyjLzQnACa/hrS6jSAwVjW2y3CIZLwqCdc7O/5ZcV7w5aDgyP9vIveVee2MrqP26nzFRKPJC/5x5zqm1Bf0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de; spf=pass smtp.mailfrom=arndb.de; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b=Tv2aY7QQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ohMa2R79; arc=none smtp.client-ip=64.147.123.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arndb.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b="Tv2aY7QQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ohMa2R79" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 13BFB1C000CF; Tue, 9 Apr 2024 01:37:15 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Tue, 09 Apr 2024 01:37:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1712641035; x=1712727435; bh=N2u6h8moDB /fTrACtRe+4SheoESaX066xDK/8RKTrfw=; b=Tv2aY7QQAm99/pz2q0eveh7JGm EfuSYzJeR2QJa0vb6P9iDs/oHdeTyb9Uuy8oyOyVuT0a9TSV4dyHIwYSImGxUmmj Ui8Rpk6S1W2zaVzAZAspGRz6HBlGQCGjh05+kDjVSxpa13UlZDVNWQjnkS/cXhNx QIq7n8JB3QZdtsDVYIFAewpZXEX5H8w6ZWK2dUbvP9cNA+6C+XS2wQwkLjOcChni mooq3eElINOpKJl7xCxmkRiYKPYzkIyqvi9lQzP0pnhk0k9nb0mqnuUnd2AFat+f vBJb8Zxbg5Euo7f4POuAZotU3tUkAbWamJ/D8BsUl3MgSGugtqbcfiegXSTQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1712641035; x=1712727435; bh=N2u6h8moDB/fTrACtRe+4SheoESa X066xDK/8RKTrfw=; b=ohMa2R79u15cVtS+Hp9UcT9qCYwDCzkdSZwD64PHuxLL ogfPbSzwStwmmxM//S/G2juvf5lWvwnAiWTGPUyF58LgwDxXagQ+6teWjMMgreAH 81Wf0T5OGNV5+N6kxifl7hF7kc9pkSS5pqvpDzxqhaFWUduPi72YNzY62BGJRyd7 vujMGnTL6XUnJi1gzKXywDTqLbHwRygNJwLx+QjaA/lrguWL1NLORZvOkB8MIM5L RhM6urcMsOQ3DpdJRBAgQi7yhMcteT9O7WnrQBxXyqSQj2e2dNEp8UDOOKr4xjyT VymgXEXID6/wtD4YUl5G6TXQiY6geTb1A1NXrkfLqQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegkedgjedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehr nhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrdguvgeqnecuggftrfgrth htvghrnhepffehueegteeihfegtefhjefgtdeugfegjeelheejueethfefgeeghfektdek teffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id DDC0AB6008D; Tue, 9 Apr 2024 01:37:14 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-379-gabd37849b7-fm-20240408.001-gabd37849 Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: In-Reply-To: References: <20240408194821.3183462-1-arnd@kernel.org> Date: Tue, 09 Apr 2024 07:34:41 +0200 From: "Arnd Bergmann" To: "Justin Stitt" , "Arnd Bergmann" Cc: "Greg Kroah-Hartman" , "Dan Carpenter" , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] [v2] staging: rts5208: replace weird strncpy() with memcpy() Content-Type: text/plain 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