Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2447348imu; Sat, 22 Dec 2018 23:18:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN4L8F8z00LfaDuauofW1gWVZC0toIrpIJLXPU40+QK18UaOMF/ZJpkyoN4A4DWZgJLuJZJS X-Received: by 2002:a63:b81a:: with SMTP id p26mr8555883pge.433.1545549517322; Sat, 22 Dec 2018 23:18:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545549517; cv=none; d=google.com; s=arc-20160816; b=xkQeKvsZEFVnLFDk+6q6l6/bhTMjAmgSmHTbjph0vqaGrfNZX3XyVo+59NPdvBBz3/ yL6bXeJKHuuLcaQRHw2K3+LQpUbKjrES044VFTACT/+iU3/aJDwy4vczmvhgRho8TWPZ cu1v5VL0ePcjCBZ4QGiKN276B7Tut/Hpb91rItjSTG+hLU+a/pp9JVwfoOjmRQz+ouAE 9mUuN5LTPBt+gC1xTQs2fKxVgz8W5zrZTFnkPInWYU30fVYrgQ6VzMu0ad78o6zs8VFe X+TzwtDb+DQtJM1kIVpju3Zwb4+7UiX1eXKh3oxR4TR3mPTl5H98pSJP5ABMcF3VTzBz jJOQ== 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=bol/EtSNZ1pGgBcscr2+UR5k7YT/e9qr896uQYhWbMo=; b=WXvBVNNmDwi0xcMCuJ1txXP45WYa/pcm519zS5RE3YPtUei8A0DcjhLqwnPHhUo9yr UwAo+90Fxp1Rx5tgpmgxsml6B6iob+pZDJ+Znpc07dqrQnALTHXeQXqdBGP9Hg4S3VmD 2cKqEzGsy6zbeti+hHkwkRBZly55mICWfR0vpNAH3Cfq3430+Hte2e7dKWEKaJcR45to Z9bI/O3D2Rbn62+WWP0WAQHwQCKBgDjyvMjWITsM3Ki6iCg8UaXgN1ynfQ0p6od5tbNB 5j993zXqHt/Vg7ze8UMhWjZh13sSzwcr0+nBDvsjwgDNiApmPgWY5lzQkVNeU5jAYiPL eoYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Qmq3G1dB; 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 g10si22375451plm.1.2018.12.22.23.18.18; Sat, 22 Dec 2018 23:18:37 -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=Qmq3G1dB; 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 S2391819AbeLUUCI (ORCPT + 99 others); Fri, 21 Dec 2018 15:02:08 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:35774 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389059AbeLUUCI (ORCPT ); Fri, 21 Dec 2018 15:02:08 -0500 Received: by mail-lf1-f67.google.com with SMTP id e26so4736100lfc.2 for ; Fri, 21 Dec 2018 12:02:06 -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=bol/EtSNZ1pGgBcscr2+UR5k7YT/e9qr896uQYhWbMo=; b=Qmq3G1dBQIodXUmikCIhNNdJnHXrNFig/BVwuSNeKv8/LOeQY0IGrebh1yEugqtC3p 3HLkBR4ng1uzJXHkCjHeZgh13SB/w7cWbY0EL5WgIXP74c1BB+0jQ33rsFeKPsIDot2G VBe4isoeUjdwQJcdaMabBMScVRS67FI3j51yY= 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=bol/EtSNZ1pGgBcscr2+UR5k7YT/e9qr896uQYhWbMo=; b=AjMaEOedNj6Z5cqXkOQvrFkH9qnw74RvWE+zFkx/T3CsCZ3DfYtP+eYSyBV3Qt/uhb xNmgMW2lcs5eXSxGIadsCDnYHKQLJD5B7C2J5P2Ugkc3GnAEka3XkzYH8RAG2AGNTWbo Hhe49d948G7ScqZmRxRUJujLwtrRAU66A3Ao2Of/hzcdt2LiXQG3liYErB9XDN42egVs Ced/Ma8emdosyDE3oEpppmlqtXiW1uBXISrjUcfdg7mDUNfK5EptwVEmdJ8eDXHcyD9o cAMP7eiG4iIel05raCg5bCDCwQ1VFoqhnLbcAWbQiy0P65oVbKVMh0a93nfWLxmB4lYP mY3g== X-Gm-Message-State: AA+aEWYxQY7+zO4rRMuyuJdl6BxlAsAW1x2M2IKZ27ao2AsmWlbTO+rO BbppGhW2jGZBQVVtKftKGsref0Iuyj4= X-Received: by 2002:a19:5059:: with SMTP id z25mr2159872lfj.120.1545422525884; Fri, 21 Dec 2018 12:02:05 -0800 (PST) Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com. [209.85.208.174]) by smtp.gmail.com with ESMTPSA id 15-v6sm5482576lje.18.2018.12.21.12.02.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 12:02:04 -0800 (PST) Received: by mail-lj1-f174.google.com with SMTP id q2-v6so5761922lji.10 for ; Fri, 21 Dec 2018 12:02:04 -0800 (PST) X-Received: by 2002:a2e:3e04:: with SMTP id l4-v6mr2347484lja.148.1545422524178; Fri, 21 Dec 2018 12:02:04 -0800 (PST) MIME-Version: 1.0 References: <20181221175618.968519903@goodmis.org> <20181221175659.208858193@goodmis.org> <20181221144054.20bdeb33@gandalf.local.home> In-Reply-To: <20181221144054.20bdeb33@gandalf.local.home> From: Linus Torvalds Date: Fri, 21 Dec 2018 12:01:48 -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 11:40 AM Steven Rostedt wrote: > > OK, what about if we just use strlen() and say that this macro is not > safe for parameters with side effects. I think gcc follows simple assignments just fine, and does the optimized strlen() for them too. So why not just do #define have_prefix(str,prefix) ({ \ const char *__pfx = prefix; \ size_t __pfxlen = strlen(__pfx); \ strncmp(str, __pfx, __pfxlen) ? 0 : __pfxlen); }) and be done with it safely? The above is ENTIRELY untested. Linus