Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4122275imj; Tue, 12 Feb 2019 10:08:29 -0800 (PST) X-Google-Smtp-Source: AHgI3IZpxHbM5nmFCZo5Bx1RPB7c1yUSO6abh8hHly74gpjzIcnAvFl/jhO4VbnAsXWM6biIsQQC X-Received: by 2002:a62:4389:: with SMTP id l9mr5346683pfi.170.1549994909592; Tue, 12 Feb 2019 10:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549994909; cv=none; d=google.com; s=arc-20160816; b=HSAqTiDoPFILHH1IxfRMt+HodatxlvfdZDM6zZFnCJ75Sl4ZCCRi7UKXOzo5sd7nRk UBlfMxQkX/fPxBSjWdCmsOorWmu16KyF//6/ma9c5m6kGi7m9yDAd57sLvLZy2ACptoO 6r0cwOILWHSTvSN25R19ltp5EJVPxBEHiJsp43UsAHYz+uHh2PrFTT6rBQI1L8hqzjbo Agg1crXVMYJQu67racQrwAPD+HksPEEN0nYEErOQoCxMNDBzubS2BDzZssdCt9CKxssG tSvXvWFcFaSxtfLeds/tla/rhymW5JMp+nmmouiSEcfC7113CwIcHN4aOJzR/fUU5z2J aFDA== 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=Orczz7OzGsol9BSTi3enSHRqZox7M6jz44V37KHUss4=; b=fr4kPOg248JpHVicydqUR7gABjN+0/enWxx7HuPl2EEIoGVMnlhUFjZxRZ/kVmym7M uJTPw+1iBTL8j5oP63VQt76GjdE5j5N51KIVDrdtn64qylhuyahNzKD65QgECJ93NKdv dRuZ2aA7c6g+fu8o/w9RcU8qyuMDj1wNLilTcDWqYzJrjvpbGB3vogW664yDCy8/V06A J9AdhugOjJm3Rqf3lmKdV0DfhpxQTtv1AWIvbm8dK3ehSFdeihoA0ZtO2dZDdmmrgOGw VrU7iYqZ8HK6dZBmWJS03vptBorT/AZFTmfABpjOjJS+vagjFN4g7o7DJdD7FMOPIuMQ 8fnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nBIrEpUB; 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 s2si1286529plp.380.2019.02.12.10.08.12; Tue, 12 Feb 2019 10:08:29 -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=nBIrEpUB; 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 S1731533AbfBLSHU (ORCPT + 99 others); Tue, 12 Feb 2019 13:07:20 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42863 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727843AbfBLSHU (ORCPT ); Tue, 12 Feb 2019 13:07:20 -0500 Received: by mail-pg1-f196.google.com with SMTP id d72so1599592pga.9 for ; Tue, 12 Feb 2019 10:07:20 -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=Orczz7OzGsol9BSTi3enSHRqZox7M6jz44V37KHUss4=; b=nBIrEpUBqKJ6uy8d9GEQpKeHVfNWOuexJcGisSwO/2YBJBXA3AcIhQQ9yCVkiocJ6I 4DXxFIT4ILIHWFMsHBdprfM5uaRQs871OoIkIoxghQcnvONQ34Fm9nau0ExtxpmjKdfq ymozvuG2rlJmHIFBRPQ5n6xRZaBaI7qzyjMAnbs7qt6NPOXp8fR++L1+n6B1sJWx1gww Sm39qn+01E3mv6QiwBne+3IcoiF+opfB5u7J0mZyEcrO2zHTt4uGAmxNCu9DReBlPXNW +wrLCqqADis2txKVpCn45b/wznnJeaVpmuIBaHbLr0C4LiuLMfz9T5DHAI852g4YNQpJ fxbg== 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=Orczz7OzGsol9BSTi3enSHRqZox7M6jz44V37KHUss4=; b=YhLDti3TWaYrl+7mEkcQhXynmI4TthVfxh2KpNjhBN9mG4D0LkddUlD0OfALMhF0Ub xVDaKGLEaRuW0hXjCmE6NbV/Ka7ruGmfR4Qc5oPwg8/g6HPRG/POr5RdiJ1ANRvSfKM1 BfrYKvH449IEfctFKIsVfk2CxPDb5TVnZBGeObh0rxXoht9IYV7Y6xfHJ5lJlFfnV+RG WCjzFrBYg220/PDbaH5BdeD6hKtqVd3X0JSDqvK8OPkMyunBAyig5i5jCebcFNelfbPS TxOBSjatodhSTL4/t+x9YkZ6ZYeQal3+RteD7wwPm9J119AXS9yUtwP8bgABrDB5/9wG H9Gw== X-Gm-Message-State: AHQUAuYapS044bVjgJXdkb9r7vVtgLnZEx62Jg+f0omTD44yFd0htgAS 39ZVigoQqdkQZc+XEFT2L3o= X-Received: by 2002:a62:ca03:: with SMTP id n3mr5255803pfg.241.1549994839828; Tue, 12 Feb 2019 10:07:19 -0800 (PST) Received: from localhost.localdomain ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id u5sm16857510pgp.2.2019.02.12.10.07.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Feb 2019 10:07:19 -0800 (PST) From: Xiang Xiao X-Google-Original-From: Xiang Xiao To: gregkh@linuxfoundation.org, alexander.shishkin@linux.intel.com, andriy.shevchenko@linux.intel.com, linux-kernel@vger.kernel.org Cc: Xiang Xiao Subject: [PATCH] lib/string: add memrchr function Date: Wed, 13 Feb 2019 02:06:49 +0800 Message-Id: <1549994809-27479-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: https://linux.die.net/man/3/memrchr Signed-off-by: Xiang Xiao --- include/linux/string.h | 1 + lib/string.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 7927b87..f380f4b 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -167,6 +167,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt) memcpy(dst, src, cnt); } #endif +void *memrchr(const void *s, int c, size_t n); 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..92914f6 100644 --- a/lib/string.c +++ b/lib/string.c @@ -964,6 +964,27 @@ void *memchr(const void *s, int c, size_t n) EXPORT_SYMBOL(memchr); #endif +/** + * memrchr - Find a character in an area of memory. + * @s: The memory area + * @c: The byte to search for + * @n: The size of the area. + * + * returns 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); + static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) { while (bytes) { -- 2.7.4