From patchwork Tue May 25 18:35:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 448466 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 362B1C2B9F8 for ; Tue, 25 May 2021 18:35:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B55D6140E for ; Tue, 25 May 2021 18:35:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231710AbhEYSgf (ORCPT ); Tue, 25 May 2021 14:36:35 -0400 Received: from mga17.intel.com ([192.55.52.151]:45532 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbhEYSge (ORCPT ); Tue, 25 May 2021 14:36:34 -0400 IronPort-SDR: uAyytL6uT87SnoTd/1yfkI9pk6pFirOz6p892GVBHR0n0ed2lpzSOXNRx674jnIylzu53kUWSe KjI3A+P3cgdA== X-IronPort-AV: E=McAfee;i="6200,9189,9995"; a="182593695" X-IronPort-AV: E=Sophos;i="5.82,329,1613462400"; d="scan'208";a="182593695" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 11:35:01 -0700 IronPort-SDR: fu1NKNP3vp3R3hg0ZSxFlfzeLTnadcB2gxFBoebJgiHQdZ7cFIBCCZu1Xvd+rZSzkW72sn4pvI EHnLGs3lU66Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,329,1613462400"; d="scan'208";a="614633850" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 25 May 2021 11:34:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0228F12A; Tue, 25 May 2021 21:35:21 +0300 (EEST) From: Andy Shevchenko To: Kent Gibson , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v1 1/2] gpiolib: Split fastpath array to two Date: Tue, 25 May 2021 21:35:17 +0300 Message-Id: <20210525183518.63149-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Split fastpath array to two, i.e. for mask and for bits. At the same time declare them as bitmaps. This makes code better to read and gives a clue about use of bitmap API. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 97a69362a584..79df075f8b82 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2540,21 +2540,24 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, while (i < array_size) { struct gpio_chip *gc = desc_array[i]->gdev->chip; - unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)]; + DECLARE_BITMAP(fastpath_mask, FASTPATH_NGPIO); + DECLARE_BITMAP(fastpath_bits, FASTPATH_NGPIO); unsigned long *mask, *bits; int first, j; if (likely(gc->ngpio <= FASTPATH_NGPIO)) { - mask = fastpath; + mask = fastpath_mask; + bits = fastpath_bits; } else { mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), sizeof(*mask), can_sleep ? GFP_KERNEL : GFP_ATOMIC); if (!mask) return -ENOMEM; + + bits = mask + BITS_TO_LONGS(gc->ngpio); } - bits = mask + BITS_TO_LONGS(gc->ngpio); bitmap_zero(mask, gc->ngpio); if (!can_sleep) @@ -2577,7 +2580,7 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, ret = gpio_chip_get_multiple(gc, mask, bits); if (ret) { - if (mask != fastpath) + if (mask != fastpath_mask) kfree(mask); return ret; } @@ -2598,7 +2601,7 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, j); } - if (mask != fastpath) + if (mask != fastpath_mask) kfree(mask); } return 0; @@ -2823,21 +2826,24 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, while (i < array_size) { struct gpio_chip *gc = desc_array[i]->gdev->chip; - unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)]; + DECLARE_BITMAP(fastpath_mask, FASTPATH_NGPIO); + DECLARE_BITMAP(fastpath_bits, FASTPATH_NGPIO); unsigned long *mask, *bits; int count = 0; if (likely(gc->ngpio <= FASTPATH_NGPIO)) { - mask = fastpath; + mask = fastpath_mask; + bits = fastpath_bits; } else { mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), sizeof(*mask), can_sleep ? GFP_KERNEL : GFP_ATOMIC); if (!mask) return -ENOMEM; + + bits = mask + BITS_TO_LONGS(gc->ngpio); } - bits = mask + BITS_TO_LONGS(gc->ngpio); bitmap_zero(mask, gc->ngpio); if (!can_sleep) @@ -2882,7 +2888,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, if (count != 0) gpio_chip_set_multiple(gc, mask, bits); - if (mask != fastpath) + if (mask != fastpath_mask) kfree(mask); } return 0; From patchwork Tue May 25 18:35:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 447564 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 9A3FBC2B9F8 for ; Tue, 25 May 2021 18:35:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79DBF6140F for ; Tue, 25 May 2021 18:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbhEYSgm (ORCPT ); Tue, 25 May 2021 14:36:42 -0400 Received: from mga07.intel.com ([134.134.136.100]:26774 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232433AbhEYSgl (ORCPT ); Tue, 25 May 2021 14:36:41 -0400 IronPort-SDR: s+ffbC42PK8Y4o90ABcYCxcsWhl7DNxofCm/CN7247+j2JhNTrOqRevk8J+sgXVnlNMQ7b3WMk yQEon5qwqFcg== X-IronPort-AV: E=McAfee;i="6200,9189,9995"; a="266162664" X-IronPort-AV: E=Sophos;i="5.82,329,1613462400"; d="scan'208";a="266162664" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 11:35:08 -0700 IronPort-SDR: XcMg12Hvc670rd8dWGhb41jqBHG3pIC5EtOyWbQO/YLOBaAa6LwIUexWJcSZGcLQzJhe8i7Kiw UshgQDByWsCA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,329,1613462400"; d="scan'208";a="479439802" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 25 May 2021 11:35:02 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 145104DB; Tue, 25 May 2021 21:35:23 +0300 (EEST) From: Andy Shevchenko To: Kent Gibson , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Subject: [PATCH v1 2/2] gpiolib: Switch to bitmap_alloc() Date: Tue, 25 May 2021 21:35:18 +0300 Message-Id: <20210525183518.63149-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210525183518.63149-1-andriy.shevchenko@linux.intel.com> References: <20210525183518.63149-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Switch to bitmap_alloc() to show clearly what we are allocating. Besides that it returns pointer of bitmap type instead of opaque void *. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 79df075f8b82..068f18624da0 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2549,13 +2549,17 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, mask = fastpath_mask; bits = fastpath_bits; } else { - mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), - sizeof(*mask), - can_sleep ? GFP_KERNEL : GFP_ATOMIC); + gfp_t flags = can_sleep ? GFP_KERNEL : GFP_ATOMIC; + + mask = bitmap_alloc(gc->ngpio, flags); if (!mask) return -ENOMEM; - bits = mask + BITS_TO_LONGS(gc->ngpio); + bits = bitmap_alloc(gc->ngpio, flags); + if (!bits) { + bitmap_free(mask); + return -ENOMEM; + } } bitmap_zero(mask, gc->ngpio); @@ -2581,7 +2585,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, ret = gpio_chip_get_multiple(gc, mask, bits); if (ret) { if (mask != fastpath_mask) - kfree(mask); + bitmap_free(mask); + if (bits != fastpath_bits) + bitmap_free(bits); return ret; } @@ -2602,7 +2608,9 @@ int gpiod_get_array_value_complex(bool raw, bool can_sleep, } if (mask != fastpath_mask) - kfree(mask); + bitmap_free(mask); + if (bits != fastpath_bits) + bitmap_free(bits); } return 0; } @@ -2835,13 +2843,17 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, mask = fastpath_mask; bits = fastpath_bits; } else { - mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), - sizeof(*mask), - can_sleep ? GFP_KERNEL : GFP_ATOMIC); + gfp_t flags = can_sleep ? GFP_KERNEL : GFP_ATOMIC; + + mask = bitmap_alloc(gc->ngpio, flags); if (!mask) return -ENOMEM; - bits = mask + BITS_TO_LONGS(gc->ngpio); + bits = bitmap_alloc(gc->ngpio, flags); + if (!bits) { + bitmap_free(mask); + return -ENOMEM; + } } bitmap_zero(mask, gc->ngpio); @@ -2889,7 +2901,9 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, gpio_chip_set_multiple(gc, mask, bits); if (mask != fastpath_mask) - kfree(mask); + bitmap_free(mask); + if (bits != fastpath_bits) + bitmap_free(bits); } return 0; }