Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp714564pxu; Thu, 26 Nov 2020 09:47:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4Bl9I4YXNp24zRZKK3cgKx27u/CkemExLhT/hpgVPBDuix/k0sVSgxigrERH3gTGWD1x7 X-Received: by 2002:a17:906:3daa:: with SMTP id y10mr3634451ejh.23.1606412825578; Thu, 26 Nov 2020 09:47:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606412825; cv=none; d=google.com; s=arc-20160816; b=lhckSwH2ipbpWs/d5YYUEIKK/5zTZ5ufL3Z4mCiGmtw2HoZg6IwSJq78+GwAm/OQLG /lwpQ8Z58IECKwsbkVYLgmuVR1ppNNd7ndZU8EtIY5XZiwe89Ssmd15VqPEuemVeFIoP lB81ud1J8Sp9wlogCA6kuJ1vUVQJzPSYRLcE9lbXfpiTG/ptqsY369n6Z0+4xLsuKC/+ giAxj0iwKcMrH38HB4gTVBbm1XSRc2xQehy8+TPppXWoU6hQpFN75I7G02n5rgOj2Zuv NKqj1uFdyMxcq1f3+jOAdj04OY8BwoJiabrMm8b4KkwCj2LA2Kq7bfs0qfuPHVj/Ym19 Z5uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jn6cCa/JGRHDPAWqH5SgzGUz7HDIJO0c4IPaSJuMFMQ=; b=VOTGuRq7ugnr0ZgWALli3MtVfeg0+oJ1WQhhFCAj3swIaCiO6ysuvvroHAYI52ASZ4 Zl/Dssx6p8lMifK8TUrZEs/D/CvTQtNuqeqzbVo9F1mJKlag5r6EFH7+bJZxCD9OeP9k KxpNCGfsUEkAqODriRWxzqeGwQlJaVuuooYyk2zmNshjzzYU+N7Zh5fMFRTXmR//cIjz MlG+1zmoLoDNKSwY1gI0I6C2xXloFnL/yi0LeWn0uqq61F15PUch4AAFpSzOky8B13wh wSS17VMaM+R+xejBbAnam0akEFRzjKaUDbFtjdSJvq6ykngsA4nmrew9B9noeM06t7NT Y+DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fevF4clo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq11si3552914edb.332.2020.11.26.09.46.43; Thu, 26 Nov 2020 09:47:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fevF4clo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2404479AbgKZRmq (ORCPT + 99 others); Thu, 26 Nov 2020 12:42:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:37478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404320AbgKZRmq (ORCPT ); Thu, 26 Nov 2020 12:42:46 -0500 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (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 A909C21D46; Thu, 26 Nov 2020 17:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606412565; bh=nIsooK7mtEnNl1AAP8xv2CcOZOILKknXcA1/3sN/yg0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fevF4clobE2Lo1+1eJC1nTYgmXG1meO0UjSUAJfT8870ZHlfUWHMTtwZHig3lwfKX Is5KDUZX7mi+3VG2KalaAky0f8qfl88WbMen8UEKeG0nN9jWrfolXTFaTeYUXvihAr oiDWQ/b5gYmtllIB0Qr7tz24vle3NPOk3cqyaNFQ= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 9DF1040E29; Thu, 26 Nov 2020 14:42:43 -0300 (-03) Date: Thu, 26 Nov 2020 14:42:43 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Song Liu , Ian Rogers , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: Re: [PATCH 05/25] tools lib: Adopt memchr_inv() from kernel Message-ID: <20201126174243.GH53384@kernel.org> References: <20201126170026.2619053-1-jolsa@kernel.org> <20201126170026.2619053-6-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201126170026.2619053-6-jolsa@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Thu, Nov 26, 2020 at 06:00:06PM +0100, Jiri Olsa escreveu: > We'll use it to check for undefined/zero data. Thanks, applied. - Arnaldo > Signed-off-by: Jiri Olsa > --- > tools/include/linux/string.h | 1 + > tools/lib/string.c | 58 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 59 insertions(+) > > diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h > index 5e9e781905ed..db5c99318c79 100644 > --- a/tools/include/linux/string.h > +++ b/tools/include/linux/string.h > @@ -46,4 +46,5 @@ extern char * __must_check skip_spaces(const char *); > > extern char *strim(char *); > > +extern void *memchr_inv(const void *start, int c, size_t bytes); > #endif /* _TOOLS_LINUX_STRING_H_ */ > diff --git a/tools/lib/string.c b/tools/lib/string.c > index f645343815de..8b6892f959ab 100644 > --- a/tools/lib/string.c > +++ b/tools/lib/string.c > @@ -168,3 +168,61 @@ char *strreplace(char *s, char old, char new) > *s = new; > return s; > } > + > +static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) > +{ > + while (bytes) { > + if (*start != value) > + return (void *)start; > + start++; > + bytes--; > + } > + return NULL; > +} > + > +/** > + * memchr_inv - Find an unmatching character in an area of memory. > + * @start: The memory area > + * @c: Find a character other than c > + * @bytes: The size of the area. > + * > + * returns the address of the first character other than @c, or %NULL > + * if the whole buffer contains just @c. > + */ > +void *memchr_inv(const void *start, int c, size_t bytes) > +{ > + u8 value = c; > + u64 value64; > + unsigned int words, prefix; > + > + if (bytes <= 16) > + return check_bytes8(start, value, bytes); > + > + value64 = value; > + value64 |= value64 << 8; > + value64 |= value64 << 16; > + value64 |= value64 << 32; > + > + prefix = (unsigned long)start % 8; > + if (prefix) { > + u8 *r; > + > + prefix = 8 - prefix; > + r = check_bytes8(start, value, prefix); > + if (r) > + return r; > + start += prefix; > + bytes -= prefix; > + } > + > + words = bytes / 8; > + > + while (words) { > + if (*(u64 *)start != value64) > + return check_bytes8(start, value, 8); > + start += 8; > + words--; > + } > + > + return check_bytes8(start, value, bytes % 8); > +} > -- > 2.26.2 > -- - Arnaldo