Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3709277pxt; Tue, 10 Aug 2021 09:32:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT5Cs7oWm2JnbULjJUWmcahyprA7k2ANdpqthYHiW+alrQOFcMBvMoJqj8kwlbSi2XJ0pF X-Received: by 2002:a50:9b06:: with SMTP id o6mr6038699edi.284.1628613130147; Tue, 10 Aug 2021 09:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628613130; cv=none; d=google.com; s=arc-20160816; b=dMRWviPgYe6RlkgLUipV8fDaQESMSLiAZ/gEb3zYsD3wGabwfW4PBNXmr7gN82C97D rcEYMJqw//Ro6HVh0+BVZG/oeXsh4aEo41ZQ72el2L3u2sw86fSx8XliZpp4eplnrrSZ nIskXh4KLyTJnQP45YrKQiE+YCYLi6f7BUqcHEw8otMdTuoWIxAPe/zOl3zx4At/M4QP RN2E0Kgh4GWhH3zwbwYDarL9YTbgX0laaGYOLbNesofYm6Fc/FKUhrKLWKFUlquo5O/r tyaekBUIumw1EUbBcSZYKCOLBo6LOLERKYA4vpQH/jqSpeEGiT1YBTd7b9eqrg7vA7vc Uowg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GPJdbMwthIpOx7h1CPyZc0tnb+DSHC0iqh0tr2rSRyw=; b=iDv/BDPecTDGdbwDgdJVX78x9ZoudmpzSJ9FENT+g+1lL1yNxBc1gm7NJTzeP4rfO/ 5lFAX9kEFnf1N/bdJqOIzsUtAXBKuMZmT0cxT90Q//N5Qvth3L3n0Y/8Ip21F/wGEPNp TQoI79y0QqarNm/trOkgXDTguI80xu05nkHHBYskG/prMfWiuHQk81P/Rzg4U8brLOYK VQfJzdQLB4pDGiJBjgBIZHzd32qYbXbVivDVy5Vy3cQ8SUaDrPIfPD1ZdfBM5RlmoxwX xQuccSApTbsi5DzfmPY+UiSeav4dI9ZedkyzwvikdmxbPt/tZxfrtJ8rHUA+mGQycupC W2jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=heeobiTh; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v15si7804940edy.99.2021.08.10.09.31.45; Tue, 10 Aug 2021 09:32:10 -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=@gmail.com header.s=20161025 header.b=heeobiTh; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240498AbhHJMMB (ORCPT + 99 others); Tue, 10 Aug 2021 08:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240492AbhHJMMA (ORCPT ); Tue, 10 Aug 2021 08:12:00 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1353C0613D3; Tue, 10 Aug 2021 05:11:38 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id fa24-20020a17090af0d8b0290178bfa69d97so5058872pjb.0; Tue, 10 Aug 2021 05:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GPJdbMwthIpOx7h1CPyZc0tnb+DSHC0iqh0tr2rSRyw=; b=heeobiThWwJocCp2/RgvSvqY/qOe2lp5nQKleqQsJu6VXfyEzFYXPBh7MXru4EeB16 Z5W7EsuRMm6sUMb79N7lehx75cps3CCvvzWZJgaoZaLf2+aH0AyfUjNKLGYmPc3AVBy6 tQQsVdikPxmrLMCzKnZy30SwbjSG3YlPic7I102HrpElG2NwrujG5Z9gS8zP7w625Rpl opGaZz4PC9ucOygUwE9FnUSohBzBNVEUQ8e5jK4RQZdt/FN4H+o0SXfgVP/pXsrtOQrc U24o9fj50gC6J8XLNMmQKSbnSy4sLTgdQu+5u02l0qorqZcqdMjRARSN2BSVCDi0xpal V9gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GPJdbMwthIpOx7h1CPyZc0tnb+DSHC0iqh0tr2rSRyw=; b=af1/pZCVW6V1ihPvAfeciICuXAGPl5HOr1Rm95ecOl3sPVif0JeKYTMEGWUZ/fUCvJ i8sPP6HCaZuLb7gc308ro+RsMrlwuFbYRsgXLa22+g5Qs4cThSlM7ogkL4jvtTAjmDry bNm2aDLi62Y7tleQMqAcm3xRrqX4s58fBK4GQTeW+sVngf6Hp4RqAkuG6x2PAFroO2P+ lsTO7eFmMQnbW0NIrs5yYEPrfcAxnK/bn/mF/Gvj4hS86vGxva2vNcyEtDawD0LXSnTV DpKZEln6NH3vs651rQNaG9U101FUpVvHoeQiVpbU3TlvA/Jz1XCpfttJ6R0WkEysaCr9 aXdg== X-Gm-Message-State: AOAM531L1Zuo9sKI5HCNqeAI22EVk5S9J6Qm7GSQNDGTxHGC5xlVFuR8 sNx72mae6c/xlivM/Fb4lletpOCTWzNd1iKGYo8= X-Received: by 2002:a17:90a:604e:: with SMTP id h14mr1585585pjm.181.1628597498005; Tue, 10 Aug 2021 05:11:38 -0700 (PDT) MIME-Version: 1.0 References: <20210807152225.9403-1-len.baker@gmx.com> <20210808172503.5187cd24@jic23-huawei> <20210809102131.000021eb@Huawei.com> <20210809161422.GA2619@titan> In-Reply-To: From: Andy Shevchenko Date: Tue, 10 Aug 2021 15:11:01 +0300 Message-ID: Subject: Re: [PATCH v2] drivers/iio: Remove all strcpy() uses in favor of strscpy() To: Len Baker Cc: Jonathan Cameron , Lars-Peter Clausen , Kees Cook , linux-hardening@vger.kernel.org, linux-iio , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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] == '-') > str = devm_kstrdup(dev, orient + 1, GFP_KERNEL); > else if (orient[0] != '0' || orient[1] != '\0') > str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient); > else > str = devm_kstrdup(dev, orient, GFP_KERNEL); Or these two swapped for better reading else if (orient[0] == '0' **&& orient[1] == '\0') str = devm_kstrdup(dev, orient, GFP_KERNEL); else str = 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; -- With Best Regards, Andy Shevchenko