From mboxrd@z Thu Jan 1 00:00:00 1970 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,DKIM_SIGNED, DKIM_VALID,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 D6D4EC433F5 for ; Thu, 23 Sep 2021 16:54:06 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A2ED61211 for ; Thu, 23 Sep 2021 16:54:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5A2ED61211 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 430258340C; Thu, 23 Sep 2021 18:53:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="2lvuLqVN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4F176833CF; Thu, 23 Sep 2021 18:47:40 +0200 (CEST) Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B5C00833E6 for ; Thu, 23 Sep 2021 18:47:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=aouledameur@baylibre.com Received: by mail-ej1-x62d.google.com with SMTP id ho42so510194ejc.9 for ; Thu, 23 Sep 2021 09:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HauJz7+4pmxfm5xm1lvtI2a+868f4vCFj5BP4qULvnU=; b=2lvuLqVND7JGtpa/QbVE7+yVBQhlFVtcoG45BZPhTWS9A3+PMj2MlJEpXrT00QlLbM KCdprVen0vOOVLSQjnUgaCxmfavmx56zyncRcTbZjgwQpJT6DCjH/Zfe7RswPjoxrKjG OvkrjMwm4937omI+WR+vdooPSNTv0vtsELpg+MFrbLG1DviqTGYUhcpHAbcCoDFTVTo4 C2s0J4umDB6ZC/hv8Gs+v7OD+s+lJH/ON2LMJV3BmiMyYo7jbN9ZIuooBmQv1m/zladt nKlf2duA2j4CwtYCsQXE6/MoB/z41TOcmNbhcU6K3NczFAoUoZbKWKGAQ1i9eGjlztXR V5XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HauJz7+4pmxfm5xm1lvtI2a+868f4vCFj5BP4qULvnU=; b=y65MfvX8+op0yYMmYMc8ArERycObiaAQik1c+8GPDUcijNLWJv+11Nt5gNh/8/lL+4 6Lyn+p5VcRfCnuySZwU8n8EAkXJvLu153ruDulGJB6aqDao9sg/AlvQ3oJsampj3gmvy mxqxsbVaj6KuHzF/lIvANwU2b7g+VkG8gh6xIf9vR4GzyodlJaSkY4bjtG5kY5Usa7la WnwLvcg2ZJqj4Hm+dx9WOO7/HOL5Mnbj+8Hy9aNwqhui0PA8jdjhIS9m/YNiRtfC2vZH H1BewHzIVtBdL42W8sdwKYYZ/GFF3P3C3ppFO6jtx8ChdK3N4/pV0SegI8MXgvaCKOTD TNng== X-Gm-Message-State: AOAM530k//M48kzN7iTyLwGd/jdffFoCxksC79HnoiY8hdeDejNBwM3C rE82/97itb11qyUVPlBeNx3HCkiglPJsRA== X-Google-Smtp-Source: ABdhPJz52Py1HsDe+yXruAZbvdSsZQMmwXVx7eIIoa77si36v7pWbKgZME+3MeaF4IBAhi/Fz4pAQQ== X-Received: by 2002:a17:906:27cf:: with SMTP id k15mr6334978ejc.123.1632415654344; Thu, 23 Sep 2021 09:47:34 -0700 (PDT) Received: from localhost.localdomain (203.247.120.78.rev.sfr.net. [78.120.247.203]) by smtp.googlemail.com with ESMTPSA id u4sm3323277ejc.19.2021.09.23.09.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 09:47:33 -0700 (PDT) From: Amjad Ouled-Ameur To: u-boot@lists.denx.de Cc: Keerthy , Amjad Ouled-Ameur Subject: [PATCH 04/10] linux: bitmap.h: Add find_next_zero_area function Date: Thu, 23 Sep 2021 18:46:43 +0200 Message-Id: <20210923164649.214770-5-aouledameur@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210923164649.214770-1-aouledameur@baylibre.com> References: <20210923164649.214770-1-aouledameur@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 23 Sep 2021 18:53:13 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Keerthy Add find_next_zero_area to fetch the next zero area in the map. Signed-off-by: Keerthy Signed-off-by: Amjad Ouled-Ameur --- include/linux/bitmap.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index dae4225be549..0a8503af9f14 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -159,6 +159,32 @@ static inline unsigned long find_first_bit(const unsigned long *addr, unsigned l (bit) < (size); \ (bit) = find_next_bit((addr), (size), (bit) + 1)) +static inline unsigned long +bitmap_find_next_zero_area(unsigned long *map, + unsigned long size, + unsigned long start, + unsigned int nr, unsigned long align_mask) +{ + unsigned long index, end, i; +again: + index = find_next_zero_bit(map, size, start); + + /* + * Align allocation + */ + index = (index + align_mask) & ~align_mask; + + end = index + nr; + if (end > size) + return end; + i = find_next_bit(map, end, index); + if (i < end) { + start = i + 1; + goto again; + } + return index; +} + static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) { if (small_const_nbits(nbits)) { -- 2.25.1