Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5208154rwb; Wed, 17 Aug 2022 13:07:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6LZH7pX7tk/84Be6wx43oieIlxXCrZZHSkI7uc6IHG9LBJYVELzv9i7u3WTqXFGur9KRYR X-Received: by 2002:a05:6402:424f:b0:43e:6d89:4316 with SMTP id g15-20020a056402424f00b0043e6d894316mr24124233edb.408.1660766828741; Wed, 17 Aug 2022 13:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660766828; cv=none; d=google.com; s=arc-20160816; b=s1f78z5ZmQ1b2u7ihSGrWzYz881XMsdq4XqdKh1wGb9x/dGt80+lgXjYrFCBRS5Vw0 vgwjGuPEvWDAEnO+E7m49utNsJG3j5aTWfcJ7pnGVSy9TFNmtJerhzit5m/OCg543D+n gPbruFXDYGVv/dQbz15OBfTo22v5ZI26s3PzprdUVdjktKDSt3dmcoO2Br3pzFuCpCHJ kuClsemC2bqeHG2VCi1L5ZXyn+3Bz1ra6jwTD7DcX9w4UeugDpp9FO44YVJ6l/Ultj9X +Ljh56lSHVaimCRZTw6IDb4K7/RpgSJ+jWKUjdOgpASGig3arDFFKk8SUt6WUDWHam1E Tnkg== 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=d4VjYSzgB4facUKp1Kh/0fFeRmoqC3r2Kp/ww9vSnU4=; b=BHDn9rLiK8AVWuhyFWaEJxfYmCTr9daxqgPVhFyMDFpBSI3JVmuSaNKs2srEOcqrw9 0hZGtp049QX3iOB/7klJn1xdN8f+OKOxAVGoGWztTNj2ZAgVoxWpGSv8u4oHmDu15g7q qIY9QueXeFSaB7gFY5kKyh2DCrYakTHHuwjCSJbkU33jSKC8P7+V2aNZ1VxkAILycrLC q3Uu3FVSeRFKWq03PEUP3zOSxazxHmr/3S8k2crLpk9xxXXfyGAtbIKW2tMQPZ1TngFn swYBK6nSqD4kAysTqmDmHY6OCdXwZw3r7ocy2972bVRfuUsU1V+Jrw6uES9u4NCv8uU7 ubvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IybX3rRa; 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 dp18-20020a170906c15200b007386cbc7461si6950896ejc.210.2022.08.17.13.06.42; Wed, 17 Aug 2022 13:07:08 -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=IybX3rRa; 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 S241674AbiHQUDu (ORCPT + 99 others); Wed, 17 Aug 2022 16:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232057AbiHQUDr (ORCPT ); Wed, 17 Aug 2022 16:03:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD5B1F623 for ; Wed, 17 Aug 2022 13:03:45 -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 A5C65B81F61 for ; Wed, 17 Aug 2022 20:03:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBB2FC4347C; Wed, 17 Aug 2022 20:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660766623; bh=wv0Zebl3/M8/sl1p7uqmjBF5ITW2e0LsrTBPWFRbNuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IybX3rRa0kAATdNa9CEutWHHd6nJNB/y5T4vkHUm4SCBxsG8J6o2lnKb5ITB9GZwT WOunqvHZDReF98jHFUrT4omATeTvB3UCsg/rZDPxcxrrDrtzAcum1B8j4gTkqj0NLe en9O7rOnvqqyggowmKPE4BeGmXuDlKMcTntGHaJ3PwQamtksLtjybpR/aPxmhpwVMg pA2qJizPk36y4j50+h95mxHjC0e9BVblhawKMwatNS0D4RpoUMf6u6kUMoXnrzZfTH 6NXMp7SKRpNPotFkq14UcIQPtJFT6KTkDsDWLgb0zPPUVkbS/L4c+4E5yToxy65t3j CT26aaydcxB2A== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Vinod Koul , Kishon Vijay Abraham I , Linux Phy , Kees Cook , Andy Shevchenko Cc: Daniel Scally , Gregory Clement , Heikki Krogerus , Sakari Ailus , linux-kernel@vger.kernel.org, pali@kernel.org, josef.schlehofer@nic.cz, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH linux-phy v2 1/4] string.h: Add str_has_proper_prefix() Date: Wed, 17 Aug 2022 22:03:32 +0200 Message-Id: <20220817200335.911-2-kabel@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220817200335.911-1-kabel@kernel.org> References: <20220817200335.911-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 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Ășn --- Andy, Kees, could you ack this if it is ok? --- include/linux/string.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 61ec7e4f6311..375f51b9182c 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -316,4 +316,22 @@ static __always_inline size_t str_has_prefix(const char *str, const char *prefix return strncmp(str, prefix, len) == 0 ? len : 0; } +/** + * str_has_proper_prefix - Test if a string has a proper prefix + * @str: The string to test + * @prefix: The string to see if @str starts with + * + * This is like str_has_prefix(), but fails if the strings are equal. + * + * Returns: + * * strlen(@prefix) if @str starts with @prefix and they aren't equal + * * 0 otherwise + */ +static __always_inline size_t str_has_proper_prefix(const char *str, + const char *prefix) +{ + size_t len = strlen(prefix); + return strncmp(str, prefix, len) == 0 && len != strlen(str) ? len : 0; +} + #endif /* _LINUX_STRING_H_ */ -- 2.35.1