Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1325314pxu; Sat, 5 Dec 2020 11:40:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuB9kCnMUuZV6hCj38K+dGiYPeNNDsu2zxEpZN98yTEY78+r2jV0GINVPOMJOS9NgamS3/ X-Received: by 2002:a17:906:8152:: with SMTP id z18mr13105147ejw.317.1607197214759; Sat, 05 Dec 2020 11:40:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607197214; cv=none; d=google.com; s=arc-20160816; b=CPkJTKycS+9ILOIH8nwpOh7RtukHGo+bjyp0NPV3rC/A5Xj91uDIrOghEbouer0qvj 5ZXKzFk0VOpTRkd3B5gc3nc537IHF5uXCfzr0w9FrXyHcXioyKf8Kw6fF65mAJUHa7ra JSkBAt3EdAYqfRNbc5kYwuefiX0Ihw7ikK67BRLLXEmuKrwd089FLOojsIRvcLNRUbsD 2FrkV/cQIZxFEkP2G5d3OVrwjfbjlEt6hZQgnr4MsSaLtmC/Z9WGWmKOO/8uqUBSf3i5 UWIKcBYK8E/Dx5fP3/NPzad6A5wCJJPUupizuswaVSXGCj8ySSA+jKMDeCau/QJkroba vXAg== 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=RdOtFYzxWPbw1Qm2MH7Iki5UJxaCPBZVQaXouJH0XCg=; b=jspdb/OG5OIeeLZxKmoFsX/ghFvFSl6CNvzCaGb4sn1/Fkq5jmQEDp7L+Kexb+K3Qu nVIOsD14F+/ADmbLGOx3LTlBAWPnC+0e9CQmsTP5X2C05DZgUukATN7GkhwytkHGXVNA TyOnQBKbGtHHcjeBnTxXhAioCkK9+pRZpSFx0SL0mrs7ABqBSsmAsnGhtbSP6v9U3mTf dadPETUNE9afsUHWu/10xuHuPBxp6juklPU347f9acRr/YbtyLH5SWHeqxeM8RtNBv9a wiiRkeUpZQW72C/otpwJMSQbo2Dr7EowNqwsdmgraLI6CHmcgXOcskCmhws9sQ6F9E0Q Pmew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t6uZgz+v; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h26si3768810ejq.399.2020.12.05.11.39.51; Sat, 05 Dec 2020 11:40:14 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=t6uZgz+v; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726263AbgLETgz (ORCPT + 99 others); Sat, 5 Dec 2020 14:36:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:58432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgLETgy (ORCPT ); Sat, 5 Dec 2020 14:36:54 -0500 X-Gm-Message-State: AOAM530zyfGX7xyg/p8wjyiN5xEAqIZwrhtDSGxcIs6RndBYbKexZILi pbU7nTl/34548WYfp0Y+DTRkCM2Jdoy6AjnRjpg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607196973; bh=sBZiwbc9G/QgjgUAGJx12HLC1iZUViENrn7bnf9AiX8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=t6uZgz+vY0R5S6gScN6STOedcjxRl7EFEqjzoyC1bqQLU/2VD2xClYG01RHgYvG6K UIpC3cKH8RSMXgQjZY5sB0d3mrCfo9mF3gopkZE/150jMQOa4SAGp0jqUsvtFzhtj7 St3NcMs3MbJNadTSM9E62nXQI1fM7wSmxD0s+kncGqIa8ZWUO3wMjMr8qGJwSaJnH1 NG/QsWsEhQt2WcQz+dnfFTTobmIvj5JizPakNVhEAbm4aBwM8QTLkPbS+n0Z77uBWJ GFw22tBVs85VLWzpSvQrltNDKHLHD/aNClPNd9z5H057wp7EQrnDsGByYVgbOq6Gkb kf8H60IM+n9Gw== X-Received: by 2002:a9d:12c:: with SMTP id 41mr7857297otu.77.1607196973105; Sat, 05 Dec 2020 11:36:13 -0800 (PST) MIME-Version: 1.0 References: <20201204170319.20383-1-laniel_francis@privacyrequired.com> <20201204170319.20383-8-laniel_francis@privacyrequired.com> In-Reply-To: From: Ard Biesheuvel Date: Sat, 5 Dec 2020 20:36:02 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v1 07/12] efi: Replace strstarts() by str_has_prefix(). To: James Bottomley Cc: laniel_francis@privacyrequired.com, linux-efi , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 4 Dec 2020 at 19:02, James Bottomley wrote: > > On Fri, 2020-12-04 at 18:07 +0100, Ard Biesheuvel wrote: > > On Fri, 4 Dec 2020 at 18:06, > > wrote: > > > From: Francis Laniel > > > > > > The two functions indicates if a string begins with a given prefix. > > > The only difference is that strstarts() returns a bool while > > > str_has_prefix() > > > returns the length of the prefix if the string begins with it or 0 > > > otherwise. > > > > > > > Why? > > I think I can answer that. If the conversion were done properly (which > it's not) you could get rid of the double strings in the code which are > error prone if you update one and forget another. This gives a good > example: 3d739c1f6156 ("tracing: Use the return of str_has_prefix() to > remove open coded numbers"). so in your code you'd replace things like > > if (strstarts(option, "rgb")) { > option += strlen("rgb"); > ... > > with > > len = str_has_prefix(option, "rgb"); > if (len) { > option += len > ... > > Obviously you also have cases where strstart is used as a boolean with > no need to know the length ... I think there's no value to converting > those. > This will lead to worse code being generated. strlen() is evaluated at build time by the compiler if the argument is a string literal, so your 'before' version gets turned into 'option += 3', whereas the latter needs to use a runtime variable. So I don't object to using str_has_prefix() in new code in this way, but I really don't see the point of touching existing code.