Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1885228rwb; Fri, 19 Aug 2022 11:03:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Op532IOSPmKUWNj0qNQ7Gm+3pyzthd9J8ahrnsmNZp9bDSKzxoQVCqaFBb4O7Z5flYh7j X-Received: by 2002:a05:6402:5203:b0:43d:444b:9f99 with SMTP id s3-20020a056402520300b0043d444b9f99mr7101593edd.343.1660932201551; Fri, 19 Aug 2022 11:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660932201; cv=none; d=google.com; s=arc-20160816; b=JY59b1iHhmF5H8IP9qir9Kae3fysT4gp2H/SI1oQz7OeQK0vSWeOxVheXfG+nzw3sJ a73e52R78sOww7KkSg84gPx1Lb/MynWIHupZlaeWpB/nM7vmHDgvwmFUq1ak+odowJ2+ oMUgjbSexcFa/nVygxv5+Rw0jPfXOGT8Byv8QLzWzbaoDQ4XXd6ilIDv5U6OXZ2KPdcD RdWE7KncGCW2ucc/cdQJYAI9PS39/H0vpWqIwMCwNBwKKUfToVayrQLK789mJV1RZ1u1 uHitc7vWAk8MygVfPhgH1g9ktEM1U0HzVgZtt9uUW/Lfgyib29OQASyOKteOwD4AVQhm 1A6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mfmqUr+MgSWAGJPHgLqqd0ps0scXywIB811semo3qlw=; b=NIoNAxtSD48NUr7FH5UYlxnUzF9ejTtFaHlCGOAhIZIvgfALdXGpYYd7+YpWSkP00f L15RhBi8swVCyXofY7hvyBTxkikkqPkgbFuQT5fiOo4ZTkalspW+Y8PKXl/fKocejlah /Hg5FuKTR2YQb/+F4pfCXBw7cEQshF4Z8m89uXafSUpyVRi0/Qb7k3xq6qVCSK/unKRt ooD/6M8tqGAZ2KArNZK/pG1WW34h+UYVw95rNvW0ZG6nWF2ilqM59IIrPUbNrmq3gBxU YqyNNGVvNY2lMdegtMwygdJZP6E70r+NQlJ6C/jZKFJAauJ8IGuVPIQeq9Uj61lHQz7v mizw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EnwAt4Hp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020a17090639c300b007308bb40f8bsi2943323eje.198.2022.08.19.11.02.53; Fri, 19 Aug 2022 11:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EnwAt4Hp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351439AbiHSQST (ORCPT + 99 others); Fri, 19 Aug 2022 12:18:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351965AbiHSQO4 (ORCPT ); Fri, 19 Aug 2022 12:14:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 311C7474DC; Fri, 19 Aug 2022 08:58:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C9A82B82820; Fri, 19 Aug 2022 15:58:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F3A8C433C1; Fri, 19 Aug 2022 15:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924695; bh=sfylS1kA5G0Jiy4gD4HZ0v2qOmq0aop5WJVIEhgmkD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EnwAt4HpAyysPt4didGnBORopcSC4dGRDI9tNSzbQJlyx5dY0S1KjudOGVpi+6qZ2 ig+OqIH+gjZqy8nKZFZmtH/MFTon/h79+RVDKpxLd+hJb3uif9Ixtp5n+LYO6p115N Z+AKxT/ukftE07iu0CYe64Lti3EuKV7eIw9pMBZo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bartosz Golaszewski , Andy Shevchenko , Sasha Levin Subject: [PATCH 5.10 213/545] lib: bitmap: provide devm_bitmap_alloc() and devm_bitmap_zalloc() Date: Fri, 19 Aug 2022 17:39:43 +0200 Message-Id: <20220819153838.893582339@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski [ Upstream commit e829c2e4744850bab4d8f8ffebd00df10b4c6c2b ] Provide managed variants of bitmap_alloc() and bitmap_zalloc(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko Signed-off-by: Sasha Levin --- include/linux/bitmap.h | 8 ++++++++ lib/bitmap.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 4dd2e1d39c74..c4f6a9270c03 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -9,6 +9,8 @@ #include #include +struct device; + /* * bitmaps provide bit arrays that consume one or more unsigned * longs. The bitmap interface and available operations are listed @@ -122,6 +124,12 @@ extern unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags); extern unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags); extern void bitmap_free(const unsigned long *bitmap); +/* Managed variants of the above. */ +unsigned long *devm_bitmap_alloc(struct device *dev, + unsigned int nbits, gfp_t flags); +unsigned long *devm_bitmap_zalloc(struct device *dev, + unsigned int nbits, gfp_t flags); + /* * lib/bitmap.c provides these functions: */ diff --git a/lib/bitmap.c b/lib/bitmap.c index 78f70d9007ad..27e08c0e547e 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1263,6 +1264,38 @@ void bitmap_free(const unsigned long *bitmap) } EXPORT_SYMBOL(bitmap_free); +static void devm_bitmap_free(void *data) +{ + unsigned long *bitmap = data; + + bitmap_free(bitmap); +} + +unsigned long *devm_bitmap_alloc(struct device *dev, + unsigned int nbits, gfp_t flags) +{ + unsigned long *bitmap; + int ret; + + bitmap = bitmap_alloc(nbits, flags); + if (!bitmap) + return NULL; + + ret = devm_add_action_or_reset(dev, devm_bitmap_free, bitmap); + if (ret) + return NULL; + + return bitmap; +} +EXPORT_SYMBOL_GPL(devm_bitmap_alloc); + +unsigned long *devm_bitmap_zalloc(struct device *dev, + unsigned int nbits, gfp_t flags) +{ + return devm_bitmap_alloc(dev, nbits, flags | __GFP_ZERO); +} +EXPORT_SYMBOL_GPL(devm_bitmap_zalloc); + #if BITS_PER_LONG == 64 /** * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap -- 2.35.1