From patchwork Thu Sep 20 11:28:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Coelho X-Patchwork-Id: 10607519 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 884D5157B for ; Thu, 20 Sep 2018 11:28:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 772B92D09B for ; Thu, 20 Sep 2018 11:28:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BBB62D0A8; Thu, 20 Sep 2018 11:28:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B30B2D09B for ; Thu, 20 Sep 2018 11:28:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731343AbeITRLx (ORCPT ); Thu, 20 Sep 2018 13:11:53 -0400 Received: from paleale.coelho.fi ([176.9.41.70]:50960 "EHLO farmhouse.coelho.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727029AbeITRLx (ORCPT ); Thu, 20 Sep 2018 13:11:53 -0400 Received: from 91-156-4-241.elisa-laajakaista.fi ([91.156.4.241] helo=redipa.ger.corp.intel.com) by farmhouse.coelho.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.91) (envelope-from ) id 1g2x8b-0004SQ-TS; Thu, 20 Sep 2018 14:28:50 +0300 From: Luca Coelho To: backports@vger.kernel.org Cc: Luca Coelho Date: Thu, 20 Sep 2018 14:28:31 +0300 Message-Id: <20180920112842.27198-4-luca@coelho.fi> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180920112842.27198-1-luca@coelho.fi> References: <20180920112842.27198-1-luca@coelho.fi> Subject: [PATCH 03/14] backport: introduce match_string() for kernels < 4.6 Sender: backports-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: backports@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Luca Coelho This function was introduced in v4.6 and now the iwlwifi driver uses it. Add the function for kernels older than v4.6. Signed-off-by: Luca Coelho --- backport/backport-include/linux/string.h | 4 ++++ backport/compat/backport-4.6.c | 26 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/backport/backport-include/linux/string.h b/backport/backport-include/linux/string.h index b85d9c73dc27..df93bf79a691 100644 --- a/backport/backport-include/linux/string.h +++ b/backport/backport-include/linux/string.h @@ -29,4 +29,8 @@ void memzero_explicit(void *s, size_t count); ssize_t strscpy(char *dest, const char *src, size_t count); #endif +#if LINUX_VERSION_IS_LESS(4,6,0) +int match_string(const char * const *array, size_t n, const char *string); +#endif /* LINUX_VERSION_IS_LESS(4,5,0) */ + #endif /* __BACKPORT_LINUX_STRING_H */ diff --git a/backport/compat/backport-4.6.c b/backport/compat/backport-4.6.c index 54ff669df192..8d0ecf56526d 100644 --- a/backport/compat/backport-4.6.c +++ b/backport/compat/backport-4.6.c @@ -75,3 +75,29 @@ int kstrtobool_from_user(const char __user *s, size_t count, bool *res) return kstrtobool(buf, res); } EXPORT_SYMBOL_GPL(kstrtobool_from_user); + +/** + * match_string - matches given string in an array + * @array: array of strings + * @n: number of strings in the array or -1 for NULL terminated arrays + * @string: string to match with + * + * Return: + * index of a @string in the @array if matches, or %-EINVAL otherwise. + */ +int match_string(const char * const *array, size_t n, const char *string) +{ + int index; + const char *item; + + for (index = 0; index < n; index++) { + item = array[index]; + if (!item) + break; + if (!strcmp(item, string)) + return index; + } + + return -EINVAL; +} +EXPORT_SYMBOL(match_string);