From patchwork Sat Dec 26 06:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Syed Nayyar Waris X-Patchwork-Id: 352497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7B32C43381 for ; Sat, 26 Dec 2020 06:43:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D8A2221ED for ; Sat, 26 Dec 2020 06:43:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729106AbgLZGne (ORCPT ); Sat, 26 Dec 2020 01:43:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726775AbgLZGne (ORCPT ); Sat, 26 Dec 2020 01:43:34 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0704C061757; Fri, 25 Dec 2020 22:42:53 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id lb18so3322043pjb.5; Fri, 25 Dec 2020 22:42:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=a3tUiYozXBW5Qe16hKGeSkVlx2ZAlF5KcbW/IWUDcrE=; b=Y+jYyhZIrl33rTudnDWCeJuYlsr2ea2ErrO1LdMrwxZbvo1kJ6tr19nHCpksC7vzqg ZodJBBj+2G2mO0giDgagGXjSqSybkjRXfn0SRXdgmFQh5GuQg3OBCMuEexzaG6re+BGo 6bpTo93iEHogngUQfgNKV4eo/Wh4EkYR8x2U1Eel7YXhjhNzeHZq+mYO2NYPaP9UPj4x O36qEXpDnF9Yt+tyEZSofozNFnlcLH78eGz7iFU0eXCmd33XxIhQR/bQSOECX0AJyp/0 cDnU1gcm9RqrH8JBXv14W223I+tPw5ZscbVu5CPuJcVOJr9bsRaYWcfk16nJiCO4Bv4G iCmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=a3tUiYozXBW5Qe16hKGeSkVlx2ZAlF5KcbW/IWUDcrE=; b=qwgUmYsj8D1e3kmYlPnaJJ/Zp6cYqB6IzDU9fAkuQkTZAG477O6bwZ9919gdnmQTi8 5IDYK/ovwLr3nkNldSJ5X95sl2UxHWTmu9PpKgyTbcsIsHXw6BAE8zQ2ATEA4o//BLjQ GNqRY8tQXFnzxbV9s+ema5LI6pbFo9IoqBpY7ZBVIgPbVnK/deRsJCMLfZETowHLkHB+ G6wmlACKkK08TvUoDjglt+F6n94aT2FzTNi08yNlwSlG3re7q1CZ7nS0/c6RZ8EFURJk r36WIKsxIUHCGYRfi/XQkzQVXYs2Xg1dZaV12cCCO8UebBw21jDN6NZX6gv0sD0gesra uCyw== X-Gm-Message-State: AOAM531navUwFve00WGkR+t7TN6bXEHGsBckMYttf7U6TGEgdWg97nBJ Aqlepi1uacI91oZvqV1KI9Y= X-Google-Smtp-Source: ABdhPJyVNdjYpXWKUu1rWy5l1gkffrE01YUrVfTrURPZ8kZ2TJtOmHuTgrMkVMCYaA78yqj0vb/Pmg== X-Received: by 2002:a17:90a:a2a:: with SMTP id o39mr11396424pjo.161.1608964973609; Fri, 25 Dec 2020 22:42:53 -0800 (PST) Received: from syed.domain.name ([103.201.127.53]) by smtp.gmail.com with ESMTPSA id j23sm12420079pgj.34.2020.12.25.22.42.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Dec 2020 22:42:53 -0800 (PST) Date: Sat, 26 Dec 2020 12:12:37 +0530 From: Syed Nayyar Waris To: linus.walleij@linaro.org Cc: andriy.shevchenko@linux.intel.com, vilhelm.gray@gmail.com, michal.simek@xilinx.com, arnd@arndb.de, rrichter@marvell.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, yamada.masahiro@socionext.com, akpm@linux-foundation.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com, linux-arch@vger.kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH 1/5] clump_bits: Introduce the for_each_set_clump macro Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This macro iterates for each group of bits (clump) with set bits, within a bitmap memory region. For each iteration, "start" is set to the bit offset of the found clump, while the respective clump value is stored to the location pointed by "clump". Additionally, the bitmap_get_value() and bitmap_set_value() functions are introduced to respectively get and set a value of n-bits in a bitmap memory region. The n-bits can have any size from 1 to BITS_PER_LONG. size less than 1 or more than BITS_PER_LONG causes undefined behaviour. Moreover, during setting value of n-bit in bitmap, if a situation arise that the width of next n-bit is exceeding the word boundary, then it will divide itself such that some portion of it is stored in that word, while the remaining portion is stored in the next higher word. Similar situation occurs while retrieving the value from bitmap. GCC gives warning in bitmap_set_value(): https://godbolt.org/z/rjx34r Add explicit check to see if the value being written into the bitmap does not fall outside the bitmap. The situation that it is falling outside would never be possible in the code because the boundaries are required to be correct before the function is called. The responsibility is on the caller for ensuring the boundaries are correct. The code change is simply to silence the GCC warning messages because GCC is not aware that the boundaries have already been checked. As such, we're better off using __builtin_unreachable() here because we can avoid the latency of the conditional check entirely. Cc: Linus Walleij Cc: Arnd Bergmann Cc: William Breathitt Gray Cc: Andy Shevchenko Signed-off-by: Syed Nayyar Waris --- drivers/gpio/clump_bits.h | 101 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 drivers/gpio/clump_bits.h diff --git a/drivers/gpio/clump_bits.h b/drivers/gpio/clump_bits.h new file mode 100644 index 000000000000..72ef772b83c8 --- /dev/null +++ b/drivers/gpio/clump_bits.h @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __CLUMP_BITS_H +#define __CLUMP_BITS_H + +/** + * find_next_clump - find next clump with set bits in a memory region + * @clump: location to store copy of found clump + * @addr: address to base the search on + * @size: bitmap size in number of bits + * @offset: bit offset at which to start searching + * @clump_size: clump size in bits + * + * Returns the bit offset for the next set clump; the found clump value is + * copied to the location pointed by @clump. If no bits are set, returns @size. + */ +extern unsigned long find_next_clump(unsigned long *clump, + const unsigned long *addr, + unsigned long size, unsigned long offset, + unsigned long clump_size); + +#define find_first_clump(clump, bits, size, clump_size) \ + find_next_clump((clump), (bits), (size), 0, (clump_size)) + +/** + * bitmap_get_value - get a value of n-bits from the memory region + * @map: address to the bitmap memory region + * @start: bit offset of the n-bit value + * @nbits: size of value in bits (must be between 1 and BITS_PER_LONG inclusive). + * + * Returns value of nbits located at the @start bit offset within the @map + * memory region. + */ +static inline unsigned long bitmap_get_value(const unsigned long *map, + unsigned long start, + unsigned long nbits) +{ + const size_t index = BIT_WORD(start); + const unsigned long offset = start % BITS_PER_LONG; + const unsigned long ceiling = round_up(start + 1, BITS_PER_LONG); + const unsigned long space = ceiling - start; + unsigned long value_low, value_high; + + if (space >= nbits) + return (map[index] >> offset) & GENMASK(nbits - 1, 0); + else { + value_low = map[index] & BITMAP_FIRST_WORD_MASK(start); + value_high = map[index + 1] & BITMAP_LAST_WORD_MASK(start + nbits); + return (value_low >> offset) | (value_high << space); + } +} + +/** + * bitmap_set_value - set value within a memory region + * @map: address to the bitmap memory region + * @nbits: size of map in bits + * @value: value of clump + * @value_width: size of value in bits (must be between 1 and BITS_PER_LONG inclusive) + * @start: bit offset of the value + */ +static inline void bitmap_set_value(unsigned long *map, unsigned long nbits, + unsigned long value, unsigned long value_width, + unsigned long start) +{ + const unsigned long index = BIT_WORD(start); + const unsigned long length = BIT_WORD(nbits); + const unsigned long offset = start % BITS_PER_LONG; + const unsigned long ceiling = round_up(start + 1, BITS_PER_LONG); + const unsigned long space = ceiling - start; + + value &= GENMASK(value_width - 1, 0); + + if (space >= value_width) { + map[index] &= ~(GENMASK(value_width - 1, 0) << offset); + map[index] |= value << offset; + } else { + map[index + 0] &= ~BITMAP_FIRST_WORD_MASK(start); + map[index + 0] |= value << offset; + + if (index + 1 >= length) + __builtin_unreachable(); + + map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + value_width); + map[index + 1] |= value >> space; + } +} + +/** + * for_each_set_clump - iterate over bitmap for each clump with set bits + * @start: bit offset to start search and to store the current iteration offset + * @clump: location to store copy of current 8-bit clump + * @bits: bitmap address to base the search on + * @size: bitmap size in number of bits + * @clump_size: clump size in bits + */ +#define for_each_set_clump(start, clump, bits, size, clump_size) \ + for ((start) = find_first_clump(&(clump), (bits), (size), (clump_size)); \ + (start) < (size); \ + (start) = find_next_clump(&(clump), (bits), (size), (start) + (clump_size), (clump_size))) + +#endif /* __CLUMP_BITS_H */ From patchwork Sat Dec 26 06:43:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Syed Nayyar Waris X-Patchwork-Id: 352496 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3366C433E0 for ; Sat, 26 Dec 2020 06:44:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B82F8221E9 for ; Sat, 26 Dec 2020 06:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728932AbgLZGo5 (ORCPT ); Sat, 26 Dec 2020 01:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgLZGo5 (ORCPT ); Sat, 26 Dec 2020 01:44:57 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9ECCC061757; Fri, 25 Dec 2020 22:44:16 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id f14so3324967pju.4; Fri, 25 Dec 2020 22:44:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=iXNqUNlDxA192iSDhXK8T34CWCe+lAvUgPxne7auzLU=; b=X3VqkGTtPHgY1bRWcNfIIEzEkd4CnRBVwL6y4V5NGTcXyshWxpSPWcwaHQU8OKHq6B yBpnK5X5s/GS0m91eQwyqhsBGtP3KFY5xpHkasoNxDOsGuajYXohFFWto5HX2wHOfyz6 W8YvxplDXEFPL3eb5vXxsoD7GZ8hUqYo7ClG/2qpwlTFEzayzUR9sNvZlyckR2Z2S59r 7FQO44kuK+Y/v/K0F6Rqei6vBf+rVPeMM3rCOUzxlS5eHYGQ/lVOcrm4y32oxnzB9D3H UmtXExLbDEPjcAVKVEGRSYCfj3yJwOkw/ODwlHCoEcawrRfmC3TUQIl2D6kI8gU4kCba sLIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=iXNqUNlDxA192iSDhXK8T34CWCe+lAvUgPxne7auzLU=; b=rIMeG6kcMrJJV37Tf2Ex1iEMgGbwKQhDeFW/8QNgkqbHf6x/vu8/8sbDnZNEzgZC85 vLQXt0bEwcvMBpDacQI9vA5rJzTYpxwmpv6+Lb/uZSC2L2JIkhWIZw6h523vis+P+31c 87Oh44+IhmAeNT6hPCeDt6MyXYcZHXXAuMgGwu5ct+WMyCpC/r+O+1d3JcAqdpulELOx zY65+YcE3uxqx3QbnZ+1VmHb5226jg9AvYFcFeGBCv3bCtJJJ9l0nwJ42A5U3PPX2SSt c2oAssOZxxsaFKlY6RI+T2UqpsYh2S2v1by97UzINFZ+PjT/S5jhsYi7z+hdeG5RxFbn feeQ== X-Gm-Message-State: AOAM532qlsvo2i5pkUt9snj09/0+WEO+CXHCzzZ1UcCfyYnD8xiEdn3Y vkvL9jVq9cIzYh+ty1VUQys= X-Google-Smtp-Source: ABdhPJziO6I42bYuv8uPNtCMThaNM13m0w03d0WDcSIMvWOVwMMh5b8LH0b40IFyd3zK8pLldMrW0w== X-Received: by 2002:a17:90b:128a:: with SMTP id fw10mr11311388pjb.113.1608965056485; Fri, 25 Dec 2020 22:44:16 -0800 (PST) Received: from syed.domain.name ([103.201.127.53]) by smtp.gmail.com with ESMTPSA id r185sm30254706pfc.53.2020.12.25.22.44.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Dec 2020 22:44:16 -0800 (PST) Date: Sat, 26 Dec 2020 12:13:58 +0530 From: Syed Nayyar Waris To: linus.walleij@linaro.org Cc: andriy.shevchenko@linux.intel.com, vilhelm.gray@gmail.com, michal.simek@xilinx.com, arnd@arndb.de, rrichter@marvell.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, yamada.masahiro@socionext.com, akpm@linux-foundation.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com, linux-arch@vger.kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH 3/5] gpio: thunderx: Utilize for_each_set_clump macro Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This patch reimplements the thunderx_gpio_set_multiple function in drivers/gpio/gpio-thunderx.c to use the new for_each_set_clump macro. Instead of looping for each bank in thunderx_gpio_set_multiple function, now we can skip bank which is not set and save cycles. Cc: William Breathitt Gray Cc: Robert Richter Cc: Bartosz Golaszewski Signed-off-by: Syed Nayyar Waris --- drivers/gpio/gpio-thunderx.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c index 9f66deab46ea..716b75ba7df6 100644 --- a/drivers/gpio/gpio-thunderx.c +++ b/drivers/gpio/gpio-thunderx.c @@ -16,6 +16,7 @@ #include #include #include +#include <../drivers/gpio/clump_bits.h> #define GPIO_RX_DAT 0x0 @@ -275,12 +276,15 @@ static void thunderx_gpio_set_multiple(struct gpio_chip *chip, unsigned long *bits) { int bank; - u64 set_bits, clear_bits; + unsigned long set_bits, clear_bits, gpio_mask; + unsigned long offset; + struct thunderx_gpio *txgpio = gpiochip_get_data(chip); - for (bank = 0; bank <= chip->ngpio / 64; bank++) { - set_bits = bits[bank] & mask[bank]; - clear_bits = ~bits[bank] & mask[bank]; + for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, 64) { + bank = offset / 64; + set_bits = bits[bank] & gpio_mask; + clear_bits = ~bits[bank] & gpio_mask; writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET); writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR); } From patchwork Sat Dec 26 06:45:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Syed Nayyar Waris X-Patchwork-Id: 352495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10BCCC433DB for ; Sat, 26 Dec 2020 06:46:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1890221E9 for ; Sat, 26 Dec 2020 06:46:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726345AbgLZGqR (ORCPT ); Sat, 26 Dec 2020 01:46:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725998AbgLZGqR (ORCPT ); Sat, 26 Dec 2020 01:46:17 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAB80C0613C1; Fri, 25 Dec 2020 22:45:36 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id s21so3466632pfu.13; Fri, 25 Dec 2020 22:45:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=vnMHu5Qy0Jg58UtwP7Ds62Ap6snjXtPHHHu3PtC/XEo=; b=dlG38EeVZacFRmy6FQi7N0YYOYZ+6eAIjVXaWVZVoDb/X30UBODrFuDWaVxw513N8K xUDYQ9fPv2JiKVd2HvG0xPmmk6KiJkc/JLQbw/A4lV3uMc2DGf3BBqUxQm/GTD21rp0f jB3aM8+L0oUzFSmMGmw+x+dc4KwRPkv6ut5pScK989Usi2C65croYz/sMmZrlLINUaS/ KjVTKVqhmd7HfIw098Fjn1Txo6kNLA8AQ83MALlX7V9ug7pk279QAuQnBUJ4NqK5laDQ 77RwdH5b906TtQcQ7PyDn12ZgVu3GjU85rdDRDyjwOElwUX7IccZKgSnV6S61fB0+SGm lJ1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=vnMHu5Qy0Jg58UtwP7Ds62Ap6snjXtPHHHu3PtC/XEo=; b=QnRNIlA270Kaj/4nVOR3KBtkxYIL0iSqYTaq3ZAYfjm66tFmuihtc9GnkXUiLads0/ D9Sl7RH+cu0GDl516+KZFwFd0WMMO6N/KIyrigrJCkou0ABVAtuna9AF7OiceRleDuVM sZ3NI2N3NTo1cH1IxvMGaf5VFPPZa5puYPrxPHpV1v38DT3M0dV7Mrd7TniN6Lf/GEbF I5rY1HD6kFHfo85eumjWWfAGjwpSLeN7OxzuGLecj+Rv+UIXTubOBMfCnAJjh8YnMi8K OEy6W3JgJOxM9nHR3QRbErNFnzbFgJNiEeamzlDBv51C2vovFYOlnEAU++5JZe4fJTMk 2p9g== X-Gm-Message-State: AOAM533p8qXUgQLWoBc6EqQrVJyoqEs40PNziYk24uSiZ5be0rZc62oT 1J84BYw46xswGtS9pVKyk3E= X-Google-Smtp-Source: ABdhPJws3YsPWlyumseJrN1/+szleyhO7fW1OuHDB/pTEgqDVu+reDMNMWH3EsSevnPoXVaiAEw6uw== X-Received: by 2002:a63:cf56:: with SMTP id b22mr35606537pgj.16.1608965136522; Fri, 25 Dec 2020 22:45:36 -0800 (PST) Received: from syed.domain.name ([103.201.127.53]) by smtp.gmail.com with ESMTPSA id cq15sm6935227pjb.27.2020.12.25.22.45.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Dec 2020 22:45:36 -0800 (PST) Date: Sat, 26 Dec 2020 12:15:20 +0530 From: Syed Nayyar Waris To: linus.walleij@linaro.org Cc: andriy.shevchenko@linux.intel.com, vilhelm.gray@gmail.com, michal.simek@xilinx.com, arnd@arndb.de, rrichter@marvell.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, yamada.masahiro@socionext.com, akpm@linux-foundation.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com, linux-arch@vger.kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH 5/5] gpio: xilinx: Add extra check if sum of widths exceed 64 Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add extra check to see if sum of widths does not exceed 64. If it exceeds then return -EINVAL alongwith appropriate error message. Cc: Michal Simek Signed-off-by: Syed Nayyar Waris Acked-by: Michal Simek --- drivers/gpio/gpio-xilinx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index d565fbf128b7..c9d740ac711b 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -319,6 +319,12 @@ static int xgpio_probe(struct platform_device *pdev) chip->gc.base = -1; chip->gc.ngpio = chip->gpio_width[0] + chip->gpio_width[1]; + + if (chip->gc.ngpio > 64) { + dev_err(&pdev->dev, "invalid configuration: number of GPIO is greater than 64"); + return -EINVAL; + } + chip->gc.parent = &pdev->dev; chip->gc.direction_input = xgpio_dir_in; chip->gc.direction_output = xgpio_dir_out;