diff options
author | Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> | 2015-09-04 18:47:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-04 19:54:41 -0400 |
commit | 73858173593c31cb94bce63fe1c24eb803bb04e6 (patch) | |
tree | d9843d5b2c3ec648501ae18821f52d78fe87aadf | |
parent | c0a294988322a804901fe24222027fe8a34defcb (diff) |
genalloc: add name arg to gen_pool_get() and devm_gen_pool_create()
This change modifies gen_pool_get() and devm_gen_pool_create() client
interfaces adding one more argument "name" of a gen_pool object.
Due to implementation gen_pool_get() is capable to retrieve only one
gen_pool associated with a device even if multiple gen_pools are created,
fortunately right at the moment it is sufficient for the clients, hence
provide NULL as a valid argument on both producer devm_gen_pool_create()
and consumer gen_pool_get() sides.
Because only one created gen_pool per device is addressable, explicitly
add a restriction to devm_gen_pool_create() to create only one gen_pool
per device, this implies two possible error codes returned by the
function, account it on client side (only misc/sram). This completes
client side changes related to genalloc updates.
[akpm@linux-foundation.org: gen_pool_get() cleanup]
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <kernel@pengutronix.de>
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/arm/mach-at91/pm.c | 2 | ||||
-rw-r--r-- | arch/arm/mach-imx/pm-imx5.c | 2 | ||||
-rw-r--r-- | arch/arm/mach-imx/pm-imx6.c | 2 | ||||
-rw-r--r-- | arch/arm/mach-socfpga/pm.c | 2 | ||||
-rw-r--r-- | drivers/media/platform/coda/coda-common.c | 2 | ||||
-rw-r--r-- | drivers/misc/sram.c | 8 | ||||
-rw-r--r-- | include/linux/genalloc.h | 4 | ||||
-rw-r--r-- | lib/genalloc.c | 49 |
8 files changed, 39 insertions, 32 deletions
diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c index 265ffeb2037e..80e277cfcc8b 100644 --- a/arch/arm/mach-at91/pm.c +++ b/arch/arm/mach-at91/pm.c | |||
@@ -369,7 +369,7 @@ static void __init at91_pm_sram_init(void) | |||
369 | return; | 369 | return; |
370 | } | 370 | } |
371 | 371 | ||
372 | sram_pool = gen_pool_get(&pdev->dev); | 372 | sram_pool = gen_pool_get(&pdev->dev, NULL); |
373 | if (!sram_pool) { | 373 | if (!sram_pool) { |
374 | pr_warn("%s: sram pool unavailable!\n", __func__); | 374 | pr_warn("%s: sram pool unavailable!\n", __func__); |
375 | return; | 375 | return; |
diff --git a/arch/arm/mach-imx/pm-imx5.c b/arch/arm/mach-imx/pm-imx5.c index 1885676c23c0..532d4b08276d 100644 --- a/arch/arm/mach-imx/pm-imx5.c +++ b/arch/arm/mach-imx/pm-imx5.c | |||
@@ -297,7 +297,7 @@ static int __init imx_suspend_alloc_ocram( | |||
297 | goto put_node; | 297 | goto put_node; |
298 | } | 298 | } |
299 | 299 | ||
300 | ocram_pool = gen_pool_get(&pdev->dev); | 300 | ocram_pool = gen_pool_get(&pdev->dev, NULL); |
301 | if (!ocram_pool) { | 301 | if (!ocram_pool) { |
302 | pr_warn("%s: ocram pool unavailable!\n", __func__); | 302 | pr_warn("%s: ocram pool unavailable!\n", __func__); |
303 | ret = -ENODEV; | 303 | ret = -ENODEV; |
diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c index 93ecf559d06d..8ff8fc0b261c 100644 --- a/arch/arm/mach-imx/pm-imx6.c +++ b/arch/arm/mach-imx/pm-imx6.c | |||
@@ -451,7 +451,7 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata) | |||
451 | goto put_node; | 451 | goto put_node; |
452 | } | 452 | } |
453 | 453 | ||
454 | ocram_pool = gen_pool_get(&pdev->dev); | 454 | ocram_pool = gen_pool_get(&pdev->dev, NULL); |
455 | if (!ocram_pool) { | 455 | if (!ocram_pool) { |
456 | pr_warn("%s: ocram pool unavailable!\n", __func__); | 456 | pr_warn("%s: ocram pool unavailable!\n", __func__); |
457 | ret = -ENODEV; | 457 | ret = -ENODEV; |
diff --git a/arch/arm/mach-socfpga/pm.c b/arch/arm/mach-socfpga/pm.c index 6a4199f2bffb..c378ab0c2431 100644 --- a/arch/arm/mach-socfpga/pm.c +++ b/arch/arm/mach-socfpga/pm.c | |||
@@ -56,7 +56,7 @@ static int socfpga_setup_ocram_self_refresh(void) | |||
56 | goto put_node; | 56 | goto put_node; |
57 | } | 57 | } |
58 | 58 | ||
59 | ocram_pool = gen_pool_get(&pdev->dev); | 59 | ocram_pool = gen_pool_get(&pdev->dev, NULL); |
60 | if (!ocram_pool) { | 60 | if (!ocram_pool) { |
61 | pr_warn("%s: ocram pool unavailable!\n", __func__); | 61 | pr_warn("%s: ocram pool unavailable!\n", __func__); |
62 | ret = -ENODEV; | 62 | ret = -ENODEV; |
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c index 58f65486de33..284ac4c934ba 100644 --- a/drivers/media/platform/coda/coda-common.c +++ b/drivers/media/platform/coda/coda-common.c | |||
@@ -2157,7 +2157,7 @@ static int coda_probe(struct platform_device *pdev) | |||
2157 | /* Get IRAM pool from device tree or platform data */ | 2157 | /* Get IRAM pool from device tree or platform data */ |
2158 | pool = of_gen_pool_get(np, "iram", 0); | 2158 | pool = of_gen_pool_get(np, "iram", 0); |
2159 | if (!pool && pdata) | 2159 | if (!pool && pdata) |
2160 | pool = gen_pool_get(pdata->iram_dev); | 2160 | pool = gen_pool_get(pdata->iram_dev, NULL); |
2161 | if (!pool) { | 2161 | if (!pool) { |
2162 | dev_err(&pdev->dev, "iram pool not available\n"); | 2162 | dev_err(&pdev->dev, "iram pool not available\n"); |
2163 | return -ENOMEM; | 2163 | return -ENOMEM; |
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index 15c33cc34a80..431e1dd528bc 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c | |||
@@ -186,10 +186,10 @@ static int sram_probe(struct platform_device *pdev) | |||
186 | if (IS_ERR(sram->virt_base)) | 186 | if (IS_ERR(sram->virt_base)) |
187 | return PTR_ERR(sram->virt_base); | 187 | return PTR_ERR(sram->virt_base); |
188 | 188 | ||
189 | sram->pool = devm_gen_pool_create(sram->dev, | 189 | sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), |
190 | ilog2(SRAM_GRANULARITY), -1); | 190 | NUMA_NO_NODE, NULL); |
191 | if (!sram->pool) | 191 | if (IS_ERR(sram->pool)) |
192 | return -ENOMEM; | 192 | return PTR_ERR(sram->pool); |
193 | 193 | ||
194 | ret = sram_reserve_regions(sram, res); | 194 | ret = sram_reserve_regions(sram, res); |
195 | if (ret) | 195 | if (ret) |
diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h index 5383bb1394a1..6afa65e6cdb7 100644 --- a/include/linux/genalloc.h +++ b/include/linux/genalloc.h | |||
@@ -118,8 +118,8 @@ extern unsigned long gen_pool_best_fit(unsigned long *map, unsigned long size, | |||
118 | unsigned long start, unsigned int nr, void *data); | 118 | unsigned long start, unsigned int nr, void *data); |
119 | 119 | ||
120 | extern struct gen_pool *devm_gen_pool_create(struct device *dev, | 120 | extern struct gen_pool *devm_gen_pool_create(struct device *dev, |
121 | int min_alloc_order, int nid); | 121 | int min_alloc_order, int nid, const char *name); |
122 | extern struct gen_pool *gen_pool_get(struct device *dev); | 122 | extern struct gen_pool *gen_pool_get(struct device *dev, const char *name); |
123 | 123 | ||
124 | bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start, | 124 | bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start, |
125 | size_t size); | 125 | size_t size); |
diff --git a/lib/genalloc.c b/lib/genalloc.c index daf0afb6d979..b13cfd1a366e 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c | |||
@@ -571,23 +571,46 @@ static void devm_gen_pool_release(struct device *dev, void *res) | |||
571 | } | 571 | } |
572 | 572 | ||
573 | /** | 573 | /** |
574 | * gen_pool_get - Obtain the gen_pool (if any) for a device | ||
575 | * @dev: device to retrieve the gen_pool from | ||
576 | * @name: name of a gen_pool or NULL, identifies a particular gen_pool on device | ||
577 | * | ||
578 | * Returns the gen_pool for the device if one is present, or NULL. | ||
579 | */ | ||
580 | struct gen_pool *gen_pool_get(struct device *dev, const char *name) | ||
581 | { | ||
582 | struct gen_pool **p; | ||
583 | |||
584 | p = devres_find(dev, devm_gen_pool_release, NULL, NULL); | ||
585 | if (!p) | ||
586 | return NULL; | ||
587 | return *p; | ||
588 | } | ||
589 | EXPORT_SYMBOL_GPL(gen_pool_get); | ||
590 | |||
591 | /** | ||
574 | * devm_gen_pool_create - managed gen_pool_create | 592 | * devm_gen_pool_create - managed gen_pool_create |
575 | * @dev: device that provides the gen_pool | 593 | * @dev: device that provides the gen_pool |
576 | * @min_alloc_order: log base 2 of number of bytes each bitmap bit represents | 594 | * @min_alloc_order: log base 2 of number of bytes each bitmap bit represents |
577 | * @nid: node id of the node the pool structure should be allocated on, or -1 | 595 | * @nid: node selector for allocated gen_pool, %NUMA_NO_NODE for all nodes |
596 | * @name: name of a gen_pool or NULL, identifies a particular gen_pool on device | ||
578 | * | 597 | * |
579 | * Create a new special memory pool that can be used to manage special purpose | 598 | * Create a new special memory pool that can be used to manage special purpose |
580 | * memory not managed by the regular kmalloc/kfree interface. The pool will be | 599 | * memory not managed by the regular kmalloc/kfree interface. The pool will be |
581 | * automatically destroyed by the device management code. | 600 | * automatically destroyed by the device management code. |
582 | */ | 601 | */ |
583 | struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order, | 602 | struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order, |
584 | int nid) | 603 | int nid, const char *name) |
585 | { | 604 | { |
586 | struct gen_pool **ptr, *pool; | 605 | struct gen_pool **ptr, *pool; |
587 | 606 | ||
607 | /* Check that genpool to be created is uniquely addressed on device */ | ||
608 | if (gen_pool_get(dev, name)) | ||
609 | return ERR_PTR(-EINVAL); | ||
610 | |||
588 | ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL); | 611 | ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL); |
589 | if (!ptr) | 612 | if (!ptr) |
590 | return NULL; | 613 | return ERR_PTR(-ENOMEM); |
591 | 614 | ||
592 | pool = gen_pool_create(min_alloc_order, nid); | 615 | pool = gen_pool_create(min_alloc_order, nid); |
593 | if (pool) { | 616 | if (pool) { |
@@ -595,29 +618,13 @@ struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order, | |||
595 | devres_add(dev, ptr); | 618 | devres_add(dev, ptr); |
596 | } else { | 619 | } else { |
597 | devres_free(ptr); | 620 | devres_free(ptr); |
621 | return ERR_PTR(-ENOMEM); | ||
598 | } | 622 | } |
599 | 623 | ||
600 | return pool; | 624 | return pool; |
601 | } | 625 | } |
602 | EXPORT_SYMBOL(devm_gen_pool_create); | 626 | EXPORT_SYMBOL(devm_gen_pool_create); |
603 | 627 | ||
604 | /** | ||
605 | * gen_pool_get - Obtain the gen_pool (if any) for a device | ||
606 | * @dev: device to retrieve the gen_pool from | ||
607 | * | ||
608 | * Returns the gen_pool for the device if one is present, or NULL. | ||
609 | */ | ||
610 | struct gen_pool *gen_pool_get(struct device *dev) | ||
611 | { | ||
612 | struct gen_pool **p = devres_find(dev, devm_gen_pool_release, NULL, | ||
613 | NULL); | ||
614 | |||
615 | if (!p) | ||
616 | return NULL; | ||
617 | return *p; | ||
618 | } | ||
619 | EXPORT_SYMBOL_GPL(gen_pool_get); | ||
620 | |||
621 | #ifdef CONFIG_OF | 628 | #ifdef CONFIG_OF |
622 | /** | 629 | /** |
623 | * of_gen_pool_get - find a pool by phandle property | 630 | * of_gen_pool_get - find a pool by phandle property |
@@ -642,7 +649,7 @@ struct gen_pool *of_gen_pool_get(struct device_node *np, | |||
642 | of_node_put(np_pool); | 649 | of_node_put(np_pool); |
643 | if (!pdev) | 650 | if (!pdev) |
644 | return NULL; | 651 | return NULL; |
645 | return gen_pool_get(&pdev->dev); | 652 | return gen_pool_get(&pdev->dev, NULL); |
646 | } | 653 | } |
647 | EXPORT_SYMBOL_GPL(of_gen_pool_get); | 654 | EXPORT_SYMBOL_GPL(of_gen_pool_get); |
648 | #endif /* CONFIG_OF */ | 655 | #endif /* CONFIG_OF */ |