Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1813534lqe; Tue, 9 Apr 2024 00:32:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3P5gHGVd6koSXTVKtjdFj4GpUKMQ1qGiuNjHWqvxU2LDE8Fa0js9I5LERxLwGjbVre+RwrvFOYWjxzUVcsnhR0/kGvRmJQ5khxQcDNw== X-Google-Smtp-Source: AGHT+IFrbIQyKpxG7yvs6Q1RVu6k+Ar63jgNEf3lBtP7KcCf9i5VI139J4FsUZVJxqxydqFjGyPT X-Received: by 2002:a05:6a20:320c:b0:1a5:6f21:f8a8 with SMTP id hl12-20020a056a20320c00b001a56f21f8a8mr8215228pzc.15.1712647962002; Tue, 09 Apr 2024 00:32:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712647961; cv=pass; d=google.com; s=arc-20160816; b=eOXEBfj63KTuf+LhiLdogBqnK4pt9dFi44+d7TsS9W4BujOHMjI+nq6CASicJK9mKg CcQFG9BcIKe67/iUllV+XJAb5cY4Kssl3ppwF8XDoGEzFuE2fpo/S4x6H50FIVda51fB l5+xwdOaWZzNBKljnL1PMJ0y1gzgnWjuI3iLpNhGpU0SwQLmey7E18Ist9csHRhqJ0xp CftS4Awa96lpTTLY4M7Oh1bRuFgypaDFgFCeF0S7hFP1/2Z4K/di28eUiyaaBZmIs3qd DEMMAXQArYhLX30WTTTDe8e2ePtA+HdFsbgo1xhTUX18aHBSBOaKhPPPV6nYFt6/ifhg jx4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:date:references:in-reply-to:message-id :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:feedback-id:dkim-signature:dkim-signature; bh=N2u6h8moDB/fTrACtRe+4SheoESaX066xDK/8RKTrfw=; fh=zQcO1I1M1vxpndsQoeIOuG2PcTm7/Qd08hpOxL7S9gw=; b=vtQz6eIgSGw1CKboQpzFBHoaMhkiczL+sX5aSpBHfC9uknM6UCr3buEpDTtviQSsVd pSKssYk7bRDsxJOFSog9pC54MKWSMHSMviUeI30Jq9gB89XoRXOUnQWtOmGhQZXhFHbb 3sUeEilTw1ao2d6sGmfXOmxohbdcPNFvO+WLCDkqtg/t0kE5FgLloU7wCp5jbDabiPgW wuIKlAqQSEXsg+FcC2qqiPErc4Lk7t7f+qrqA8++/RvJgDSWGJgPU9nDdfzgYnLIQWXK SwFs+OFgtzyanTRvXe8Pm3vD8zchsPKOIlH+hCcf+/6kX0g1AhZBGCfU0Ir23fRDnDdi yNmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b=Tv2aY7QQ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ohMa2R79; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-136258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id t4-20020a170902bc4400b001e434292b80si3058812plz.152.2024.04.09.00.32.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 00:32:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b=Tv2aY7QQ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ohMa2R79; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-136258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 84269B228E7 for ; Tue, 9 Apr 2024 05:38:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0353C79955; Tue, 9 Apr 2024 05:37:21 +0000 (UTC) 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 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 AAE9974438 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=1712641039; cv=none; b=U7b2ll42Ndh+ynFTIguxmhHIX+3qFl64dM6Q7rjm8V0FBzoDs6E/skagjOv6VgnK49kk6G9awccRkRZjmdJo/pCg2JivI7AyClztt5hsmhWl0cW6+AEHefs539psGU+iao6nJ88I4+wf/NmaCIS9PlhY+vqt4y85Itb7XsSKz1o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712641039; c=relaxed/simple; bh=lTCSNVlJ6eROconCklf0lUttHmQ5Wtcp6EAz241j66g=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=EVZhpvaD7rOGZS7S1UNqN/ELqjpDVEIqV/oSPXcIn8AXWGOH67U2mAOY3WXhgT4/x5+u/pVGdVup8Ieyu4vtgZtrfc0F85TTPa/XuRUABmm4zcVDzJdBSI/iqm1VMjX8p3O+/GUa9NAxRSQag/UCH9GzZ60Bz68Sebo/21vTFgI= 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 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-kernel@vger.kernel.org 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