Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp823225rwb; Thu, 18 Aug 2022 12:57:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR6hxCPo/2jJKoKNA7/+VXeqd3v7hQ4+IZQly3G2IjS+Jr+BbbMCbQDqMHKmqM5o9hwaaAeP X-Received: by 2002:a17:903:190:b0:16f:642:1a72 with SMTP id z16-20020a170903019000b0016f06421a72mr4338734plg.113.1660852633891; Thu, 18 Aug 2022 12:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660852633; cv=none; d=google.com; s=arc-20160816; b=PNja/f0ZOaY8Co3l0JRPILSRGACCg74g4VkNHRSCpPPRZvi0SVdFd4MJK8I0e3f1C2 XEtuVmNSsUkVjsAnM/orIHsPMBca27OGOHr7msJHjHlcFsS0g0iNlc784eTJs7IfKhXk Oplkf+rKk0EE3QlvXeYQIhg9Mo/REj6enxy4Z3gAwu0W0gYuiIWyP0P3a4xQbFxxekI1 hpUYa6D007TXhHRTEDp4dPSl+xGsF0LGw1bPrE2nWNe+gzyNIqTDqS8CnyUehrcdgmh8 HOlpWHDzSXGLJxIOKqHBL9jKneRYZZluB244r2CqeoGxiC0y6FsMwcRN6y5c+ZFSNbNP Z5fA== 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:subject:cc:to:from:date :dkim-signature; bh=qKIZ6XBYx3MttVcqQ6AQvDcBwEgkjVO/ZPiATXR4euM=; b=i/VMu2xvrhkabu3Cz6SAf5QquAfU0Yw503eHvHCrFWDNLKql7bSmpyQs8VPVi1Z4+C MZ9lZqrt7sED3e7hCamQgiIAqIXRKQ/KzSrSovZ7WJi5Z+XmAG6CMTUM25FwrlVEy4Hf MN7w6WK01adWtKfVaezJIy9xwMfbj6/zJZWF0hLL6XIl9+ZK03vp7/asaWAtj7bnNHsO qlgXL+iUiJ78mV2HbsWwolLLS333qcUAop1IjidcaidsPBXG3DCh69qlFx6yQrQ5uFhR luPJlKr5fBaULBAzQnTrsLFHGVZH4JoPL/FWXnqUf0mIjsisy3hhoRsm3jz5V9WLcQLe 3stQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OzoOBygB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y13-20020a63180d000000b0041ccf0b2e64si1960301pgl.12.2022.08.18.12.57.02; Thu, 18 Aug 2022 12:57:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OzoOBygB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1345628AbiHRTss (ORCPT + 99 others); Thu, 18 Aug 2022 15:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345624AbiHRTsj (ORCPT ); Thu, 18 Aug 2022 15:48:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 869FE5A813 for ; Thu, 18 Aug 2022 12:48:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 36149B82415 for ; Thu, 18 Aug 2022 19:48:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07503C433C1; Thu, 18 Aug 2022 19:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660852114; bh=LbfCHFjKk6kzGgxEEUBJgU/bUqUM3IB8CCxE0P4a6bY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OzoOBygBfdk21arMXR12/gapkYCLUl5DIZIjGoyLdNfq6LLBUnayGq4VlmnHl323L iZx3xye5Bssk3Ez9gQME9SMvSAdHMUaNueGBEKGwyKqLyF/Z3A/8vDgmzU7vzj+YNw /dPIV2coNRspoY2u0ns/Kb+OTFDInFA9saWHLRn66nOcXEeVl1eXzOTBvbcjbhI3GX ueICF1IHxevnJkimJ5YUZ3bj14htoUYrdSQTyrUFmGovJVl1rh8VQd6p2LnCzKJO0C M1R/9YezXiYJoWBw/nhVmU/GAhwePb02Ze6VKUNtoKK31e03j8DEFjuqjYdhHvrBBJ bFRPejkcm5irw== Date: Thu, 18 Aug 2022 21:48:28 +0200 From: Marek =?UTF-8?B?QmVow7pu?= To: Andy Shevchenko Cc: Vinod Koul , Kishon Vijay Abraham I , Linux Phy , Kees Cook , Andy Shevchenko , Daniel Scally , Gregory Clement , Heikki Krogerus , Sakari Ailus , Linux Kernel Mailing List , Pali =?UTF-8?B?Um9ow6Fy?= , josef.schlehofer@nic.cz Subject: Re: [PATCH linux-phy v2 1/4] string.h: Add str_has_proper_prefix() Message-ID: <20220818214828.22023dc7@thinkpad> In-Reply-To: References: <20220817200335.911-1-kabel@kernel.org> <20220817200335.911-2-kabel@kernel.org> X-Mailer: Claws Mail 3.19.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 18 Aug 2022 22:10:58 +0300 Andy Shevchenko wrote: > On Wed, Aug 17, 2022 at 11:06 PM Marek Beh=C3=BAn wrot= e: > > > > Add str_has_proper_prefix(), similar to str_has_prefix(), but requires > > that the prefix is proper: the string itself must be longer than the > > prefix. > > > > Signed-off-by: Marek Beh=C3=BAn > > --- > > Andy, Kees, could you ack this if it is ok? =20 >=20 > Seems to me there are too many strlen():s. One is hidden in strncmp(). I thought this was ok cause gcc has optimizations for this in https://github.com/gcc-mirror/gcc/blob/master/gcc/tree-ssa-strlen.cc But now I see that kernel does not declare these functions as inline that call __builtin_strlen()... so probably the optimizations are not used. > Besides not the good naming (what 'proper' means), The naming comes from similar naming in math: proper subset is as subset that is not equal to the superset. See https://en.wikipedia.org/wiki/Substring : "A proper prefix of a string is not equal to the string itself" > the entire function is not needed. You may simply call >=20 > str_has_prefix() && p[len] !=3D '\0'; >=20 > Correct? Do you mean that I should implement this function to simply return str_has_prefix() && p[len] !=3D '\0' or that this function should not exist at all and I should do that in the code where I would have used the function? Thanks. Marek