Skip to content

Commit 7385817

Browse files
Vladimir Zapolskiytorvalds
authored andcommitted
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>
1 parent c0a2949 commit 7385817

8 files changed

Lines changed: 39 additions & 32 deletions

File tree

‎arch/arm/mach-at91/pm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static void __init at91_pm_sram_init(void)
369369
return;
370370
}
371371

372-
sram_pool = gen_pool_get(&pdev->dev);
372+
sram_pool = gen_pool_get(&pdev->dev, NULL);
373373
if (!sram_pool) {
374374
pr_warn("%s: sram pool unavailable!\n", __func__);
375375
return;

‎arch/arm/mach-imx/pm-imx5.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static int __init imx_suspend_alloc_ocram(
297297
goto put_node;
298298
}
299299

300-
ocram_pool = gen_pool_get(&pdev->dev);
300+
ocram_pool = gen_pool_get(&pdev->dev, NULL);
301301
if (!ocram_pool) {
302302
pr_warn("%s: ocram pool unavailable!\n", __func__);
303303
ret = -ENODEV;

‎arch/arm/mach-imx/pm-imx6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata)
451451
goto put_node;
452452
}
453453

454-
ocram_pool = gen_pool_get(&pdev->dev);
454+
ocram_pool = gen_pool_get(&pdev->dev, NULL);
455455
if (!ocram_pool) {
456456
pr_warn("%s: ocram pool unavailable!\n", __func__);
457457
ret = -ENODEV;

‎arch/arm/mach-socfpga/pm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int socfpga_setup_ocram_self_refresh(void)
5656
goto put_node;
5757
}
5858

59-
ocram_pool = gen_pool_get(&pdev->dev);
59+
ocram_pool = gen_pool_get(&pdev->dev, NULL);
6060
if (!ocram_pool) {
6161
pr_warn("%s: ocram pool unavailable!\n", __func__);
6262
ret = -ENODEV;

‎drivers/media/platform/coda/coda-common.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ static int coda_probe(struct platform_device *pdev)
21572157
/* Get IRAM pool from device tree or platform data */
21582158
pool = of_gen_pool_get(np, "iram", 0);
21592159
if (!pool && pdata)
2160-
pool = gen_pool_get(pdata->iram_dev);
2160+
pool = gen_pool_get(pdata->iram_dev, NULL);
21612161
if (!pool) {
21622162
dev_err(&pdev->dev, "iram pool not available\n");
21632163
return -ENOMEM;

‎drivers/misc/sram.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ static int sram_probe(struct platform_device *pdev)
186186
if (IS_ERR(sram->virt_base))
187187
return PTR_ERR(sram->virt_base);
188188

189-
sram->pool = devm_gen_pool_create(sram->dev,
190-
ilog2(SRAM_GRANULARITY), -1);
191-
if (!sram->pool)
192-
return -ENOMEM;
189+
sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
190+
NUMA_NO_NODE, NULL);
191+
if (IS_ERR(sram->pool))
192+
return PTR_ERR(sram->pool);
193193

194194
ret = sram_reserve_regions(sram, res);
195195
if (ret)

‎include/linux/genalloc.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ extern unsigned long gen_pool_best_fit(unsigned long *map, unsigned long size,
118118
unsigned long start, unsigned int nr, void *data);
119119

120120
extern struct gen_pool *devm_gen_pool_create(struct device *dev,
121-
int min_alloc_order, int nid);
122-
extern struct gen_pool *gen_pool_get(struct device *dev);
121+
int min_alloc_order, int nid, const char *name);
122+
extern struct gen_pool *gen_pool_get(struct device *dev, const char *name);
123123

124124
bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start,
125125
size_t size);

‎lib/genalloc.c‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -570,54 +570,61 @@ static void devm_gen_pool_release(struct device *dev, void *res)
570570
gen_pool_destroy(*(struct gen_pool **)res);
571571
}
572572

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+
573591
/**
574592
* devm_gen_pool_create - managed gen_pool_create
575593
* @dev: device that provides the gen_pool
576594
* @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
578597
*
579598
* Create a new special memory pool that can be used to manage special purpose
580599
* memory not managed by the regular kmalloc/kfree interface. The pool will be
581600
* automatically destroyed by the device management code.
582601
*/
583602
struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order,
584-
int nid)
603+
int nid, const char *name)
585604
{
586605
struct gen_pool **ptr, *pool;
587606

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+
588611
ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL);
589612
if (!ptr)
590-
return NULL;
613+
return ERR_PTR(-ENOMEM);
591614

592615
pool = gen_pool_create(min_alloc_order, nid);
593616
if (pool) {
594617
*ptr = pool;
595618
devres_add(dev, ptr);
596619
} else {
597620
devres_free(ptr);
621+
return ERR_PTR(-ENOMEM);
598622
}
599623

600624
return pool;
601625
}
602626
EXPORT_SYMBOL(devm_gen_pool_create);
603627

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-
621628
#ifdef CONFIG_OF
622629
/**
623630
* 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,
642649
of_node_put(np_pool);
643650
if (!pdev)
644651
return NULL;
645-
return gen_pool_get(&pdev->dev);
652+
return gen_pool_get(&pdev->dev, NULL);
646653
}
647654
EXPORT_SYMBOL_GPL(of_gen_pool_get);
648655
#endif /* CONFIG_OF */

0 commit comments

Comments
 (0)