Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3061596imu; Sun, 23 Dec 2018 14:58:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/VVq4wiyvZDEqldm3kBS9VZrHnztB0qzRbvMO3/DO8nHAtwJKR6lC/nELLIruo02yvQe2Qi X-Received: by 2002:a62:8893:: with SMTP id l141mr10949408pfd.1.1545605908964; Sun, 23 Dec 2018 14:58:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545605908; cv=none; d=google.com; s=arc-20160816; b=St4SNVetDzfvROGAtmy3UZH/DM0BbSbxLUM8v/ZDaFJMaOoufj8N5j+MalLB+936Mh NFNCG33H4FIA2iEXBZ1Azu4uGRasenOxm5ikXAevuaqVVNBOSiqRtKPfF2XsZzmIcI3V HihTN0IQq1Fnac5NkgutygH2X4qOqr6+kO0Bo07TxhD9qSTMc6Yjz8gBHyoprxlLDpqK w8ZXCBMOjvtFq3+TvoVRz0wQSNETjvuqr5QhL8czT9nKWl6KL4EmLgS9D96smsIQDouB i3zEIszWWbB7S+a8R9PxdnMgLY8UMQ09h3L+e6oa5maAiu4umctV5LsFg8Fi6l4ObL+6 81OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=ccPL6yEJu1RyHVN6RJ26fZDLmCtrfb+ZdLkpdUZlQLo=; b=uofSxYLyvuAfxxNNzDa+1Brmzb3ATcQ8ZdkFO1/4y3dijWI478OLu+cNcyOb0sVTkr X0OcfBc0cuEODK8icpZbMf9X3nbyALVlQnWXKQO55PtPHvIcip68PbTDArWT3AJp3zev wUqYwqTYRK9peZb4qM7PvulzFjSpcDomCL0tD+sYZNJ8Be9PhNOR+OLvBQZC8V0BBWW9 iIYvtvv23HIAbq+6s3dUIuK2Q35qme1tbBcc5CDtygnTjQiqJTFMNhqsW99eiHkTph+q btAfYYB+BmDa8US4j1xUSEUThyCCnY5n+HrcZR6p6zY1tjqIZrRSJyDnKmGxe0DQ/d/d I3WQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si23799895plf.370.2018.12.23.14.58.13; Sun, 23 Dec 2018 14:58:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726000AbeLWW4Z (ORCPT + 99 others); Sun, 23 Dec 2018 17:56:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:35864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbeLWW4Y (ORCPT ); Sun, 23 Dec 2018 17:56:24 -0500 Received: from vmware.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62C65217D7; Sun, 23 Dec 2018 22:56:23 +0000 (UTC) Date: Sun, 23 Dec 2018 17:56:21 -0500 From: Steven Rostedt To: Rasmus Villemoes Cc: Joe Perches , Andreas Schwab , Linus Torvalds , Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , Namhyung Kim , Masami Hiramatsu , Tom Zanussi , Greg Kroah-Hartman Subject: Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro Message-ID: <20181223175621.4e4d958c@vmware.local.home> In-Reply-To: <098d7abf-5b62-6a01-a370-97d96bece299@rasmusvillemoes.dk> References: <20181221175618.968519903@goodmis.org> <20181221175659.208858193@goodmis.org> <20181221144054.20bdeb33@gandalf.local.home> <20181221153526.5e6055ca@gandalf.local.home> <077eeb8b09baebe78822819b5f15d671b738a2b2.camel@perches.com> <20181221155435.38a9a221@gandalf.local.home> <871s6ad2br.fsf@igel.home> <20181221160826.34c544e6@gandalf.local.home> <84199633fd49db573c9ba71f1992936422e907d4.camel@perches.com> <098d7abf-5b62-6a01-a370-97d96bece299@rasmusvillemoes.dk> X-Mailer: Claws Mail 3.15.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 23 Dec 2018 23:01:52 +0100 Rasmus Villemoes wrote: > On 21/12/2018 23.20, Joe Perches wrote: > > On Fri, 2018-12-21 at 16:08 -0500, Steven Rostedt wrote: > >> On Fri, 21 Dec 2018 21:58:32 +0100 > >> Andreas Schwab wrote: > >> > >> > >>>> Well, perhaps I can just remove the ending ones. I get paranoid with > >>>> macro variables, and tend to over do it so that there's no question. > >>> > >>> Why not make it an inline function? > >> > >> Matters if that removes the strlen(const) optimization. I could try it > >> and see what happens. > > > > Using > > > > static inline bool str_has_prefix(const char *str, const char prefix[]) > > { > > return !strncmp(str, prefix, strlen(prefix)); > > } > > > > We already have exactly that function, it's called strstarts(). It's not exact. > > commit 66f92cf9d415e96a5bdd6c64de8dd8418595d2fc > Author: Rusty Russell > Date: Tue Mar 31 13:05:36 2009 -0600 > > strstarts: helper function for !strncmp(str, prefix, strlen(prefix)) > > Please don't add a copy under another name. > > As for converting existing users, go for it. FWIW, I ran a cocci script > a few years ago to find suspicious strncmp() cases, and there were some > (e87c3f, ca957b6), but fewer than I expected. There are some > confused/confusing ones that apparently deliberately do strncmp(a, b, > sizeof(b)) instead of the equivalent to strcmp(a, b) (e.g. 'strncmp(str, > "hwc", 4) == 0') Well, one thing that str_has_prefix() does that strstarts() does not, is to return the prefix length which gets rid of the duplication. Would it be OK to convert strstarts() to return the length of prefix? -- Steve