Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3720654pxt; Tue, 10 Aug 2021 09:47:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyn6O8dPOdfZIk+BIDyTBVgIIxOrPSaMDXxuf1b+P2lWo/3JrwHJRD6UBJ1HGOT7/zsyX1i X-Received: by 2002:a05:6402:22aa:: with SMTP id cx10mr5902892edb.59.1628614027705; Tue, 10 Aug 2021 09:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628614027; cv=none; d=google.com; s=arc-20160816; b=0Ru0UXSZXlZs2Fxtw+GKSTDBW0Rv60mQ/URNDokGjqu7dMIQVr8UM3DWTUAaaZBQnl ZdIc2rIO9XA858oNiOJYNHNDxO//FcBlekrT0o9V/CDu8ENSNODXKItnMs+l6FCUykhv dsLzT7Rx464GRPUOLWOM/+5Q0VruFqWQGrqiXWrGU02Q6889enJ4K97TUxQZibwh6648 11EclrDs7KJMI5OOxppf2yECSDXi62le0/EdqmAMrRHdVYRCl8M4au3dUytHaZZdjOJQ Aa8VwaLDBSrPZ2bekyOadetgZ3KfAH0HAmTt3rc6XrKUu7PD/KaOkZQb2wGlJ9xhCNOi 0Rng== 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 :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+YFWCbfKjvGf01Mpq5hN47zs9aRH+qBhnRAlT63Jj2Y=; b=oTH6X6+Qijv/zg7hVfKnPzN2Ixkv/n/iMYWSDYkzmVuRA7Yt4I0krhxUqi4Nt0yFUB RVKF6YcHsEJgpfQcWvUAezfR/HPgnwz0/FpwUxacOPcD6Z883LNg+qI5Y+PSXeQh/H8q qrWQefnP/IsPmmpjZcaFbGF5bf7Zeb5BesSV2RJ451w3LBZsWAM+w35kJYNm5VddMKXv /5LlL1tNu4YY5rliACIeuUN5du/WMaMkA06kL3UAO6USVlgzrVfM3WuiODtLwp9Ib2Jf Rk0li0voZMCiXVHG9XN2FwEMHm/JAdSCTLEKGs14XAfGpPCWeucBSgKAMlQacWuzNxls ifjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=gaNLTcUf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq2si20845850edb.572.2021.08.10.09.46.40; Tue, 10 Aug 2021 09:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=gaNLTcUf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243317AbhHJPoA (ORCPT + 99 others); Tue, 10 Aug 2021 11:44:00 -0400 Received: from mout.gmx.net ([212.227.17.20]:47579 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242153AbhHJPn7 (ORCPT ); Tue, 10 Aug 2021 11:43:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1628610195; bh=f9yoZklWAOjRko5GEHne/rB2HxvyimqQxu/6RVsxWfM=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=gaNLTcUfYmNM6APGQiF0FHtnKBz1zKej6HpnDaAgzlhG4E4nolV22WYw1d9mw+2Ns K4MT7IXSfb7VXEFBMevPZ93nvFZJOqq3FBeug+5SrVpcPSfkZDKKLRaxJJc/VKO03P hI6cHuNhjDVvTJGl2HqqzCULIGUdIq1dWdsNecnU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from titan ([79.150.72.99]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1McpJq-1mlzNZ1L0s-00a0AJ; Tue, 10 Aug 2021 17:43:15 +0200 Date: Tue, 10 Aug 2021 17:43:03 +0200 From: Len Baker To: Andy Shevchenko , David Laight , Jonathan Cameron Cc: Len Baker , Lars-Peter Clausen , Kees Cook , linux-hardening@vger.kernel.org, linux-iio , Linux Kernel Mailing List Subject: Re: [PATCH v2] drivers/iio: Remove all strcpy() uses in favor of strscpy() Message-ID: <20210810154303.GA2508@titan> References: <20210807152225.9403-1-len.baker@gmx.com> <20210808172503.5187cd24@jic23-huawei> <20210809102131.000021eb@Huawei.com> <20210809161422.GA2619@titan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:cRHTKwbL0WqT843vcAOgaEC2gKAhlW/Nz3Siys7qUczMedk2Sbz CYN4XnCy+VCfuctiQz9MiYdV5tnke7l4479UWw9mSEI7qzLnwIdoeFbWEj+BKtMZaWPVbkn trYBZMDm8S+jM0W5vVjDREqytula4FEoFEuF9qybQUNsUbJquEdW6/QwOOnaRB2rKHsA2vY rY+5uB2126WMJm6t9xDQg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:VZWlOome2sY=:7hkCJf7Tk4hkI7kJ3dIFPt 8tK3bg5/XlCkE+AeqXrX3+HxOLVmNaM3vuMDqj4LOmQhbUdI5OG10C1d5a8IYyu6Ti8TAuQ9D ja0T8XxUpLRI8vZDqvMzHXJIbW+lHdCsKhCXD7miGhVSFQL7xAlsLKVVsEmZVfJBRYUOo+TeQ qGtjyQJwUVWUkcz366Y0nS9ZWuuXgVUUX3H8GQn5m2CT3uWiAMVtaChiHZXucm/HBS9S/BdKG L87yLEBZr7EpTguHVMTtWOZVEbGm5j/L9U/c1CkzWhbwcvoH5RO+YKul+tirAhxWjMVAk60Sf 8atQrQSdktM3B0SeDoTIVjFu2WdQo+Pd7xASoCgfXJbzonvTBGcBvB1e12BCF5QusxjPjse3E 2EjOHLvaZjaBVqz7WW1Vo827qgK387et7r4e9Ru+DxzoE9q4CQR0b8hepQRXefNN9SVNB8dCF g0X6jmJe+Szpmlm34awqWB9ulCH4DGIAqirzrmefkVC+7A+861RExTO7Ux2lD6n1kId2/NyUB FtGe16ELqiNdDE20+xndkX3Pg2mL5LsfZ4Pwa3METKwCglQuoecOA8X2gxZw4HwoEcfpzW+Ae d18+S4wbAWjuV2X8oZq92I+V3aCLBrZvJnZprjbyZpY7D68U4fFABoJktK7ZbDhrmhBp0gWgJ f4uAT3B5vK0xCW2KsTjqeXWFz1OAhfu5hKKZPc3udIJcObwzoznA0T+/75EMzxq/LQujctCbH h4z+7Oto8UCefyDxkuQyI2jJTjoyvRCKmtUzsIiMmHMuJYBRhF/pJ6NdALjTTsUuMTcrDpLI+ L3L4vZQjrXdrsWg0/PhJLdAixhndGMgpJGMwat5GiBEnwnHRsAafTGrOE1sNWO8LqGn8OdOHY +PPMCz9IxfTkTwk4xnaPYBKOugp9H7hWPQvF46tyb+wDon3hRVia6F2rGUxfvIkLFRHpIpCef YYajSEVtSy3oDeIyqGjdwWPV/ziEkt3X8kUVBksfPDKwKkvJn7aalvw1laAyxytI1kWcL20fE q4omv7Dh6htr5og+YV42Dv5kuP4vyGY2IxEEP0XwCh2x+zDACsxFoFAhTVmekBqdw2thwwJZf G2R1JA6i5fBOWbUdUbZxVa7HucMs/pFqNOYX6A57Quk9dPKwT5rGBT7LQ== Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, David and Jonathan First of all thanks you very much for your code snippets ;) More below. On Tue, Aug 10, 2021 at 03:11:01PM +0300, Andy Shevchenko wrote: > On Tue, Aug 10, 2021 at 3:06 PM Andy Shevchenko > wrote: > > On Mon, Aug 9, 2021 at 7:14 PM Len Baker wrote: > > > > > Even if we leave the logic as is, this might be better > > > > if (orient[0] =3D=3D '-') > > str =3D devm_kstrdup(dev, orient + 1, GFP_KERNEL); > > > else if (orient[0] !=3D '0' || orient[1] !=3D '\0') > > str =3D devm_kasprintf(dev, GFP_KERNEL, "-%s", orient); > > else > > str =3D devm_kstrdup(dev, orient, GFP_KERNEL); I think the above snippet is the right one: Is compact and easy to understand. > > Or these two swapped for better reading > > else if (orient[0] =3D=3D '0' **&& orient[1] =3D=3D '\0') > str =3D devm_kstrdup(dev, orient, GFP_KERNEL); > else > str =3D devm_kasprintf(dev, GFP_KERNEL, "-%s", orient); > > And with a comment added that we negate the result according to the > rules: 1) drop leading '-' (minus); 2) leave 0 as is; add leading '-' > (minus). > > > if (!str) > > return -ENOMEM; Also, I think that it is better to leave the logic as is and don't try to use always the +/- sign. Again thanks to all for the feedback. Regards, Len