Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3796740iog; Tue, 28 Jun 2022 03:01:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vfyrxmSYFmB/v4PXE7ltOwC5b/HoLnw3Q6pO4zBmj9ITPhvhYhu9EuyApMOFi7BzLe2y8+ X-Received: by 2002:a17:902:ecd1:b0:16a:6b2e:2a76 with SMTP id a17-20020a170902ecd100b0016a6b2e2a76mr4314946plh.90.1656410487781; Tue, 28 Jun 2022 03:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656410487; cv=none; d=google.com; s=arc-20160816; b=atrRp50PM3B3W9iNvH3+CSfniXIvnX8e+6neZM/ntRWn35rkdU0cHz7HoeIhWEy+JT l+Ktl1zQBHewgfyRPdkNcXagjEIGwwKmICc2zfAk8hV9cQwJweRMB8/fq+oiHYsQiBt6 B/Ous4ehJ1qy+R7OcLObn0pfB5rHj6MWOzSHS/XwTb5nLrK75btLth+pYYLDJtYHOZHd Ih/wL4mebgl+TEaPZ1MgU2K32DCVFdz5P32uONi7ittl0DNPp8X6ANYHrobkTElWCUnI KKT0RI1XhXFKEKh02Wl9ArvtxnfmFvn2urkb5Q7flw5/N4aLRlBpCaz+LJ1f6tKz6++C TLcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=4TnV2KxyP2DV/2uDmzCbdYwAkBIDFDITNxmSAAlof8Y=; b=fE30X2JiaDRjhl13d+qABkXhy4qgUq+rQsBG1s95SFtS312/UG81f9Efu/DWXEU749 aEBkkCbfUi8xITLZCGPlZ/cgoWDWYPiBMTaVnEQrcAseu9U1OH38HBDCmZRe1NSAQtfv v/edVxFwnpCQUI1P0H7LyhxEOtAmPB/Fy31W04WT13p0pe7esW5m+NhuVV4K2cnqJWkN SIcpd2ApZVPglEOMyVMhBeNHv5qAYqPyHVXM4FPnGPazn1p+3HW+bBZINF/Z9+93Opf4 kzPwDC28hDgkxU9wLfQjXBxzVxzfI3HkEQlYISUHJng5SPOT3dl2iYChdW7CQUrfldlz Zbcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ORXopAl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a17090a9f0500b001ed5100fc33si9722347pjp.108.2022.06.28.03.01.14; Tue, 28 Jun 2022 03:01:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ORXopAl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344678AbiF1J71 (ORCPT + 99 others); Tue, 28 Jun 2022 05:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344149AbiF1J7N (ORCPT ); Tue, 28 Jun 2022 05:59:13 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 932122E9ED for ; Tue, 28 Jun 2022 02:59:10 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id d17so11240909wrc.10 for ; Tue, 28 Jun 2022 02:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=4TnV2KxyP2DV/2uDmzCbdYwAkBIDFDITNxmSAAlof8Y=; b=ORXopAl49yqtPpSQXoB46D2aTOgSJnlpOKwh5Xf257b9HiSYJHzyPj5T0eWCB0dAYd Nk+lIlx0wZFK262bf0RpR2W7aKgZCzHoUWyc/k2hGdEzjPyLtfXIXAs6KC30P9lHuX7n 8WMzdDMk3Ff4QGpr+FjaWHHXWK4ayKffTR0EqS5ay725cWWnR1nUrOWy1UsdmVXKxOj1 4ZxYOv2+XZ0ECFomyDdh+uixrRkdSMlwH/fm5T9xtQCj0Bxm/5Pfa8df39SJi9mtSqUa UrvsOuOiUTePwYcCXl0KiMcbnG/ZsVeZT+hIFoLEGS7VdwpInYngC+U3kzH/OBTKCdDl YkYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=4TnV2KxyP2DV/2uDmzCbdYwAkBIDFDITNxmSAAlof8Y=; b=p0ODk109Aarm33S2kMNDcbPGkUMjFCipd3IeL4hbNxwli7oupTZCgLjOsUCFLyinIM dvWyhIOYr3gNBGm7sJRCnulBhWgrD0Cd00LheFn0OKhL7CpTI3r6BW77//aD2Ov33Fll 3IlcOcYjWohDFcPRnzzEaLkafNK3AiXiUlHJOzlnSR/9vgsF9XcSuNztuKVt4s51KJ7D oHcc08X6eHl90m8j0aFpkIALaiLCGJc3oNk7sqfaZbr/tNTev0arZ94PHUkadMHlcPMy O5frwW/s2q74KWAOunsDnIH8YRDDuxGis/YoAofXOner6VZehKWBRqa7EvEoAqNHiNRD DM9w== X-Gm-Message-State: AJIora+qKEXoltuKKbdb9iRkAzHD6jW/PeSf7J5NMTPKhmuDFT8Br4ZC tVTI0ZTnzrwz6FVMpv48GqoR8A== X-Received: by 2002:a5d:59a8:0:b0:21d:1bdd:44b9 with SMTP id p8-20020a5d59a8000000b0021d1bdd44b9mr3417839wrr.7.1656410348977; Tue, 28 Jun 2022 02:59:08 -0700 (PDT) Received: from [192.168.0.252] (xdsl-188-155-176-92.adslplus.ch. [188.155.176.92]) by smtp.gmail.com with ESMTPSA id d9-20020a05600c3ac900b003a03be22f9fsm17712354wms.18.2022.06.28.02.59.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jun 2022 02:59:08 -0700 (PDT) Message-ID: <7580e511-169e-4b9e-061d-1ef6893dcb72@linaro.org> Date: Tue, 28 Jun 2022 11:59:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2] soc: qcom: cmd-db: replace strscpy_pad() with strncpy() Content-Language: en-US To: Douglas Anderson , Bjorn Andersson Cc: Matthias Kaehlcke , Andy Gross , Konrad Dybcio , Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220627171816.v2.1.Ie7b480cd99e2c13319220cbc108caf2bcd41286b@changeid> From: Krzysztof Kozlowski In-Reply-To: <20220627171816.v2.1.Ie7b480cd99e2c13319220cbc108caf2bcd41286b@changeid> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/06/2022 02:18, Douglas Anderson wrote: > Commit ac0126a01735 ("soc: qcom: cmd-db: replace strncpy() with > strscpy_pad()") breaks booting on my sc7280-herobrine-herobrine > device. From printouts I see that at bootup the function is called > with an id of "lnbclka2" which is 8 bytes big. > > Previously all 8 bytes of this string were copied to the > destination. Now only 7 bytes will be copied since strscpy_pad() saves > a byte for '\0' termination. > > We don't need the '\0' termination in the destination. Let's go back > to strncpy(). According to the warning: > If a caller is using non-NUL-terminated strings, strncpy() can still > be used, but destinations should be marked with the __nonstring > attribute to avoid future compiler warnings. > ...so we'll do that. > > While we're at it, let's change the query array to use > "sizeof(ent->id)" so it can't possibly go out of sync with our later > copy. > > Fixes: ac0126a01735 ("soc: qcom: cmd-db: replace strncpy() with strscpy_pad()") > Signed-off-by: Douglas Anderson > Reviewed-by: Matthias Kaehlcke > > --- > > Changes in v2: > - Size array with "sizeof(ent->id)" > > drivers/soc/qcom/cmd-db.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c > index c5137c25d819..ffd2660b2890 100644 > --- a/drivers/soc/qcom/cmd-db.c > +++ b/drivers/soc/qcom/cmd-db.c > @@ -141,14 +141,14 @@ static int cmd_db_get_header(const char *id, const struct entry_header **eh, > const struct rsc_hdr *rsc_hdr; > const struct entry_header *ent; > int ret, i, j; > - u8 query[8]; > + u8 query[sizeof(ent->id)] __nonstring; > > ret = cmd_db_ready(); > if (ret) > return ret; > > /* Pad out query string to same length as in DB */ I would find useful a comment that length of the ID can be equal to sizeof(query)... so no one will need to increment the counter of wasted time on this. :) But beside that, thanks for the fix: Reviewed-by: Krzysztof Kozlowski > - strscpy_pad(query, id, sizeof(query)); > + strncpy(query, id, sizeof(query)); > > for (i = 0; i < MAX_SLV_ID; i++) { > rsc_hdr = &cmd_db_header->header[i]; Best regards, Krzysztof