Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1314069pxu; Sat, 5 Dec 2020 11:12:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtEOJadLuegM6copP/CRZNtsZX7wz7CklQFbzkOIFuk/ojhtc9Xg+bu+v7NZtIw9RGmDwD X-Received: by 2002:a17:906:4d52:: with SMTP id b18mr12043573ejv.405.1607195554800; Sat, 05 Dec 2020 11:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607195554; cv=none; d=google.com; s=arc-20160816; b=f8xhPAUtgrbJtu+RqVI8dLrxLcO15s9N0CdozK7gxrsb8CHasgBTpIsCnHKx1DGRtT WB1iPlf+/h0V29YzP2AN43I+1ac7wMBtpYFYayem3AAimx9kvhSoA9CPjjUI9W9NmEuA BQmyoyFyKQ4h6Wf73RyfVtnnq2mfeXv3HydZGZTxtYgYsAN0qkGXMFZXE5zXxky+Tai5 x1Bbx1YJERP44IXAMACov2lYia569ky76EfMOgGz3j9iG+adWJc90q7l0kS9qbPfaNjt YPCaxckvgc9eJNwC7hcALgnAx3PmMN+dibXzL/9DSnS3/QEzXRTX5SiwBkTJQZyCH3XT /QzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Enxbl35bWgW2k4CXkeFg1MrWekQN+UnByDQFI9Ki+mA=; b=BsjmtrIYoyS6WGO7cBz7m1KB1FmHCvEJ6wv35d/BvvijRrFyyCNSoozsTOeDwntcJf QIf9eLgX4Ix/6qTYAT1UUObXM6AfVNxKA5efVzIbiCm33yffVtgLsqtzTv3K6phD//3M 4R19WDdCyAiJD6uTXfB74J0Gz3Hq1UN9ZyYtV0rrizU0xBMp4aFEx1qaZpJY+c30F2eb qb8IzUNGLteGRiz09bHoBPefcuthAX1q12JVswKi0HEnSfPLPkrNiOswOpvS3ZZYfUDA raGHhUEO96/VUL2PEBvhH32A9/ZaZTN17yaYTWy2SzWEFikkNcGU2OSi7L6vONwYKXIj cLvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@privacyrequired.com header.s=stigmate header.b=IN0WugIk; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si5270478edw.454.2020.12.05.11.12.09; Sat, 05 Dec 2020 11:12:34 -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=@privacyrequired.com header.s=stigmate header.b=IN0WugIk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726276AbgLETKb (ORCPT + 99 others); Sat, 5 Dec 2020 14:10:31 -0500 Received: from [198.167.222.108] ([198.167.222.108]:40979 "EHLO devianza.investici.org" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgLETKa (ORCPT ); Sat, 5 Dec 2020 14:10:30 -0500 Received: from mx2.investici.org (unknown [127.0.0.1]) by devianza.investici.org (Postfix) with ESMTP id 4CpJyb073Xz6vZP; Sat, 5 Dec 2020 19:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=privacyrequired.com; s=stigmate; t=1607195335; bh=Enxbl35bWgW2k4CXkeFg1MrWekQN+UnByDQFI9Ki+mA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IN0WugIkKjzuabyrLtCIqrR5Dz9NmwNdrJ2PDOHkbzu+mx7X50hjdtiNjCESr/O4T 9G1STvvilcWHw6XLRChWJvAaKHumeLDAxPFyBlKW+m++YelIpnAUKL4YKuaKgjMXg/ WJBQXXLzio/SQvLNIV5MvwVfnuiJ24euv3+PB+h8= Received: from [198.167.222.108] (mx2.investici.org [198.167.222.108]) (Authenticated sender: laniel_francis@privacyrequired.com) by localhost (Postfix) with ESMTPSA id 4CpJyZ5dyqz6vZL; Sat, 5 Dec 2020 19:08:54 +0000 (UTC) From: Francis Laniel To: James Bottomley Cc: Ard Biesheuvel , linux-efi , Linux Kernel Mailing List Subject: Re: [RFC PATCH v1 07/12] efi: Replace strstarts() by str_has_prefix(). Date: Sat, 05 Dec 2020 20:08:53 +0100 Message-ID: <2156854.ibmmEGdOxF@machine> In-Reply-To: References: <20201204170319.20383-1-laniel_francis@privacyrequired.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le vendredi 4 d=E9cembre 2020, 19:02:09 CET James Bottomley a =E9crit : > On Fri, 2020-12-04 at 18:07 +0100, Ard Biesheuvel wrote: > > On Fri, 4 Dec 2020 at 18:06, > >=20 > > wrote: > > > From: Francis Laniel > > >=20 > > > 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. > >=20 > > Why? >=20 > 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 >=20 > if (strstarts(option, "rgb")) { > option +=3D strlen("rgb"); > ... >=20 > with >=20 > len =3D str_has_prefix(option, "rgb"); > if (len) { > option +=3D len > ... The proposed changes were a bit mechanical and I did not think about using = the=20 returned value in the way you proposed. This a good idea though, so I can modify my patches to include this and sen= d a=20 v2! =20 > 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. =46or the v2, should I only change cases where using str_has_prefix() bring= s a=20 benefit over strstarts() or all the cases? > James