Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1985627imu; Sat, 22 Dec 2018 09:31:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN6rbvoW6DfPW5hQzwTTvWXQdw0Fkg+YDrhgrPXfQZbhKmcLEgFWAbH8xXOBhZyn3YIoMlUt X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr7046155plg.222.1545499906439; Sat, 22 Dec 2018 09:31:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545499906; cv=none; d=google.com; s=arc-20160816; b=ekoPaqK8lTtFskEqBvqJVOIzjXFTxt+vQkOUX0ZjTK7gr8DY/Wuy9SGMQnb8rvUuNA CX5ZN+B1bZbXygWaoFiO7YX04vYrfA8KtWuv5UUTS1gtsrTYElJp84Pl+1pNJGEgi7Yw V8aaOkxAVFXbo0RxiTpxvYTZsFKyimM6oeLvTYr1kvd/DbsnXBYs51kCmsKBPcYTAciK bhJ7hUU+MvOB5HgpnvRuULNyaPAYH6LuNrXyth4nYYhK9vh1sYZLNHX5wxr6KL8vur8Q HNGGX1SKi5rWbTBHLRjSIkP4/4KRFQLsRVRgLhpOkuhW0782RgFbnVxp38jNx4uvCFVH z6pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0zApp6IS+WoZWhc5M0SkUqLBNZjji60b0VHaYT0YWxs=; b=tFz/ZSaipglVecyAWNXZCuUnBw4mQATM3flO9S9f9NmomvKtpWPtaelVrYV9RsJJ6o 6JtnKJtqQhoIU8NuqxWVNw2DwPXKGqgLXlIf73JKJmhYA/Y1U+0AHa2jQRCKqc9imsbb Mn81Akm+KhBO1yfkrMWurPi21SdSPgeku9F/j4KwW7cgrt7tuN6YVDD/br/isEusROeJ vn7szser6AS8Ii9H4BOpUDiAYFMuqKLOBZLiN9dDK8CObUUvMZG+O/0XsuGALj0WKgqn lCiBwhoT1xNGBec+OiEDZqgq4LwDeG8Q7piyUGqLkzrZYHpRMrsazFZXRLJqc6GC3fAJ VZzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZYb4o5aJ; 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 i190si13009762pfc.116.2018.12.22.09.31.30; Sat, 22 Dec 2018 09:31:46 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZYb4o5aJ; 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 S2404498AbeLUSvu (ORCPT + 99 others); Fri, 21 Dec 2018 13:51:50 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46393 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730799AbeLUSvt (ORCPT ); Fri, 21 Dec 2018 13:51:49 -0500 Received: by mail-lj1-f194.google.com with SMTP id v15-v6so5597360ljh.13 for ; Fri, 21 Dec 2018 10:51:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0zApp6IS+WoZWhc5M0SkUqLBNZjji60b0VHaYT0YWxs=; b=ZYb4o5aJncBjQAfYc+C05uVka9XxdOGnQnhvKj/OqagU7c2LE9ScYcylYovOPQiX6y rEXD5IjuJLRQanfcTS1h5+EOyGlj6yZIvgzq+bsBwauuYvi2H3DRqCw4F7KAbEXCCRZc Xgjo+vtWY7ItLDGNn9WfF6RpqHvrZZs4gskv8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0zApp6IS+WoZWhc5M0SkUqLBNZjji60b0VHaYT0YWxs=; b=TdfZVwQtWMbGRZik6+qCmg0LR+af2mKJZizo+HDSF+XT71YNGBoYDRLR5PiTbmNTdj 4leXmVE1LejbjR66vPs0RDgWGCnz/7pn6Tk9+jjaTgGoiRBmzB1jjyue/T2KQnhF54gQ t8SgVZJFvvVwvVDlkJ4cZOG6qm/FKDOdBSy9bn5NEHSUpL2oNGNbxLX3LMDNJuCO+cdR VTPkdvM6g9oW1rLg49ezbTiGf+btpSia/Hfr0Rh7NxlqtF9OTZKPDjwD5N8ia2KvWRFK Kfte3GXKXZcws2vWapgpFZjMjYVrnstnWkuLnk52j7PIN8HoQIZQpXjmUTibMVZX8cOa AKFQ== X-Gm-Message-State: AJcUukfZ0lfsjBOhwv+W7e0QPBil7jMYJUMahqOdqw/Jr+n0/KeF6wmx d7mm7sr1z3u7WUQ6pi8K0qkAZHO4UWk= X-Received: by 2002:a2e:908b:: with SMTP id l11-v6mr2356488ljg.150.1545418306387; Fri, 21 Dec 2018 10:51:46 -0800 (PST) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id d190sm5726055lfe.9.2018.12.21.10.51.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 10:51:45 -0800 (PST) Received: by mail-lj1-f182.google.com with SMTP id t18-v6so5609709ljd.4 for ; Fri, 21 Dec 2018 10:51:45 -0800 (PST) X-Received: by 2002:a2e:310a:: with SMTP id x10-v6mr2534379ljx.6.1545418304974; Fri, 21 Dec 2018 10:51:44 -0800 (PST) MIME-Version: 1.0 References: <20181221175618.968519903@goodmis.org> <20181221175659.208858193@goodmis.org> In-Reply-To: <20181221175659.208858193@goodmis.org> From: Linus Torvalds Date: Fri, 21 Dec 2018 10:51:29 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro To: Steven Rostedt Cc: Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , Namhyung Kim , Masami Hiramatsu , Joe Perches , Tom Zanussi , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 21, 2018 at 9:57 AM Steven Rostedt wrote: > > I figured the best thing to do is to create a helper macro and place it > into include/linux/string.h. And go around and fix all the open coded > versions of it later. > > I plan on only applying this patch and updating the tracing hooks for > this merge window. And perhaps use it to fix some of the bugs that were > found. I like the helper function concept, but as they say about CS: "There is only one hard problem in computer science: naming and off-by-one errors". And this one has that problem. The name makes absolutely no sense. Calling it "strncmp_prefix()" when there is no "n" there makes no sense. So drop the "n" from the name. And honestly, maybe it would be better to use a different naming pattern entirely, and avoid the crazy non-boolean "str*cmp()" model. That thing is useful for search comparisons (where "before/after" matters), but it's horrible for the actual "is this true or not", where the code ends up being if (!strcmp_prefix(a, "prefix")) { // This is the "Yes, prefix matched" case, despite the "if !" syntax which is just confusing. So I'd really prefer more of a #define has_prefix(str, prefix) ... model that actually returns a boolean (true if it has a prefix, false if it doesn't), rather than use the "str*cmp" naming and return values. (But I agree that *if* you use the "strcmp" naming, then you do need to hold to the traditional strcmp return value semantics). Hmm? Finally, I also suspect that your helper might be slightly fragile. Doing sizeof() seems broken. I could see somebody using some prefix define for arrays with constant sizes, and doing #define PFX1 "cpp\0" #define PFX2 "c\0\0\0" #define PFX3 "h\0\0\0" or similar. Also, is there a reason you use "&prefix" for the constant test? I don't see that pattern anywhere else. Plus it looks entirely wrong without the parenthesis (ie "&(prefix)" to make sure we group things right). So a lot of small problems, but the naming one is big. Linus