Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1223920imj; Thu, 14 Feb 2019 03:14:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IZQNmnztIr3WGtfdtNt3k0IqeMX94S7RPOtiwfBTgLpjsoHLHMiOzcJJG5MCM5z6DUxqwKM X-Received: by 2002:a17:902:8d94:: with SMTP id v20mr3567119plo.194.1550142872617; Thu, 14 Feb 2019 03:14:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550142872; cv=none; d=google.com; s=arc-20160816; b=GllzmyUSgZUMKO7l3WzXUfTSH8qt4w4l6girfIdQIq9wNddjNreWoW36dqMynIgf0u wPjCw/y+YPr3o5WKXQFvYnvewWFhNq4f3rmfkSC0LigRY1s2h2cIdyosTJ6RNDJeLJGs BeAQgUK0JyHm01oSrsuTAyXcaGKzBlE6Q6waIXURiCSsGUNrl1hnf6U0Yf6bWxiLp6cA UFKNn0vLlCC3TsN5iIDgwS3Sg3I+ewKIzWcHdUnNzZKDSdiwN9T3c+xM/hpwMF0HhkjG uaO6SErDoEwcTWyFJCWv7n7ikJptYZG518u8oJkenhlXtUc8Te7rxABhzko/0NusTUXV ZYKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=obQgo3WVdga7QkxYHDWUZ23L/Zl/CdiYVduNTZIJDjQ=; b=q4N9spl8YeiZtc7I5VrmiJFTZ2cev4ieKmExi/fUOQt5ygAT3NytHPpGQymxiVXmY8 poiGb/JgeRaidy858qykAsZiMbxOvedWCwI8E0H/AdsmDEV4c9/w1Q0i7edlE99/t/F+ FajQA9+WfmbkRf5KtM1lHpw9cC3aMmMtkBlIDh8q4fnflcP6RTaHIyHK+ROwHx6ifP5H tNv+BEUbBgwvBYTpKF+U4sc9HxHZjDX8GjCjammaXjnBoo8s09yPeeAn4I0i5VmyxZfJ 5WpAjX/mJJ8YUaFt5qUgU9HCG3POmPFgSwAfEVrYBtPqiOqb6ITXpujdVUczJQ6OmsxF 4JPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="QIY6S/bO"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si451376pgb.276.2019.02.14.03.14.14; Thu, 14 Feb 2019 03:14:32 -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=@gmail.com header.s=20161025 header.b="QIY6S/bO"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395354AbfBNGDG (ORCPT + 99 others); Thu, 14 Feb 2019 01:03:06 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37518 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726407AbfBNGDE (ORCPT ); Thu, 14 Feb 2019 01:03:04 -0500 Received: by mail-pl1-f194.google.com with SMTP id b5so2567572plr.4; Wed, 13 Feb 2019 22:03:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=obQgo3WVdga7QkxYHDWUZ23L/Zl/CdiYVduNTZIJDjQ=; b=QIY6S/bOj/YRcpvPpdxz6y2ECrrDzKWVfcFZxtzr7zCS1IigKnLpO/bPVGsngx2wTa 0zb59mg76rUCiY6qtsibgvWtSEplAQrfrZq6xqWjVxYOYybd4sQPY3dUeu73vKQyR9fv TqK2BPrgpkus3Y6WWmhoflzMja0ElWWWpqCINQq60a5fHjBhTCavqU6ncOQBg1kigitV th1sBxqFf2NBybl8j43an3FhEyvjHGQ3V2yufcshyG6kyWPRrgL2B4lI9ZFjjN2RSiwY ab9XJKs6f5NWYrKVfOwPS+J/CaFlPIN3y8BQoYdBjiLOBQG8zV1o+oJqxmd2w/eoPLd9 410A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=obQgo3WVdga7QkxYHDWUZ23L/Zl/CdiYVduNTZIJDjQ=; b=ZZPHgISVv1LznVlusDMd5nLuWAdhgVvfI8yHLYZO4kGYtUNmzy/jmJCFUf128A23vh i1EVYt3gqEbDBNbmj1pWWfa8BNmejvoky6xRWFa0/xKulJnIWq+fQJk0Z2WGTCXLXp+s 32TZwQgKu8wz5sg6Z1yeZfNIcnYyPH+N3pqMW0HIJXqGa+eBbkmz2hbmB9FZy2NLMo4R dKiHVfvUk7mc9NpCn13lXCjbD0LxMW/76hmYlgoUIftJRh7q8BnZydZoU5MllvaXX1fT fiIiGx5MRR+JvWN0BiKUx/qWpIrr9Ax9Ztm+VKPxAb3AdLJYNQjCXyS63WsBnB/MXBe5 he1Q== X-Gm-Message-State: AHQUAub4vhu/63eQPQyywUlm8sMgooyYyAQWV+u8M/TDGimyEQuMgMqE HR/HTQosxXVA44YTmdB2+NQ= X-Received: by 2002:a17:902:264:: with SMTP id 91mr2431409plc.108.1550124183749; Wed, 13 Feb 2019 22:03:03 -0800 (PST) Received: from localhost.localdomain ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id c23sm1269211pgh.73.2019.02.13.22.03.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Feb 2019 22:03:03 -0800 (PST) From: Xiang Xiao X-Google-Original-From: Xiang Xiao To: rdunlap@infradead.org, gregkh@linuxfoundation.org, alexander.shishkin@linux.intel.com, andriy.shevchenko@linux.intel.com, ohad@wizery.com, bjorn.andersson@linaro.org, wendy.liang@xilinx.com, arnaud.pouliquen@st.com, kumar.gala@linaro.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Xiang Xiao Subject: [PATCH V2 1/2] lib/string: add memrchr function Date: Thu, 14 Feb 2019 14:02:37 +0800 Message-Id: <1550124158-1111-1-git-send-email-xiaoxiang@xiaomi.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Here is the detailed description for memrchr: void *memrchr(const void *s, int c, size_t n); The memrchr() function is like the memchr() function, except that it searches backward from the end of the n bytes pointed to by s instead of forward from the beginning. The memrchr() functions return a pointer to the matching byte or NULL if the character does not occur in the given memory area. Signed-off-by: Xiang Xiao --- include/linux/string.h | 3 +++ lib/string.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 7927b87..915c617 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -167,6 +167,9 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt) memcpy(dst, src, cnt); } #endif +#ifndef __HAVE_ARCH_MEMRCHR +void *memrchr(const void *s, int c, size_t n); +#endif void *memchr_inv(const void *s, int c, size_t n); char *strreplace(char *s, char old, char new); diff --git a/lib/string.c b/lib/string.c index 38e4ca0..595e0b3 100644 --- a/lib/string.c +++ b/lib/string.c @@ -964,6 +964,29 @@ void *memchr(const void *s, int c, size_t n) EXPORT_SYMBOL(memchr); #endif +#ifndef __HAVE_ARCH_MEMRCHR +/** + * memrchr - Find the last character in an area of memory. + * @s: The memory area + * @c: The byte to search for + * @n: The size of the area. + * + * Return: the address of the last occurrence of @c, or %NULL + * if @c is not found + */ +void *memrchr(const void *s, int c, size_t n) +{ + const unsigned char *p = s + n; + + while (n-- != 0) { + if ((unsigned char)c == *--p) + return (void *)p; + } + return NULL; +} +EXPORT_SYMBOL(memrchr); +#endif + static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) { while (bytes) { -- 2.7.4