Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp738385ybe; Wed, 11 Sep 2019 04:02:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRZoqXPfCCZRqBn9fNhJngdZW/glpypUfDukvcHiN4hxFClU9vUT9vF1Selr+mA4FHveFs X-Received: by 2002:a17:906:7e52:: with SMTP id z18mr28528144ejr.114.1568199763426; Wed, 11 Sep 2019 04:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568199763; cv=none; d=google.com; s=arc-20160816; b=l+PF3OlMlRbCWEGnNtGmAShrERdfHQN1H2dHPJTdCwIPO+72pY3xk6WvCqjPy+9Nb9 cVjwdeGbCPnDV9iPayonAgeJRnkEefGaiKfOIndvwgq7YUak6ncEo++kOgJPo3yS0PuG 4VU6c6PKkzEPW5moPX+OTQKipdoNHCNV9xHGih39XAwKYKGDzY9UPL5Z0DDSBiZtonnQ UmZWRzYA1Hjl86P9zXLGRF9sBEQgGsYMpa/gJ30ZKe5b1yTJEFQPDj9ZSoLYfK58wVIy VUoxaHweN9cK1DEnO0CBHN6879xXNkjC+RrG3GSsAahFCzfEDFnExfHdQpEwFAPxHtLD k0Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=4/T0pBGAJHntS1Kbm8BWjyn4roEDB9HgEnnPwYPp6zU=; b=0iXL2Jo+fOymSHZZkKXrl452Czff//U7lwglcklKV99FS5IL3Xg0DWeqtvKOz1Y3tb MVJYp8uookroD7N81IfAq7oIrWklAJ051RJNi5lCVqkxhkxwX1gl77jNvt9jtfOMK3H6 7z8jEj70sjf1fxXb+y+2XRyc0hM1kLstaXKJsNK1NLA48T3zxdxmWGzr8JQU7nvNwf75 md1nboJKqm8aqtqWifGrAwSi8LEc74bOQxTLaXW/0NWnw2jfo2fRAj6UEPk7EpTQ3J4q GUg7YJrGXvqguYrjO+5T56HsTnou1Qer/oQrv2He+JLuS/QrI9P2jBeOKCmXI3rIwjyH oTiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=BMMT6gr1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h20si12236486edb.218.2019.09.11.04.02.19; Wed, 11 Sep 2019 04:02:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=BMMT6gr1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727329AbfIKK6T (ORCPT + 99 others); Wed, 11 Sep 2019 06:58:19 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39864 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbfIKK6T (ORCPT ); Wed, 11 Sep 2019 06:58:19 -0400 Received: by mail-lj1-f194.google.com with SMTP id j16so19562616ljg.6 for ; Wed, 11 Sep 2019 03:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=4/T0pBGAJHntS1Kbm8BWjyn4roEDB9HgEnnPwYPp6zU=; b=BMMT6gr1xD18cZuT2TTRNbmmh75K7oPCt2ItEaNQ86K3SW0V75avif6iot3oOycBSF mRLuGmijn5tAPGsHleo0et7lMUf8LfjAfhj3kzFt41/DDRnILbZ7aekiFmKwCuPcPype /tvYS4eUinsdE71SUB/71Xcs3v9Pvp1a5TGF8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4/T0pBGAJHntS1Kbm8BWjyn4roEDB9HgEnnPwYPp6zU=; b=XIJtSk46VjUbovYceSs2K5KHRphDn74HOASOrB1guc7tqNu/BHB4PIqjAnSYlNzYln A3GIjejg4zIg54pWgjtnQSsxIXWJ3Na0qoba3h+DBnGWCrWYwi4ItI/+s/3qXL1xM10g 203RMNMauAiHAbOLq4IZ9pvnCa4Yeth20pCeXCCyUpLTlKOYDV2S+NTBFSim+ocn175r d1oT+LD8NvgyNUNLuj7G459CBdaEbU9A1XN0YYWzVpIGdYiRldf3Tqo+deUxSGKn8mRY 498eYysUmu7m3jWniqjNFt1CwWCY4aTPn31mgAa37V9hJEAeVexh+CfNWIi2IQWU/b7f tyrA== X-Gm-Message-State: APjAAAV2U7WjLL5XI9ZOjxPqZdI+hJE63gHz6VHMTx3qdsDxkkCEmiJ+ /zAtvQKV+IayJ6WLUEMc6eB7SA== X-Received: by 2002:a2e:50b:: with SMTP id 11mr23331127ljf.11.1568199496973; Wed, 11 Sep 2019 03:58:16 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id x11sm5255046ljc.90.2019.09.11.03.58.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Sep 2019 03:58:16 -0700 (PDT) Subject: Re: [PATCH] Staging: octeon: Avoid several usecases of strcpy To: Dan Carpenter , Sandro Volery Cc: devel@driverdev.osuosl.org, gregkh@linuxfoundation.org, davem@davemloft.net, linux-kernel@vger.kernel.org, aaro.koskinen@iki.fi References: <20190911084956.GH15977@kadam> <39D8B984-479C-42D5-8431-9FF7BD3A96D6@volery.com> <20190911091659.GI15977@kadam> From: Rasmus Villemoes Message-ID: <7a004f18-50cd-9ab0-40b0-051624f0fb95@rasmusvillemoes.dk> Date: Wed, 11 Sep 2019 12:58:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190911091659.GI15977@kadam> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/09/2019 11.16, Dan Carpenter wrote: > On Wed, Sep 11, 2019 at 11:04:38AM +0200, Sandro Volery wrote: >> >> >>> On 11 Sep 2019, at 10:52, Dan Carpenter wrote: >>> >>> On Wed, Sep 11, 2019 at 08:23:59AM +0200, Sandro Volery wrote: >>>> strcpy was used multiple times in strcpy to write into dev->name. >>>> I replaced them with strscpy. Yes, that's obviously what the patch does. The commit log is supposed to explain _why_. >>>> Signed-off-by: Sandro Volery >>>> --- >>>> drivers/staging/octeon/ethernet.c | 16 ++++++++-------- >>>> 1 file changed, 8 insertions(+), 8 deletions(-) >>>> >>>> diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c >>>> index 8889494adf1f..cf8e9a23ebf9 100644 >>>> --- a/drivers/staging/octeon/ethernet.c >>>> +++ b/drivers/staging/octeon/ethernet.c >>>> @@ -784,7 +784,7 @@ static int cvm_oct_probe(struct platform_device *pdev) >>>> priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED; >>>> priv->port = CVMX_PIP_NUM_INPUT_PORTS; >>>> priv->queue = -1; >>>> - strcpy(dev->name, "pow%d"); >>>> + strscpy(dev->name, "pow%d", sizeof(dev->name)); >>> >>> Is there a program which is generating a warning for this code? We know >>> that "pow%d" is 6 characters and static analysis tools can understand >>> this code fine so we know it's safe. >> >> Well I was confused too but checkpatch complained about >> it so I figured I'd clean it up quick > > Ah. It's a new checkpatch warning. I don't care in that case. I'm > fine with replacing all of these in that case. But why? It actually gives _less_ compile-time checking (gcc and all static tools know perfectly well what strcpy is and does, but knows nothing of strscpy). And using sizeof() instead of ARRAY_SIZE() means a future reader is not even sure dev->name is not just a pointer. Moreover, it's very likely also a runtime and .text pessimization, again because gcc knows what strcpy does, so it can just do a few immediate stores (e.g. 0x25776f70 for the "pow%" part) instead of emitting an actual function call. Rasmus